Angular E2E 测试之路一

前言

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

安装流程

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

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

[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),可以使用浏览器下载两个文件,放置路径为

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

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

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

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

[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配置文件有误,肯定会报错。修改如下即可:

// 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.
  }
};

测试文件

// 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

脚本宝典为你提供优质服务
脚本宝典 » Angular E2E 测试之路一

发表评论

提供最优质的资源集合

立即查看 了解详情