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

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

Related

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

Meaning of "browser" in Selenium's requested capabilities

I am developing functional tests with Behat, Mink and Selenium. I have long been perplexed by the "browser" item included in the Capabilities object that's created with each new session:
02:13:48.592 INFO - Got a request to create a new session: Capabilities
[{browser=safari, name=Behat feature suite, browserName=safari, [...] }]
As far as I can tell, only "browserName" has any effect - if I set "browserName" to "safari" and "browser" to any other value, then the new session will be created on a node that can run Safari.
So why does Mink include the value? It must surely have some purpose, but I haven't found any documentation explaining it.
A possible answer would be:
browser and browserName is the same capability for the browser to use.
If you are using capabilities parametter to set up the desired capabilities to use, then the browserName has priority.
If you are NOT using capabilities parametter you can also setup the browser name by using browser.
To get a better picture please take a look to getConfig method at arrayNode('selenium2') line from Extension.php located in vendor > behat > mink-extension > src.
Hope this will help you in getting an answer or at least point you to the right direction.

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
},

Run parallel Protractor tests in multiple Chrome tabs

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?

Test browser code with Intern through Grunt and Phantomjs

I have been playing with Intern and made my tests work in the browser. To better integrate with my current workflow I'm trying to run my tests through grunt with phantomjs. However all my attempts have failed. I've been looking at this question as a reference Intern WebDriver and PhantomJS but can't figure out all of the steps to make it work.
First of all: Is it even possible to run the tests through grunt and phantomjs?
A little bit of info:
I don't want/can't connect to Sauce Labs or a Selenium testing environment.
I want to test browser code while having jQuery as a shimmed dependency
I have Grunt 0.4.1 and phantomjs 1.9.1 installed
I'm not testing any ajax request (as the linked question is having problem with)
I'm not familiar with neither Selenium nor Sauce Lab
If it is possible to test through grunt and phanomjs, how would I go about doing it?
I guess that I have to start the GhostDriver
phantomjs --webdriver=8910
But then what are the important pieces of info in the Intern config to make this work?
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
environments: [
{
browserName: 'phantom',
version: '1.9.0',
platform: 'Linux'
}
],
webdriver: {
host: 'localhost',
port: 8910
},
maxConcurrency: 3,
useSauceConnect: false,
// ...
});
How does the environments browserName map to phantomjs? I've tried the browserNames 'phantom' as well as 'phanomjs' with different versions and platforms (running Mac 10.7)
My Gruntfile section for intern looks like:
intern: {
phantom: {
options: {
config: 'tests/intern',
reporters: ['webdriver']
}
}
}
Running this setup without any test-suite that includes browser code outputs
'ReferenceError: document is not defined' in 'node_modules/intern/lib/reporters/webdriver.js:41:19'
Adding browser tests gives 'ReferenceError: window is not defined' in 'src/vendor/jquery/jquery-1.9.1.js:9597:5'
Running it through node gives the same 'window is not defined' error.
node node_modules/intern/client.js config=tests/intern
What am I doing wrong/missing here?
There are two problems with your Gruntfile configuration:
The default run type for the Grunt task is 'client', which means it runs the Node.js client by default, not the test runner. You need to set runType: 'runner' in your Gruntfile options to run tests against your specified environments.
The webdriver reporter is for use in a browser client only and is specified automatically by the test runner when it is needed. You should typically never use it directly. The reporter you specify in the Gruntfile should be the one you want the test runner to use; the console default is usually appropriate.
These two things in combination mean that you’ve configured Intern to try to use a reporter that only works in a browser in conjunction with the test runner inside the Node.js client, hence the error. Once corrected, the remaining configuration should work properly to run on PhantomJS, assuming it is already running on localhost at port 8910.