【问题标题】:Configurate Protractor to ignore browser console errors配置量角器以忽略浏览器控制台错误
【发布时间】:2017-04-14 01:56:10
【问题描述】:

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

但是当我运行 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$ 

【问题讨论】:

    标签: javascript angularjs testing protractor


    【解决方案1】:

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

    听起来您正在使用 protractor-console-plugin 并将 failOnWarning 设置为 true,请修复它:

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

    【讨论】:

    • 感谢您的回答,但这不是测试失败的原因。在测试之前我没有安装那个插件。现在我尝试安装该插件并像这样配置它: plugins: [{ package: 'protractor-console-plugin', failOnWarning: false, failOnError: false, logWarnings: false }] 它对我没有帮助。控制台错误后 Protracktor 测试失败。还有一些其他机制,在控制台错误后测试失败。你知道这个任务的其他配置功能吗?
    • @pj-infest 很有趣!您能否提供更多详细信息:您的量角器配置和您正在执行的测试?谢谢。
    • @pj-infest 您能否尝试将量角器升级到最新版本并使用jasmine2 而不是 jasmine - 有帮助吗?谢谢。
    • jasmine2 npm 包的名称是什么?
    • @pj-infest 我的错,别管它jasmine - 最新的量角器会自动使用最新的 jasmine - jasmine2。
    猜你喜欢
    • 2021-10-14
    • 1970-01-01
    • 1970-01-01
    • 2020-04-13
    • 2014-09-23
    • 2018-01-31
    • 2013-01-25
    • 1970-01-01
    • 2018-03-30
    相关资源
    最近更新 更多