在Protractor测试中获取当前浏览器名称

时间:2014-05-26 15:00:44

标签: angularjs protractor

我在某些测试中创建用户。由于它连接到后端并创建真正的用户,我需要固定装置。我在考虑使用浏览器名称来创建唯一用户。然而,事实证明它很难实现......

任何人都可以指出我正确的方向吗?

3 个答案:

答案 0 :(得分:36)

rubber ducking的另一个案例:)

答案其实很简单。

在我的onPrepare函数中,我添加了以下函数,它完美无缺。

browser.getCapabilities().then(function (cap) {
  browser.browserName = cap.caps_.browserName;
});

我可以使用browser.browserName访问我的测试中的名称。

答案 1 :(得分:16)

从3.2(selenium webdriver 2.52)

开始,量角器的版本发生了变化

现在应该打电话:

step

答案 2 :(得分:0)

如果您想避开浏览器,可能需要执行此操作:

it('User should see a message that he has already been added to the campaing when entering the same email twice', function () {

    browser.getCapabilities().then(function (capabilities) {
        browserName = capabilities.caps_.browserName;
        platform = capabilities.caps_.platform;
    }).then(function () {
        console.log('Browser:', browserName, 'on platform', platform);
        if (browserName === 'internet explorer') {
            console.log('IE Was avoided for this test.');
        } else {
            basePage.email.sendKeys('bruno@test.com');
            console.log('Mande el mail');
            basePage.subscribe.click().then(function () {
                basePage.confirmMessage('Contact already added to target campaign');
            });
        }
    });

}); 
相关问题