将Protractor配置为忽略浏览器控制台错误

Configurate Protractor to ignore browser console errors

本文关键字:浏览器 控制台 错误 Protractor 配置      更新时间:2023-09-26

我试图为web应用程序编写测试,但有一些困难。当我使用网络应用程序时,我在浏览器控制台中遇到了一些角度错误。这不是致命的错误,它们不会干扰应用程序的执行。

但当我运行Protractor测试时,它会在第一个浏览器控制台错误时失败。

是否有一种方法可以将Protractor测试配置为执行测试场景并检查场景获取结果,忽略这些浏览器控制台错误?

我的测试文件:

var
    testingAdress = 'http://localhost:1340',
describe('admin avtorization test', function(){
    beforeEach(function(){
        // should be called before each it block
    });
    it('should avtorizate as admin', function(){
        browser.get(testingAdress);
        expect(browser.getCurrentUrl()).toEqual('localhost:1340'+'/#!/');
        //element(by.linkText('Sign Up')).click();
        //expect(browser.getCurrentUrl()).toEqual(testingAdress + '/#!/signup');
        //element(by.id('myLink').click());
        //expect(browser.getCurrentUrl()).toEqual("http://myUrl.com");
    });
});

我的配置文件:

exports.config = {
    directConnect: true,
    // Capabilities to be passed to the webdriver instance.
    capabilities: {
        //'browserName': 'firefox'
        'browserName': 'chrome'
    },
    // Framework to use. Jasmine is recommended.
    framework: 'jasmine',
    // Spec patterns are relative to the current working directory when
    // protractor is called.
    specs: ['spec/avtorization_test.js'],
    // Options to be passed to Jasmine.
    jasmineNodeOpts: {
        defaultTimeoutInterval: 30000
    },
    plugins: [{
        package: 'protractor-console-plugin',
        failOnWarning: false,
        failOnError: false,
        logWarnings: false
    }]
};

这是我在浏览器控制台上的错误

unreachable code after return statement application.js:27995:8
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.5.2/$rootScope/infdig?p0=10&p1=%5B%5D
 application.js:71011:12
"Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.5.2/$rootScope/infdig?p0=10&p1=%5B%5D
minErr/<@http://localhost:1340/js/application.js:71011:12
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:1340/js/application.js:87720:1
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:1340/js/application.js:87946:13
bootstrapApply@http://localhost:1340/js/application.js:72656:9
invoke@http://localhost:1340/js/application.js:75568:16
bootstrap/doBootstrap@http://localhost:1340/js/application.js:72654:1
bootstrap@http://localhost:1340/js/application.js:72674:1
[29]</</<@http://localhost:1340/js/application.js:120390:3
trigger@http://localhost:1340/js/application.js:74070:7
defaultHandlerWrapper@http://localhost:1340/js/application.js:74360:3
createEventHandler/eventHandler@http://localhost:1340/js/application.js:74348:9
" application.js:84237:18
Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.5.2/$rootScope/infdig?p0=10&p1=%5B%5D
 application.js:71011:12
"Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.5.2/$rootScope/infdig?p0=10&p1=%5B%5D
minErr/<@http://localhost:1340/js/application.js:71011:12
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:1340/js/application.js:87720:1
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:1340/js/application.js:87946:13
done@http://localhost:1340/js/application.js:82267:36
completeRequest@http://localhost:1340/js/application.js:82465:7
requestLoaded@http://localhost:1340/js/application.js:82406:1
"

量角器测试结果控制台文本:

roman@rmk-pc:~/agroapp/test$ protractor config.js
Using ChromeDriver directly...
[launcher] Running 1 instances of WebDriver
Started
F
Failures:
1) admin avtorization test should avtorizate as admin
  Message:
    Failed: unknown error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
    Watchers fired in the last 5 iterations: []
    http://errors.angularjs.org/1.5.2/$rootScope/infdig?p0=10&p1=%5B%5D
      (Session info: chrome=49.0.2623.87)
      (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.2.0-34-generic x86_64)
  Stack:
    WebDriverError: unknown error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
    Watchers fired in the last 5 iterations: []
    http://errors.angularjs.org/1.5.2/$rootScope/infdig?p0=10&p1=%5B%5D
      (Session info: chrome=49.0.2623.87)
      (Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 4.2.0-34-generic x86_64)
        at WebDriverError (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/error.js:27:10)
        at Object.checkLegacyResponse (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/error.js:580:13)
        at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:360:15
        at Promise.invokeCallback_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
        at TaskQueue.execute_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
        at TaskQueue.executeNext_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
        at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27
        at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
        at process._tickCallback (node.js:369:9)
    From: Task: Run it("should avtorizate as admin") in control flow
        at Object.<anonymous> (/usr/lib/node_modules/protractor/node_modules/jasminewd2/index.js:81:14)
        at /usr/lib/node_modules/protractor/node_modules/jasminewd2/index.js:18:5
        at Promise.invokeCallback_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
        at TaskQueue.execute_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
        at TaskQueue.executeNext_ (/usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
        at /usr/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27
    From asynchronous test: 
    Error
        at Suite.<anonymous> (/home/roman/agroapp/test/spec/avtorization_test.js:16:5)
        at Object.<anonymous> (/home/roman/agroapp/test/spec/avtorization_test.js:11:1)
        at Module._compile (module.js:409:26)
        at Object.Module._extensions..js (module.js:416:10)
        at Module.load (module.js:343:32)
        at Function.Module._load (module.js:300:12)
1 spec, 1 failure
Finished in 4.334 seconds
Warning from "protractor-console-plugin" plugin: SEVERE: http://localhost:1340/js/application.js 84237:24 Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.5.2/$rootScope/infdig?p0=10&p1=%5B%5D
    at http://localhost:1340/js/application.js:71011:12
    at Scope.$digest (http://localhost:1340/js/application.js:87720:19)
    at Scope.$apply (http://localhost:1340/js/application.js:87946:24)
    at bootstrapApply (http://localhost:1340/js/application.js:72656:15)
    at Object.invoke (http://localhost:1340/js/application.js:75568:19)
    at doBootstrap (http://localhost:1340/js/application.js:72654:14)
    at Object.angular.resumeBootstrap (http://localhost:1340/js/application.js:72682:12)
    at <anonymous>:248:41
    at callFunction (<anonymous>:237:33)
    at <anonymous>:247:23
Warning from "protractor-console-plugin" plugin: SEVERE: http://localhost:1340/js/application.js 84237:24 Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.5.2/$rootScope/infdig?p0=10&p1=%5B%5D
    at http://localhost:1340/js/application.js:71011:12
    at Scope.$digest (http://localhost:1340/js/application.js:87720:19)
    at Scope.$apply (http://localhost:1340/js/application.js:87946:24)
    at done (http://localhost:1340/js/application.js:82267:47)
    at completeRequest (http://localhost:1340/js/application.js:82465:7)
    at XMLHttpRequest.requestLoaded (http://localhost:1340/js/application.js:82406:9)
Warning from "protractor-console-plugin" plugin: SEVERE: http://localhost:1340/js/application.js 71011:12 Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.5.2/$rootScope/infdig?p0=10&p1=%5B%5D
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #01 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
roman@rmk-pc:~/agroapp/test$ 

这不是默认的量角器行为。

听起来你在使用protractor-console-pluginfailOnWarning设置为true,修复它:

plugins: [{
  package: 'protractor-console-plugin',
  failOnWarning: false,
  failOnError: true,
  logWarnings: true
}]