行动后错误量角器检查控制台 [英] Protractor check console for errors after action

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

问题描述

在我的测试中,我需要检查是否有错误在控制台中点击一个按钮后。但唯一的错误,我得到的是从登录页面,然后在页面加载后。但没有按钮点击之后,我知道有错误发生。如果有没有错误,也有记录。我的功能似乎并没有捕捉到那些无论是。这是pretty沮丧。这里是我的code。 (我在我的 config.js 文件登录code)

In my test I need to check if there are errors in the console after clicking a button. But the only errors I get are from the login page, then when the page loads after that. But nothing after the button click, and I know there are errors happening. And if there's not errors, there are logs. My function doesn't seem to capture those either. It's pretty frustrating. Here's my code. (I have the login code in my config.js file.)

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
  });
});

我缺少的东西吗?是否有不同的/更好的方式来做到这一点?

Am I missing something? Is there a different/better way to do this?

推荐答案

如果你只想按钮单击事件后,检查错误,那么你可以写你的 checkConsoleErrors()点击事件的承诺,而不是 afterEach内部功能(​​)。下面是如何 -

If you want to check for errors only after button click event, then you can write your checkConsoleErrors() function inside click event's promise instead of afterEach(). Here's how -

btn.click().then(function(){
    timestamp = moment().valueOf();
    browser.sleep(10000);
    checkConsoleErrors();
});

借助错误日志级别值该浏览器还给到控制台通常 800 (用于信息) 900 (用于警告)的,这样你检查上述值的code不打印任何东西900 。高于900水平这显示时出现致命错误(例如,执行停止,因为一个包的问题,​​无效的路径等)的严重消息。要查看错误,你的执行产生调整水平> = 900 来显示所需的信息。希望这有助于。

The error log level values that browser gives back to console are usually 800 (for info) and 900 (for warning), so your code doesn't print anything as you are checking for values above 900. Levels above 900 are severe messages which display when fatal errors occur (ex, execution stopped because of a package issue, invalid path, etc). To see for error that your execution creates adjust the levels >=900 to show the required messages. Hope this helps.

这篇关于行动后错误量角器检查控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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