Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor: accessing capabilities

Tags:

protractor

I am running with multiCapabilities, and would like to know if it is possible to know what capability is currently used, both in the onPrepare function and/or the testcase itself.

The use case is that I am planning to run my tests both on chrome and on android. For Chrome the window should be resized to required dimensions, however running the same code on selendroid gives an exception because the method is not implemented (also resizing a window on a device does not really make sense):
So, the idea was to somehow wrap the offending code in a simple check like so:
if(browser != 'android') browser.driver.manage().window().setSize(480, 800);

There are also other use cases, but that's the most important one for now.

like image 307
FrankyBoy Avatar asked Apr 07 '14 15:04

FrankyBoy


1 Answers

I do stuff like that within the onPrepare section, e.g.

// Return if current browser is IE, optionally specifying if it is a particular IE version
browser.isInternetExplorer = function(ver) {
    var browserName, version, ie;

    return browser.getCapabilities().then(function(s) { 
        browserName = s.caps_.browserName;
        version = s.caps_.version;

        ie = /i.*explore/.test(browserName);

        if (ver == null) {
            return ie;
        } else {
            return ie && ver.toString() === version;
        }
    });
};

Then, later on, i use it like this:

if (browser.isInternetExplorer()) {...}

For android this should work:

browser.isAndroid = function(ver) {
    var browserName, version;

    return browser.getCapabilities().then(function(s) { 
        browserName = s.caps_.browserName;
        version = s.caps_.version;

        return /droid/.test(browserName);
    });
};
like image 85
Leo Gallucci Avatar answered Oct 24 '22 21:10

Leo Gallucci