量角器:访问功能 [英] Protractor: accessing capabilities

查看:30
本文介绍了量角器:访问功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 multiCapabilities,并且想知道是否有可能知道当前在 onPrepare 函数和/或测试用例本身中使用了什么功能.

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.

用例是我计划在 chrome 和 android 上运行我的测试.对于 Chrome,应将窗口大小调整为所需尺寸,但是在 selendroid 上运行相同的代码会出现异常,因为该方法未实现(在设备上调整窗口大小也没有真正意义):
因此,我们的想法是以某种方式将有问题的代码包装在一个简单的检查中,如下所示:
if(浏览器 != 'android')browser.driver.manage().window().setSize(480, 800);

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.

推荐答案

我在 onPrepare 部分做类似的事情,例如

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()) {...}

对于 android 这应该可以工作:

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);
    });
};

这篇关于量角器:访问功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆