@bornkiller
2014-12-31T03:46:13.000000Z
字数 3041
阅读 2949
angularjs
angular的E2E全面采用protractor作为测试工具,放弃原来的scenario runner。工具基于selenium,webDriverJS,使用node封装而来。在安装路上遇到不少问题,所以单独记录安装过程。
// first stepnpm install -g protractor// second stepwebdriver-manager update// third stepwebdriver-manager start
问题出在第二步,输出信息如下:
[root@iZ9466vz8yvZ ~]# webdriver-manager updateUpdating selenium standalonedownloading https://selenium-release.storage.googleapis.com/2.44/selenium-server-standalone-2.44.0.jar...Updating chromedriverdownloading 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.zipError: 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 startseleniumProcess.pid: 1147911:08:02.567 INFO - Launching a standalone server11:08:02.610 INFO - Java: Oracle Corporation 24.71-b0111:08:02.611 INFO - OS: Linux 2.6.32-431.23.3.el6.i686 i38611:08:02.623 INFO - v2.44.0, with Core v2.44.0. Built from revision 76d78cf11: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: LINUX11:08:02.779 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub11:08:02.781 INFO - Version Jetty/5.1.x11: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@1d7413811:08:02.800 INFO - Started HttpContext[/wd,/wd]11:08:02.804 INFO - Started SocketListener on 0.0.0.0:444411:08:02.804 INFO - Started org.openqa.jetty.jetty.Server@1639615
表明selenium server处于开启状态。
protractor运行需要两种文件,配置文件和测试文件。官方提供的tutorial配置文件有误,肯定会报错。修改如下即可:
// An example configuration fileexports.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.jsdescribe('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