Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js selenium webdriver - Get browser capabilities inside test?

I'm using selenium webdriver on node.js (currently via webdriverio, but I don't mind switching to webdriverjs or wd).

I run some tests on different browsers and want to save results of each test along with information about the browser, for example:

  • Test 1 - chrome - 199 assertions, 0 failures, 0 skipped
  • Test 1 - IE9 - 199 assertions, 0 failures, 0 skipped
  • etc..

How can I get the "desiredCapabilities" object from within the test?

Or how can I pass it to the test so it will be available?

EDIT

I found that browser.desiredCapabilities returns the requested capabilities object, but now I realize I actually need the "actual capabilities" used (for example if I ask for IE8 on a machine that only has IE11 I get IE11 but the desiredCapabilities object shows version=8).

I'm looking for a way to get the actual used browser capabilities, as documented on selenium wiki:

If a session cannot support a capability that is requested in the desired capabilities, no error is thrown; a read-only capabilities object is returned that indicates the capabilities the session actually supports.

like image 557
Malki Avatar asked Dec 02 '14 07:12

Malki


1 Answers

Using WebDriverJS (which you mentioned you could switch to), you can use getCapabilities:

browser.getCapabilities().then(function (caps) {
    console.log(caps);
});

The code above will just dump the capabilities but you should use the methods of the Capabilities class to inspect the values. For instance:

browser.getCapabilities().then(function (caps) {
    console.log(caps.get("browserName"), caps.get("version"));
});
like image 140
Louis Avatar answered Sep 29 '22 07:09

Louis