Check there were no errors in the browser console with Protractor

后端 未结 4 1102
南旧
南旧 2021-02-14 10:38

I\'m using Protractor to test AngularJS

I want to check that at the end of the test no uncaught exceptions occurred and were printed to the browser console.

Is t

4条回答
  •  一向
    一向 (楼主)
    2021-02-14 11:02

    With a little effort we can tweak the accepted answer to work with Cucumber.js, in case you're not using Protractor with the default testing framework.

    this.After(function(callback) {
        browser.manage().logs().get('browser').then(function(browserLog) {
            if (browserLog.length !== 0) {
                var failMessage = "There was output in the browser console:" +
                                  browserLog.map(JSON.stringify).join(";\n");
                callback.fail(failMessage);
            }
            else {
                callback();
            }
        });
    });
    

    You'll want to check out the documentation on After hooks, which are Cucumber's equivalent to Jasmine's afterEach.

提交回复
热议问题