处理量角器中的未知错误 [英] Handling Unknown Errors in protractor

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

问题描述

我有一个量角器设置,多个浏览器通过 multiCapabilities 配置,在browserstack上运行测试。



我的一个关键的量角器规格/测试包含以下 afterEach()块:

  afterEach(function(){
browser.manage()。logs()。get(browser)。then(function(browserLog){
expect(browserLog.length).toEqual(0);
});
});

检查浏览器控制台是否为空(控制台上没有错误)。



问题是:当我针对Internet Explorer运行这个规范时,我得到一个 UnknownError


UnknownError:找不到命令:P​​OST / session / 6b838fe8-f4a6-4b31-b245-f4bf8f37537c / log


经过快速研究,我发现 IE selenium webdriver 尚不支持会话日志:





问题是:如何捕获这个 UnknownError ,并在特定错误的情况下通过spec?



或者,要解决它,可能有一个 afterEach()块功能y /浏览器特定的,或者知道当前运行的功能是什么?






我试图使用 try / catch 并尝试依赖例外发件人,但 console.log()不执行:

  afterEach(function(){
try {
browser.manage ).logs()。get(browser)。then(function(browserLog){
expect(browserLog.length).toEqual(0);
});
}
catch(e){
console.log(e.sender);
}
});

作为解决方法,我重复相同的规范,但没有失败的 afterEach()阻止,专门用于Internet Explorer。

解决方案

找到一个选项 - 使用 getCapabilities() 来检索当前的浏览器名称:



$ pre> afterEach(function(){
browser.driver.getCapabilities()。then(function(caps){
var browserName = caps.caps_.browserName ;

if(browserName!==internet explorer){
browser.manage()。logs()。get(browser)。then(function(browserLog){
expect(browserLog.length).toEqual(0);
});
}
});
});

在这种情况下,如果针对Internet Explorer运行,浏览器日志将不会被检查。


I have a protractor setup with multiple browsers configured through multiCapabilities, running tests on browserstack.

One of my key protractor specs/tests contain the following afterEach() block:

afterEach(function() {
    browser.manage().logs().get("browser").then(function (browserLog) {
        expect(browserLog.length).toEqual(0);
    });
});

that checks that the browser console is empty (no errors on the console).

The problem is: when I run this spec against Internet Explorer, I'm getting an UnknownError:

UnknownError: Command not found: POST /session/6b838fe8-f4a6-4b31-b245-f4bf8f37537c/log

After a quick research, I've found out that IE selenium webdriver does not yet support session logs:

The question is: how can I catch this UnknownError and let the spec pass in case of this specific error?

Or, to turn it around, is it possible to have an afterEach() block capability/browser-specific, or know which currently running capability is it?


I've tried to use try/catch and try relying on exception sender, but console.log() is not executed:

afterEach(function() {
    try {
        browser.manage().logs().get("browser").then(function (browserLog) {
            expect(browserLog.length).toEqual(0);
        });
    }
    catch (e) {
        console.log(e.sender);
    }
});

As a workaround, I'm duplicating the same spec but without that failing afterEach() block, specifically for Internet Explorer.

解决方案

Found one option - using getCapabilities() to retrieve the current browser name:

afterEach(function() {
    browser.driver.getCapabilities().then(function(caps) {
        var browserName = caps.caps_.browserName;

        if (browserName !== "internet explorer") {
            browser.manage().logs().get("browser").then(function (browserLog) {
                expect(browserLog.length).toEqual(0);
            });
        }
    });
});

In this case browser logs would not be checked if running against Internet Explorer.

这篇关于处理量角器中的未知错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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