博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自动化端对端测试框架-Protractor Reference 3
阅读量:7080 次
发布时间:2019-06-28

本文共 11606 字,大约阅读时间需要 38 分钟。

hot3.png

Upgrading from Jasmine 1.3 to 2.x

First, please read .

In your conf file

Specify that you want to use jasmine2.x:

exports.config = {  // Specify you want to use jasmine 2.x as you would with mocha. Note, 'jasmine' by default will use the latest jasmine framework.  framework: 'jasmine'};

Similar to jasmine 1.3, you may include jasmineNodeOpts in the config file. However, because we changed the runner from "" to "", the options have changed slightly. In particular, we will only support the options in the official "jasmine-npm":

jasmineNodeOpts: {  // If true, print colors to the terminal.  showColors: true,  // Default time to wait in ms before a test fails.  defaultTimeoutInterval: 30000,  // Function called to print jasmine results.  print: function() {},  // If set, only execute specs whose names match the pattern, which is  // internally compiled to a RegExp.  grep: 'pattern',  // Inverts 'grep' matches  invertGrep: false}

Notably options print and grep are new, but we will no longer support options isVerbose and includeStackTrace (unless, of course, "jasmine-npm" introduces these options).

In your specs

Focused specs

Instead of iit, please use fit. Instead of ddescribe, please use fdescribe.

Timeouts

Having a custom timeout for an it block as a third parameter is not currently supported in Jasmine2, but it will be supported in a release soon. See .

Custom matchers

See 

Before:

toHaveText: function(expectedText) {  return this.actual.getText().then(function(actualText) {    return expectedText === actualText;  });}

Now:

toHaveText: function() {  return {    compare: function(actual, expectedText) {      return {        pass: actual.getText().then(function(actualText) {          return actualText === expectedText;        })      };    }  };}

Asynchronous specs

Note: minijasminenode provided asynchronous support for jasmine1.3 before (i.e. via done callback). Jasmine 2.x now provides the support natively, but the change is mostly transparent to protractor users who are upgrading from jasmine1.3.

You can still pass in the done parameter as part of your asynchronous spec, but the syntax for failing it has changed.

Before:

it('async spec', function(done) {  setTimeout(function() {    if (passed) {      done(); // When done    } else {      done('failure message'); // To fail spec    }  }, 5000);});

Now:

it('async spec', function(done) {  setTimeout(function() {    if (passed) {      done(); // When done    } else {      done.fail('failure message'); // To fail spec    }  }, 5000);});

Reporters

The syntax for custom reporters has changed for Jasmine2. If you were previously adding reporters from a node module, such as the jasmine-reporters package on npm, make sure you upgrade to a version which supports Jasmine2. If you are writing your own reporter, see the .

Mobile Setup

There are many options for using WebDriver to test on mobile browsers. Protractor does not yet officially support or run its own tests against a particular configuration, but the following are some notes on various setup options.

Setting Up Protractor with Appium - Android/Chrome

Setup
  • Install Java SDK (>1.6) and configure JAVA_HOME (Important: make sure it's not pointing to JRE).

  • Follow  to install and set up Android developer environment. Do not set up Android Virtual Device as instructed here.

  • From commandline, android avd and then install an AVD, taking note of the following:

    • Start with an ARM ABI

    • Enable hardware keyboard: hw.keyboard=yes

    • Enable hardware battery: hw.battery=yes

    • Use the Host GPU

    • Here's an example:

Phone:

> android list avdAvailable Android Virtual Devices:    Name: LatestAndroid  Device: Nexus 5 (Google)    Path: /Users/hankduan/.android/avd/LatestAndroid.avd  Target: Android 4.4.2 (API level 19) Tag/ABI: default/armeabi-v7a    Skin: HVGA

Tablet:

> android list avdAvailable Android Virtual Devices:    Name: LatestTablet  Device: Nexus 10 (Google)    Path: /Users/hankduan/.android/avd/LatestTablet.avd  Target: Android 4.4.2 (API level 19) Tag/ABI: default/armeabi-v7a    Skin: WXGA800-7in

  • Follow  to install ant and set up the environment.

  • Follow  to install mvn (Maven) and set up the environment. 

    • NOTE: Appium suggests installing Maven 3.0.5 (I haven't tried later versions, but 3.0.5 works for sure).

  • Install Appium using node npm install -g appium. Make sure you don't install as sudo or else Appium will complain.

    • You can do this either if you installed node without sudo, or you can chown the global node_modules lib and bin directories.

  • Start emulator manually (at least the first time) and unlock screen.

> emulator -avd LatestAndroid

  • Your devices should show up under adb now:

> adb devicesList of devices attached emulator-5554 device

  • If the AVD does not have chrome (and it probably won't if it just created), you need to install it:

    • You can get v34.0.1847.114 from 

    • Once you download the apk, install to your AVD as such:

> adb install ~/Desktop/chrome-browser-google-34.0.1847.114-www.apk4fun.com.apk 2323 KB/s (30024100 bytes in 12.617s)Success

  • If you check your AVD now, it should have Chrome.

Running Tests
  • Ensure app is running if testing local app (Skip if testing public website):

> npm start # or `./scripts/web-server.js`Starting express web server in /workspace/protractor/testapp on port 8000

  • If your AVD isn't already started from the setup, start it now:

> emulator -avd LatestAndroid

  • Start Appium:

> appiuminfo: Welcome to Appium v1.0.0-beta.1 (REV 6fcf54391fb06bb5fb03dfcf1582c84a1d9838b6)info: Appium REST http interface listener started on 0.0.0.0:4723info: socket.io started

Note Appium listens to port 4723 instead of 4444

  • Configure protractor:

exports.config = {  seleniumAddress: 'http://localhost:4723/wd/hub',  specs: ['basic/*_spec.js'],  // Reference: https://github.com/appium/sample-code/blob/master/sample-code/examples/node/helpers/caps.js  capabilities: {    browserName: 'chrome',    'appium-version': '1.0',    platformName: 'Android',    platformVersion: '4.4.2',    deviceName: 'Android Emulator',  },  baseUrl: 'http://10.0.2.2:8000',  // configuring wd in onPrepare  // wdBridge helps to bridge wd driver with other selenium clients  // See https://github.com/sebv/wd-bridge/blob/master/README.md  onPrepare: function () {    var wd = require('wd'),      protractor = require('protractor'),      wdBridge = require('wd-bridge')(protractor, wd);    wdBridge.initFromProtractor(exports.config);  }};

Note the following:

  • baseUrl is 10.0.2.2 instead of localhost because it is used to access the localhost of the host machine in the android emulator 

  • selenium address is using port 4723

Setting Up Protractor with Appium - iOS/Safari

Setup
  • Install Java SDK (>1.6) and configure JAVA_HOME (Important: make sure it's not pointing to JRE).

  • Follow  to install ant and set up the environment.

  • Follow  to install mvn (Maven) and set up the environment. 

    • NOTE: Appium suggests installing Maven 3.0.5 (I haven't tried later versions, but 3.0.5 works for sure).

  • Install Appium using node npm install -g appium. Make sure you don't install as sudo or else Appium will complain.

    • You can do this either if you installed node without sudo, or you can chown the global node_modules lib and bin directories.

  • Run the following: appium-doctor and authorize_ios (sudo if necessary)

  • You need XCode >= 4.6.3, 5.1.1 recommended. Note, iOS8 (XCode 6) did not work off the shelf (see ) but this was resolved 

Running Tests
  • Ensure app is running if testing local app (Skip if testing public website):

> npm start # or `./scripts/web-server.js`Starting express web server in /workspace/protractor/testapp on port 8000

  • Start Appium:

> appiuminfo: Welcome to Appium v1.0.0-beta.1 (REV 6fcf54391fb06bb5fb03dfcf1582c84a1d9838b6)info: Appium REST http interface listener started on 0.0.0.0:4723info: socket.io started

Note: Appium listens to port 4723 instead of 4444.

  • Configure protractor:

additional dependencies:

npm install --save-dev wd wd-bridge

iPhone:

exports.config = {  seleniumAddress: 'http://localhost:4723/wd/hub',  specs: [    'basic/*_spec.js'  ],  // Reference: https://github.com/appium/sample-code/blob/master/sample-code/examples/node/helpers/caps.js  capabilities: {    browserName: 'safari',    'appium-version': '1.0',    platformName: 'iOS',    platformVersion: '7.1',    deviceName: 'iPhone Simulator',  },  baseUrl: 'http://localhost:8000',  // configuring wd in onPrepare  // wdBridge helps to bridge wd driver with other selenium clients  // See https://github.com/sebv/wd-bridge/blob/master/README.md  onPrepare: function () {    var wd = require('wd'),      protractor = require('protractor'),      wdBridge = require('wd-bridge')(protractor, wd);    wdBridge.initFromProtractor(exports.config);  }};

iPad:

exports.config = {  seleniumAddress: 'http://localhost:4723/wd/hub',  specs: [    'basic/*_spec.js'  ],  // Reference: https://github.com/appium/sample-code/blob/master/sample-code/examples/node/helpers/caps.js  capabilities: {    browserName: 'safari',    'appium-version': '1.0',    platformName: 'iOS',    platformVersion: '7.1',    deviceName: 'IPad Simulator',  },  baseUrl: 'http://localhost:8000',  // configuring wd in onPrepare  // wdBridge helps to bridge wd driver with other selenium clients  // See https://github.com/sebv/wd-bridge/blob/master/README.md  onPrepare: function () {    var wd = require('wd'),      protractor = require('protractor'),      wdBridge = require('wd-bridge')(protractor, wd);    wdBridge.initFromProtractor(exports.config);  }};

Note the following:

  • note capabilities

  • baseUrl is localhost (not 10.0.2.2)

  • selenium address is using port 4723

Setting Up Protractor with Selendroid

Setup
  • Install Java SDK (>1.6) and configure JAVA_HOME (Important: make sure it's not pointing to JRE).

  • Follow  to install and set up Android developer environment. Do not set up Android Virtual Device as instructed here.

  • From commandline, 'android avd' and then follow Selendroid's recommendation (). Take note of the emulator accelerator. Here's an example:

> android list avdAvailable Android Virtual Devices:    Name: myAvd  Device: Nexus 5 (Google)    Path: /Users/hankduan/.android/avd/Hank.avd  Target: Android 4.4.2 (API level 19) Tag/ABI: default/x86    Skin: WVGA800

Running Tests
  • Ensure app is running if testing local app (Skip if testing public website):

> npm start # or `./scripts/web-server.js`Starting express web server in /workspace/protractor/testapp on port 8000

  • Start emulator manually (at least the first time):

> emulator -avd myAvdHAX is working and emulator runs in fast virt mode

Note: The last line that tells you the emulator accelerator is running.

  • Start selendroid:

> java -jar selendroid-standalone-0.9.0-with-dependencies.jar...

  • Once selendroid is started, you should be able to go to "" and see your device there:

{"value":{"os":{"name":"Mac OS X","arch":"x86_64","version":"10.9.2"},"build":{"browserName":"selendroid","version":"0.9.0"},"supportedDevices":[{"emulator":true,"screenSize":"WVGA800","avdName":"Hank","androidTarget":"ANDROID19"}],"supportedApps":[{"mainActivity":"io.selendroid.androiddriver.WebViewActivity","appId":"io.selendroid.androiddriver:0.9.0","basePackage":"io.selendroid.androiddriver"}]},"status":0}

  • Configure protractor:

exports.config = {  seleniumAddress: 'http://localhost:4444/wd/hub',  specs: [    'basic/*_spec.js'  ],  capabilities: {    'browserName': 'android'  },  baseUrl: 'http://10.0.2.2:8000'};

Note the following:

  • browserName is 'android'

  • baseUrl is 10.0.2.2 instead of localhost because it is used to access the localhost of the host machine in the android emulator

转载于:https://my.oschina.net/u/658505/blog/665177

你可能感兴趣的文章
Python多线程一学就会!
查看>>
django 常用 import
查看>>
安卓手机APP压力monkey测试
查看>>
NGS数据的Duplication
查看>>
Modelsim-altera 仿真 顶层原理图设计的FPGA
查看>>
【jQuery插件】用jQuery Masonry快速构建一个pinterest网站布局(转)
查看>>
PHP权限控制(转)
查看>>
谈谈easyui datagrid 的数据加载(转)
查看>>
团队博客
查看>>
2012-2013 ACM-ICPC, NEERC, Central Subregional Contest
查看>>
[转]What is closure
查看>>
C#设计模式-1简单工厂模式Simple Factory)
查看>>
Android动画分析
查看>>
最优非对称加密填充(OAEP)和PSS(Probabilistic Signature Scheme)
查看>>
【Android游戏开发之二】剖析游戏开发用view还是surfaceView ?!
查看>>
JVM核心机制(类加载器、三种类加载器、代理加载模式、双亲委派机制
查看>>
接收发送邮件
查看>>
python 函数参数多种传递方法
查看>>
leetcode-482-License Key Formatting
查看>>
IE6 下 z-index 设置的 DIV 偏移位置的解决方法
查看>>