在处理未知量角器错误 [英] Handling Unknown Errors in protractor
问题描述
我有一个量角器
设置通过 multiCapabilities
配置多个浏览器,在browserstack运行测试。
I have a protractor
setup with multiple browsers configured through multiCapabilities
, running tests on browserstack.
我的一个关键量角器规格的/测试包含以下 afterEach()
块:
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).
的问题是:当我运行针对Internet Explorer的这个天赋,我发现了一个不明错误
:
The problem is: when I run this spec against Internet Explorer, I'm getting an UnknownError
:
不明错误:找不到命令:POST /会话/ 6b838fe8-f4a6-4b31-B245-f4bf8f37537c /日志
UnknownError: Command not found: POST /session/6b838fe8-f4a6-4b31-b245-f4bf8f37537c/log
一个快速研究后,我发现, IE硒的webdriver
尚不支持会话日志:
After a quick research, I've found out that IE selenium webdriver
does not yet support session logs:
- [IE] Add support for fetching logs using the webdriver.manage().logs() mechanism
现在的问题是:我怎么能抓住这个不明错误
,让规范通在此特定错误的情况下
The question is: how can I catch this UnknownError
and let the spec pass in case of this specific error?
或者,围着它转,是有可能有一个 afterEach()
块能力/浏览器特定的,或者知道当前运行的能力是什么呢?
Or, to turn it around, is it possible to have an afterEach()
block capability/browser-specific, or know which currently running capability is it?
我试图用的try / catch
并试图依靠例外发件人
,但的console.log()
不执行:
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);
}
});
作为一种解决办法,我重复相同的规范,但没有不及格的 afterEach()
块,专门针对IE浏览器。
As a workaround, I'm duplicating the same spec but without that failing afterEach()
block, specifically for Internet Explorer.
推荐答案
找到一个选择 - 使用的 的getCapabilities()
检索当前浏览器的名称:
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);
});
}
});
});
在这种情况下,浏览器日志将不会对是否Internet Explorer中运行检查。
In this case browser logs would not be checked if running against Internet Explorer.
这篇关于在处理未知量角器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!