[关闭]
@bornkiller 2014-12-31T11:46:13.000000Z 字数 3041 阅读 2688

Angular E2E 测试之路一

angularjs


前言

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

安装流程

  1. // first step
  2. npm install -g protractor
  3. // second step
  4. webdriver-manager update
  5. // third step
  6. webdriver-manager start

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

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

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

  1. //mkdir selenium manually
  2. /usr/local/lib/node_modules/protractor/selenium

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

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

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

  1. [root@iZ9466vz8yvZ ~]# webdriver-manager start
  2. seleniumProcess.pid: 11479
  3. 11:08:02.567 INFO - Launching a standalone server
  4. 11:08:02.610 INFO - Java: Oracle Corporation 24.71-b01
  5. 11:08:02.611 INFO - OS: Linux 2.6.32-431.23.3.el6.i686 i386
  6. 11:08:02.623 INFO - v2.44.0, with Core v2.44.0. Built from revision 76d78cf
  7. 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
  8. 11:08:02.779 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
  9. 11:08:02.781 INFO - Version Jetty/5.1.x
  10. 11:08:02.781 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
  11. 11:08:02.782 INFO - Started HttpContext[/selenium-server,/selenium-server]
  12. 11:08:02.782 INFO - Started HttpContext[/,/]
  13. 11:08:02.799 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@1d74138
  14. 11:08:02.800 INFO - Started HttpContext[/wd,/wd]
  15. 11:08:02.804 INFO - Started SocketListener on 0.0.0.0:4444
  16. 11:08:02.804 INFO - Started org.openqa.jetty.jetty.Server@1639615

表明selenium server处于开启状态。

使用

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

  1. // An example configuration file
  2. exports.config = {
  3. // The address of a running selenium server.
  4. seleniumAddress: 'http://localhost:4444/wd/hub',
  5. // Capabilities to be passed to the webdriver instance.
  6. capabilities: {
  7. 'browserName': 'chrome'
  8. },
  9. // Spec patterns are relative to the configuration file location passed
  10. // to protractor (in this example conf.js).
  11. // They may include glob patterns.
  12. specs: ['index.spec.js'],
  13. directConnect: true,
  14. // Options to be passed to Jasmine-node.
  15. jasmineNodeOpts: {
  16. showColors: true // Use colors in the command line report.
  17. }
  18. };

测试文件

  1. // spec.js
  2. describe('snowykiss homepage', function() {
  3. it('should have a title', function() {
  4. browser.get('http://127.0.0.1:1336/');
  5. expect(browser.getTitle()).toEqual('web worker');
  6. });
  7. });

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

联系方式

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

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注