Angular E2E 测试之路一

前言

angularE2E全面采用protractor作为测试工具,放弃原来的scenario runner。工具基于seleniumwebDriverJS,使用node封装而来。在安装路上遇到不少问题,所以单独记录安装过程。

安装流程

shell// first step
npm install -g protractor
// second step 
webdriver-manager update
// third step
webdriver-manager start

问题出在第二步,输出信息如下:

shell[root@iZ9466vz8yvZ ~]# webdriver-manager update
Updating selenium standalone
downloading https://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar...
Updating chromedriver
downloading https://chromedriver.storage.googleapis.com/2.12/chromedriver_linux32.zip...
Error: Got error Error: connect ETIMEDOUT from https://chromedriver.storage.googleapis.com/2.12/chromedriver_linux32.zip
Error: Got error Error: connect ETIMEDOUT from https://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar

从路径上判断,肯定是抵御"外敌"!!!"入侵"!!!的屏障没有放行。如果浏览器能够穿越(goagent),可以使用浏览器下载两个文件,放置路径为

shell//mkdir selenium manually 
/usr/local/lib/node_modules/protractor/selenium

注意,chromeDriver是个zip文件,不用解压。

为了后期使用方便,可以采用一种比较呆萌的处理方式。下载之后文件放在本地HTTP服务器上,在其它机器上安装的时候,直接改机器的hosts文件,将上面两条路由指向放置文件的服务器即可。

然后执行第三部,输出信息如下:

shell[root@iZ9466vz8yvZ ~]# webdriver-manager start
seleniumProcess.pid: 11479
11:08:02.567 INFO - Launching a standalone server
11:08:02.610 INFO - Java: Oracle Corporation 24.71-b01
11:08:02.611 INFO - OS: Linux 2.6.32-431.23.3.el6.i686 i386
11:08:02.623 INFO - v2.44.0, with Core v2.44.0. Built from revision 76d78cf
11:08:02.719 INFO - Default driver org.openqa.selenium.ie.InternetExplorerDriver registration is skipped: registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match with current platform: LINUX
11:08:02.779 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
11:08:02.781 INFO - Version Jetty/5.1.x
11:08:02.781 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
11:08:02.782 INFO - Started HttpContext[/selenium-server,/selenium-server]
11:08:02.782 INFO - Started HttpContext[/,/]
11:08:02.799 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@1d74138
11:08:02.800 INFO - Started HttpContext[/wd,/wd]
11:08:02.804 INFO - Started SocketListener on 0.0.0.0:4444
11:08:02.804 INFO - Started org.openqa.jetty.jetty.Server@1639615

表明selenium server处于开启状态。

使用

protractor运行需要两种文件,配置文件和测试文件。官方提供的tutorial配置文件有误,肯定会报错。修改如下即可:

javascript// An example configuration file
exports.config = {
  // The address of a running selenium server.
  seleniumAddress: 'http://localhost:4444/wd/hub',

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  // Spec patterns are relative to the configuration file location passed
  // to protractor (in this example conf.js).
  // They may include glob patterns.
  specs: ['index.spec.js'],

  directConnect: true,

  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true // Use colors in the command line report.
  }
};

测试文件

javascript// spec.js
describe('snowykiss homepage', function() {
  it('should have a title', function() {
    browser.get('http://127.0.0.1:1336/');
    expect(browser.getTitle()).toEqual('web worker');
  });
});

文档说,页面只要引入angular.js文件,就不会报错,但测试的时候本地出现问题。待测试页面为完整的angular application,即在body上引入ng-app指令后,不会抛错。

联系方式

Email:hjj491229492@hotmail.com
https://github.com/bornkiller

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值