在我的测试中,我需要检查单击按钮后控制台中是否有错误。但是我得到的唯一错误是来自登录页面,然后在页面加载之后。但按钮点击后没有任何东西,我知道有错误发生。如果没有错误,就有日志。我的功能似乎也没有捕捉到这些。这很令人沮丧。这是我的代码。 (我在我的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从这里回答 - http://stackoverflow.com/questions/27415507/doing-something-aftereach-describe-in-protractor-with-selenium-server-with-angul –
我不看看从afterEach到afterAll的变化将产生不同的效果 – cocoa
您是否尝试过使用内置于量角器的控制台插件?谢谢。 – alecxe