disable screenshots in phantomjs - automation

How do I stop phantomjs from taking screenshots? I need to run a test in parrallel a bunch of times using jmeter. JMeter randomly fails on some of the tests and I'm suspecting it could be Phantomjs trying to save a screenshot of the test run. With multiple threads trying to write a file to the same place at the same time I'm assuming this may be an issue. If not I'd still like to try disabling the ability to save a screenshot.
I had needed to disable phantomjs from logging and had gotten it to work with the following code:
headlessNoLogs {
driver = {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("takesScreenshot", false);
ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--webdriver-loglevel=NONE");
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
Logger.getLogger(PhantomJSDriverService.class.getName()).setLevel(Level.OFF);
new PhantomJSDriver(caps)
}
}
Disabling the logging is working as expected. But I'm setting takesScreenshot, false and phantomjs is still taking screenshots.

Related

How Can I set chrome browser to automatically download a pdf using QAF and WebDriverManager

Using a datasheet, I usually pass a browser name into a class I created to select which browser I want to run my tests from. Recently, I've been working on an app in which I need to download a PDF and then verify its contents. I have everything working successfully other than downloading the PDF. With WebDriverManager, it creates a browser profile every time a test runs, and so, I need to update chromeOptions to download PDFs automatically before at the start of the script.
Here is the code that I already have. I just need help with what to put in the prefs for this to work. -
public static void selectBrowser(String strBrowser) {
switch (strBrowser) {
case "Chrome":
String chromePrefs = "{'goog:chromeOptions':{'prefs':{'profile.default_content_settings.popups':0}}}";
ConfigurationManager.getBundle().setProperty("chrome.additional.capabilities", chromePrefs);
TestBaseProvider.instance().get().setDriver("chromeDriver");
Reporter.log("Chrome Browser was set", MessageTypes.Info);
break;
}
}
After researching for hours, finally found that I needed to use the plugins.always_open_pdf_externally preference. Here is the code for anyone who might need it.
Note, the "goog:" before chromeOptions is necessary since I have WebDriverManager enabled. With 3rd party driver managers, we need to put "goog:" before chromeOptions for it to work.
You can simply put it in the application.properties like this -
chrome.additional.capabilities={"goog:chromeOptions":{"args":[--disable-extensions],"prefs":{"plugins.always_open_pdf_externally":true}}}
or you can put it in the code I have up top like this
String chromePrefs = "{'goog:chromeOptions':{'args':[],'prefs':{\"plugins.always_open_pdf_externally\":true}}}";

How to prevent selenium from opening new firefox windows?

I am running Selenium Firefox Webdriver on Python for webscraping and when I am going around diferent pages, some of those have some mechanism that open new windows, something in the way of this:
$(function(){
window.open(url, windowName[, windowFeatures]);
});
And it is some kind of malicious webpage that keeps opening random pages on new windows and after some minutes my PC runs out of memory and crashes.
So want I want is to load some feature on the webdriver so it doesn't allow pages to open new windows.
I have tryed not to load JS but this feature is no longer working I guess.
Also, if you know some option or preference to ignore script tags I would like to know it.
Thanks in advice.
Try loading a JS file just in your tests which overwrites the window.open function. Something like:
(function(){
window.open = function() { return false; }
})();
Notice this is an immediatly invoked function exectution.

How do I test a website without opening it using automation?

I am able to use Selenium web driver to test the website and get the result. But I need to get the result without opening a single web page. I made some R&D and found Selenium can't do this.
Can any body tell me how can I achieve this?
Thanks,
Rahul
Give Htmlunitdriver a try
Enter this line in your code
driver = new HtmlUnitDriver(true);
true = to enable javascript support.
In case you'll see many warnings in your console once you run your test. To ignore them simply do this
static Logger log = Logger.getLogger("com.gargoylesoftware");
log.setLevel(Level.OFF);
driver = new HtmlUnitDriver(true);
Else there is always other options like PhantomJS
Source: SoftwareAutomata

Mink and Sahi timing out on getContent

I've written a website scraper for use in a project.
I'm controlling Firefox through Sahi using Mink to visit each site and interact with any elements where necessary. I've managed to get this working perfectly on all sites I've tried except for one...
I'm trying to get the markup from https://www.o2.co.uk/shop/phones/
I'm using the exact same code for this page, as I have for all others:
// Configure driver
$this->driver = new \Behat\Mink\Driver\SahiDriver('firefox',
new \Behat\SahiClient\Client(
new \Behat\SahiClient\Connection(null, CRAWL_SERVER, 9999)
)
);
// Init session:
$this->session = new \Behat\Mink\Session($this->driver);
// Start session:
$this->session->start();
// Open the url
$this->session->visit($config['url']);
// Get the markup from the page
$markup = $this->session->getPage()->getContent();
When I use this code to attempt to get the markup from https://www.o2.co.uk/shop/phones/ Mink just seems to hang, waiting for something to happen.
It would seem that maybe something on this page is preventing either Sahi or Mink from returning the markup. I've also tried running other functions instead of getContent(), such as $this->session->wait(2000); and attempting to search through getPage using the find command.
If anyone has any idea as to why this is happening I would be very interested in finding out why and how I can make this work.
tl;dr
Why is Mink/Sahi timing out on this site?

Login popup window using selenium webdriver?

the popup window is only happening if I use the Fire Fox browser otherwise, is there a way to fix this problem? I have to enter userid/password every time the i use FF as my browser.
currently, I am entering every time i run my test which is very painful but looking to make it more automated....
I have goggled and found two links here and here but no avail
http://username:password#xyz.com
This worked for me (xyz.com being the site name)
After spending hours reading I finally found the solution which works pretty well and I hope this will help others too. - Enjoy!!
First - follow this steps:
1) Open the FireFox browser
2) Type the following `about:config`
3) Look for `network.http.phishy-userpass-length` if you don't find then create a new Integer key
Create a new Integer key (right-click->New->Integer): `network.http.phishy-userpass-length` with value `255`
Second: You need to create a Firefox driver with the following:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("network.http.phishy-userpass-length", 255);
profile.SetPreference("network.automatic-ntlm-auth.trusted-uris", "YOUR HOST ADDRESS HERE");
_driver = new FirefoxDriver(profile);
let me know if you have any questions.
If this is a windows user account & password, then you need to enable the integrated windows login by setting
network.negotiate-auth.delegation-uris: MyIISServer.domain.com
network.automatic-ntlm-auth.trusted-uris: MyIISServer.domain.com
network.automatic-ntlm-auth.allow-proxies: True
network.negotiate-auth.allow-proxies: True
in the Firefox profile that WebDriver starts. Once you have the profile created and saved (run "Firefox -P" when no other instances are running to select a profile), you can do this in the code:
File profileDir = new File("C:/wherever/SeleniumFirefoxProfile");
FirefoxProfile profile = new FirefoxProfile(profileDir);
profile.setEnableNativeEvents(true);
driver = new FirefoxDriver(profile);
I have had to handle these a few times, but my approach is using a script outside Selenium. Are you working on Windows?
Basically what you do is this:
1) Prior to loading the page, clicking the URL, etc that causes that dialog to appear:
-- Launch an asynchronous script to handle the login
2) Then load the page, click the link, etc
-- Selenium will block until your asynch script completes
The async script:
-- Sleep for a few seconds
-- Activate the dialog
-- Send the username
-- Send a TAB
-- Send the password
-- Send a TAB
-- Send the Enter Key
If you are working on windows, I can post sample scripts to handle this. I've done it with Java and C#, but I would guess that basically the same thing would work regardless of how you are writing your tests (unless you are strictly using the FF plugin, in which case this won't work).
Let me know if you'd like more details.
You can use a FF plugin "autoauth". Download this plugin and create Firefox instance by the following way:
FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");
File pluginAutoAuth = new File("D:\\autoauth-2.1-fx+fn.xpi");
firefoxProfile.addExtension(pluginAutoAuth);
driver = new FirefoxDriver(firefoxProfile);
I used "autoauth-2.1-fx+fn.xpi"