Check there were no errors in the browser console with Protractor

后端 未结 4 1120
南旧
南旧 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:16

    If you're using Protractor with Jasmine, use the following code:

    afterEach(function() {
        browser.manage().logs().get('browser').then(function(browserLog) {
            expect(browserLog.length).toEqual(0);
        });
    });
    

    This will pass the test case if there are no console errors. If there are any console errors, the test will fail.

    Instructions on how to access the content of the browser's console can be found in the How can I get hold of the browser's console section of the FAQ.

提交回复
热议问题