Run parallel Protractor tests in multiple Chrome tabs - selenium

I'm using the following .conf:
capabilities: {
browserName : 'chrome',
shardTestFiles: true,
'time-zone': 'AEST',
maxInstances: 5,
singleWindow: true
}
I'm using singleWindow as described in the capabilities page for Selenium and the properties are passed to the WebDriver according to this. However I'm still seeing multiple individual windows appearing and disappearing during execution. These fight for focus and it's very annoying while doing other work.
Is it possible to run parallel tests in separate tabs rather than separate instances/windows of Chrome?

Related

Webdriver.io: what's the difference between the capabilities and desiredCapabilities keywords?

I'm using Webdriver.io to run UI tests in a Node environment.
I'd like to run Headless Chrome and came up with the following working configuration:
{
capabilities: [{
browserName: 'chrome',
args: ['--headless', '--disable-gpu']
}
}],
services : ['selenium-standalone'],
execArgv : ['--inspect']
}
However, I can't figure out whether capabilities is deprecated or not; I'm wondering because all the examples I see reference desiredCapabilities instead.
If I use desiredCapabilities though, then Chrome runs normally, not in headless mode.
I feel like I'm missing something, but I don't know what. Is there a significant difference between the two, and is one going away?
Thanks!
If you run webdriverio through the test runner (using a wdio.conf.js file), it uses capabilities.
If you run it in standalone mode (e.g. node myTest.js), it uses desiredCapabilities

Disable file downloads Selenium Firefox

I'm building a webscraping app and I'm using Selenium with a Firefox driver to open my pages. Whenever it opens a link that leads to a download, my app stalls and hangs on the link for eternity.
I've tried looking for a solution, but they never mention disabling downloads. They only talk about enabling them, changing the download directory,...
Would it be possible to detect that the link is a download link and just skip it, or maybe to skip the link whenever it opens?
I had a slightly different problem and I solved it by changing Firefox capabilities.
Open about:config in Firefox to see list of them. Then you can pass them to webdriver through desired_capabilities.
caps = {'acceptInsecureCerts': True,
'browserName': 'firefox',
'marionette': True,
'moz:firefoxOptions': {
'args': ['--no-remote'],
'prefs': {
'browser.safebrowsing.downloads.enabled': False
}
},
driver = webdriver.Remote([...]
desired_capabilities=caps)

Nightwatch tests do not find elements in Headless chrome mode

I am trying to get my tests (written in Nightwatch.js) to run locally in headless chrome.
However, the tests fail since they are not able to find the elements in headless mode (they work without headless mode though).
If I check the failure screenshots I only get a white screen.
But if test checks for the "body" element, it actually pass. So I think the page is loaded, but maybe headless chrome, for some reason, cannot load the javascript? Later I wait for divs and buttons etc to be visible for several seconds, but it does not find them.
Do you have any ideas what could be wrong?
I have added the --headless and --disable-gpu flags in desiredCapabilities in the nightwatch config file.
So, as I said in my reply I had the same issue yesterday, I was just trying to do a dummy test on google homepage. This morning with a fresh brain I tried to tackle that. I had the brilliant idea to take a screenshot just before nightwatch fails to find an element.
It turns out the "normal" chrome had the home page in English, and the "headless" chrome had the homepage in french, for some reason.
I found this: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1925 may be explaining why.
The workaround I found to always have the correct language is:
"chromeOptions" : {
"args" : ["--lang=fr", "--headless"]
}
I still have a hard time setting it in english (weirdly) but I hope this will save someone a couple of hours in the future
I think you should declare binary path in Nightwatch.js
If you are on linux please try this, it works perfectly for me :
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"chromeOptions": {
"args": [
"headless", "disable-gpu"
],
"binary": "/usr/bin/google-chrome"
}
}
If you are on Mac, replace your binary path, eg /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

Create new WebDriver session for each spec file

We have a bunch of e2e protractor tests on jasmine2 framework and recently we started to run them on SauceLabs.
SauceLabs has a restriction that one WebDriver session can not run longer than 30 mins. This makes perfect sense to me, however causes our tests to fail as protractor runs all our tests in a single WebDriver session.
So I'm wondering how can I initiate new WebDriver session, say for each spec file or for each 'describe'? Or there is a solution that protractor can offer out of the box?
Timeout increase is not an option for me.
Many thanks.
I believe that's what you are looking for:
{
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 5
},
Use this in your config.js file and make sure to divide the tests among multiple spec files. I am using this in my tests (an example here), and it is working fine for me.
{
'name': 'Window10 -Chrome-tests',
'browserName': 'chrome',
shardTestFiles: true,
platform: 'Windows 10',
screenResolution: '1376x1032',
maxInstances: 5
},

Setting up selenium grid to use Microsoft edge

Environment:
win10 (build 10240)
Vaadin Testbench 4.1
Selenium 2.53
Drivers for Firefox, Chrome, IE11 and Edge for build 10240
Node and hub
start java -jar c:\users\powder\vaadin-testbench-standalone-4.1.0.jar -role hub
start java -jar c:\users\powder\vaadin-testbench-standalone-4.1.0.jar -role node -Dwebdriver.edge.driver=c:\users\powder\MicrosoftWebDriver.exe
Usage in java code
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(DesiredCapabilities.edge().getBrowserName());
//DesiredCapabilities capabilities = DesiredCapabilities.edge(); Tried as well
capabilities.setCapability("acceptSslCerts", "true");
setDriver(new RemoteWebDriver(new URL(this.remoteHubUrl), capabilities));
getDriver().get("http://www.google.com");
Errormessage
Error forwarding the new session cannot find : Capabilities [{acceptSslCerts=true, browserName=MicrosoftEdge}]
Selenium grid console - edge is missing
Everything is working fine with other browsers, but not with Edge. Any ideas how to fix that?
There are 2 problems here:
First, if you look at the default node config you will notice that only Firefox, Chrome and IE are enabled by default (that's why all you need to use them is specify driver location via a system property). If you want to use any other browser then you need to use your own json config:
{
"capabilities": [
{
"browserName": "MicrosoftEdge",
"platform": "WIN10",
"maxInstances": 1
},
{
"browserName": "firefox",
"platform": "WIN10",
"maxInstances": 5
},
{
"browserName": "chrome",
"platform": "WIN10",
"maxInstances": 5
},
{
"browserName": "internet explorer",
"platform": "WIN10",
"maxInstances": 1
}
],
"hub": "http://selenium-hub-host:4444"
}
and pass it to your command line:
java "-Dwebdriver.edge.driver=c:\path\to\MicrosoftWebDriver.exe" "-Dwebdriver.gecko.driver=c:\path\to\geckodriver.exe" "-Dwebdriver.chrome.driver=c:\path\to\chromedriver.exe" "-Dwebdriver.ie.driver=c:\path\to\IEDriverServer.exe" -jar "c:\path\to\selenium-server-standalone.jar" -role node -nodeConfig "c:\path\to\the\above.json"
(btw: alternatively you can also put the whole config in your command line using multiple -capabilities or -browser params)
This in theory should work. However in practice you will often be hit by the 2nd problem, which is: "sometimes it randomly doesn't work" ;] Initially everything will look fine: your grid will properly report Edge browser capability on the console, it will properly delegate tests to a node containing Edge, the node will properly start Edge browser, however the browser will sometimes freeze on its initial blue screen with e logo and after few seconds you will get some exception on the client side without any meaningful stack-trace nor message (I don't have it saved anywhere to paste here now).
Some people suggested a workaround to start 2 separate nodes on the same machine (on different ports of course) : one only for Edge and second for IE, FF and Chrome. This way it seems to work pretty stable (tested on Edge build 15063 running on win-10 and Selenium-3.4.0)
Additional info:
Apart from the above, Edge driver has few limitations that require specific workarounds in the configuration:
currently only 1 concurrent session is supported by the driver/browser so maxInstances must be set to 1 (kudos to this answer)
the driver must be running in the foreground, so that the browser window can be actually displayed on the desktop. Therefore the node cannot be started as a Windows Service nor from Windows Task Scheduler at startup. The best way to automate starting of the node is to configure auto-login and add a batch script starting the node to user's Startup Programs as described in my article
Try putting the -D parameters before the -jar parameter. I had an issue where it thought -Dwebdriver..... was a parameter to selenium itself instead of java.