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');
});
});
});

[Protractor] Use protractor to catch errors in the console的更多相关文章

  1. log4j报错ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

    ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only err ...

  2. Angular+Grunt+Bower+Karma+Protractor (Atom)

    1. 配置bower 1.安装bower npm install -g bower 2.创建.bowerrc文件 { "directory": "src/bower&qu ...

  3. angular自动化测试--protractor

    前戏 面向模型编程: 测试驱动开发: 先保障交互逻辑,再调整细节.---by 雪狼. 为什么要自动化测试? 1,提高产出质量. 2,减少重构时的痛.反正我最近重构多了,痛苦经历多了. 3,便于新人接手 ...

  4. 自动化测试--protractor

    前戏 面向模型编程: 测试驱动开发: 先保障交互逻辑,再调整细节.---by 雪狼. 为什么要自动化测试? 1,提高产出质量. 2,减少重构时的痛.反正我最近重构多了,痛苦经历多了. 3,便于新人接手 ...

  5. debug protractor

    HTAir:protractor-cucumber-typescript kbladewht$ node --inspect-brk=0.0.0.0:1229 node_modules/protrac ...

  6. Node.js+Protractor+vscode搭建测试环境(1)

    1.protractor简介 官网地址:http://www.protractortest.org/ Protractor是一个end-to-end的测试框架,从网络上得到的答案是Protractor ...

  7. C++异常处理:try,catch,throw,finally的用法

    写在前面 所谓异常处理,即让一个程序运行时遇到自己无法处理的错误时抛出一个异常,希望调用者可以发现处理问题. 异常处理的基本思想是简化程序的错误代码,为程序键壮性提供一个标准检测机制. 也许我们已经使 ...

  8. C++异常处理: try,catch,throw,finally的用法

    写在前面 所谓异常处理,即让一个程序运行时遇到自己无法处理的错误时抛出一个异常,希望调用者可以发现处理问题. 异常处理的基本思想是简化程序的错误代码,为程序键壮性提供一个标准检测机制. 也许我们已经使 ...

  9. [Lua] try catch实现

    参考了https://blog.csdn.net/waruqi/article/details/53649634这里的代码,但实际使用时还有些问题,修改后在此记录一下. -- 异常捕获 functio ...

随机推荐

  1. Unity 触屏缩放模型

    现在的手机都是触屏控制的,那么在游戏中我们想通过手指在屏幕上滑动捕获相应的动作呢?Unity官网API中提供了Input类和Touch类,在该类里提供了许多接口.相信只要我们稍微看下,就可以自己应用了 ...

  2. C#基础:C#4.0权威指南 杂笔一

    1.c#中数组初始化的几种不同用法     int[] name = new int[NUM];       int[] name = {1, 2, 3, 4, 5, 6};       int[] ...

  3. Web App 前端构建(纯净版)

    asp.net 母版页: <!DOCTYPE html> <html> <head> <meta charset="utf-8" name ...

  4. linq读书笔记1-linq 初步

    至于linq是什么之类的已经有过太多的文章介绍,亦不清楚的胡朋友可以自己搜索一下便可以得到大量的答案 为了体验linq究竟能带给我们什么体验,我们直接从代码入手: string[] words = n ...

  5. nginx和apache的特点优点和使用场景

    Apache   Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一.   Apache源于 ...

  6. Oracle函数function

    --function /* 函数是有返回值.-只能有一个返回值. 语法 Create or replace func1(参数) Return varchar2 As Pl/sql块 Return 'J ...

  7. Parser Error Message: Access is denied【转】

    PRB: Access Denied Error When You Make Code Modifications with Index Services Running View products ...

  8. JSON转Model内部实现解析

    一.思路: 1.通过模型类型获得所有的属性和其类型 2.对获得的json进行处理.类型处理 3.考虑字典键值和模型属性名不一致的情况 4.添加code用于归档 5.补充JSON转字典.字典转JSON. ...

  9. [转载]opencv +linux

    转载 ubuntu12.04安装openCV2.4.2(2012-08-08 16:54:06 参考http://www.samontab.com/web/2012/06/installing-ope ...

  10. C/C++中的空类及抽象类大小

    代码: #include <iostream> using namespace std; struct A{ }; struct B{ int i; }; class C:B{ ; }; ...