【发布时间】:2015-11-18 03:33:28
【问题描述】:
在我的测试中,我需要在单击按钮后检查控制台中是否有错误。但是我得到的唯一错误来自登录页面,然后是页面加载时。但是单击按钮后什么也没有,我知道发生了错误。如果没有错误,就会有日志。我的功能似乎也没有捕捉到这些。这很令人沮丧。这是我的代码。 (我的config.js 文件中有登录代码。)
function checkConsoleErrors() {
browser.manage().logs().get('browser').then(function (browserLog) {
if (browserLog.length) {
browserLog.forEach(function(log){
var error = log.level.value > 900;
if(error) {
console.error('ERROR: ', log.message);
if (log.timestamp > timestamp) {
expect(error).toBeFalsy(); //only check for errors after the button click
}
}
});
}
});
}
describe('Errors', function() {
afterEach(function() {
checkConsoleErrors();
});
it('should have no errors', function() {
//code here
btn.click();
timestamp = moment().valueOf(); //capture the time the button was clicked
browser.sleep(10000); //wait
});
});
我错过了什么吗?有没有其他/更好的方法来做到这一点?
【问题讨论】:
-
从这里尝试@alecxe 的答案-stackoverflow.com/questions/27415507/…
-
我看不出从
afterEach更改为afterAll会有什么不同的效果 -
您是否尝试过使用量角器内置的控制台插件?谢谢。
-
@alecxe 是的,我有,我帮助不大。当出现错误时它会通过,即使将 failOnWarning 和 failOnError 标记为 true
标签: javascript angularjs protractor