Protractor: access to features

I run with multiCapabilities and would like to know if it is possible to find out which function is currently used, both in the onPrepare function and / or the test panel itself.

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

There are other use cases, but the most important at the moment.

+4
source share
1 answer

I do as in the section onPrepare, for example

// 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, I use it as follows:

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);
    });
};
+5
source

Source: https://habr.com/ru/post/1535401/


All Articles