zoukankan      html  css  js  c++  java
  • [Protractor] Use protractor to catch errors in the console

    For any reason, there is an error in your code, maybe something like undefined error. Protractor still has all the test cases passing, but our application has some problem.

    Or let's say in production code, we want check whether we have cleaned all of our console.log() code in the console. 

    To do that we can add an afertEach() block:

      afterEach(function () {
        browser.manage().logs().get('browser').then(function (browserLog) {
          expect(browserLog.length).toEqual(0);
          if (browserLog.length) console.error('log: ' + JSON.stringify(browserLog));
        });
      });

    ----------------

    Code:

    var IndexPage = require('./IndexPage');
    
    describe('hello-protractor', function () {
    
      var page = new IndexPage();
    
      beforeEach(function() {
          page.get();
      });
    
      afterEach(function () {
        browser.manage().logs().get('browser').then(function (browserLog) {
          expect(browserLog.length).toEqual(0);
          if (browserLog.length) console.error('log: ' + JSON.stringify(browserLog));
        });
      });
    
      describe('index', function () {
        it('should display the correct title', function () {
          expect(page.getTitle()).toBe('hello protractor');
        });
    
        it('should display the message when button clicked', function () {
          page.clickButton();
    
          expect(page.getMessageText()).toBe('button 1 clicked');
        });
      });
    });
  • 相关阅读:
    构建之法阅读笔记03
    构建之法阅读笔记02
    构建之法阅读笔记01
    人月神话阅读笔记03
    人月神话阅读笔记02
    人月神话阅读笔记01
    关于APP“跑跑”
    软件设计模式24
    软件构造9
    软件构造8
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5204269.html
Copyright © 2011-2022 走看看