Angular E2E 测试之路一

发布时间:2019-06-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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 测试之路一全部内容,希望文章能够帮你解决Angular E2E 测试之路一所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。