23

Protractor intro

Embed Size (px)

DESCRIPTION

Introduction of Protractor.

Citation preview

Page 1: Protractor intro
Page 2: Protractor intro

Ideal

Actualprotractor.conf.js

Test,Scripts

Selenium,Server

Browser,Drivers

Page 3: Protractor intro

$ npm install protractor

Setup

Page 4: Protractor intro

$ npm install protractor

Setup

$ npm install yo$ sudo ynpm i -g generator-ypr -otractor$ cd your-repo-dir$ yo yprotractor:existing$ ynpm update

Page 5: Protractor intro

$ npm install protractor

Setup

package.json

}, "devDependencies": { "less": "1.7.3", "jslint": "0.5.2", "mojito-cli": "0.1.2", "yahoo-arrow": "~0.5.1", "yhint": "*", "chai": "^1.9.0", "chai-as-promised": "^4.1.0", "mocha": "^1.19.0", "protractor": "1.1.x", "protractor-utils": "0.2.x" },

$ npm install yo$ sudo ynpm i -g generator-ypr -otractor$ cd your-repo-dir$ yo yprotractor:existing$ ynpm update

Page 6: Protractor intro

$ npm install protractor

Setup

package.json

}, "devDependencies": { "less": "1.7.3", "jslint": "0.5.2", "mojito-cli": "0.1.2", "yahoo-arrow": "~0.5.1", "yhint": "*", "chai": "^1.9.0", "chai-as-promised": "^4.1.0", "mocha": "^1.19.0", "protractor": "1.1.x", "protractor-utils": "0.2.x" },

$ npm install yo$ sudo ynpm i -g generator-ypr -otractor$ cd your-repo-dir$ yo yprotractor:existing$ ynpm update

$ git clone xxx.git && cd xxx$ ynpm i

Page 7: Protractor intro

$ npm install webdriver-manager

$ webdriver-manager update --standalone$ webdriver-manager start

Setup

$ npm install protractor

$ git clone xxx.git && cd xxx$ ynpm i

$ webdriver-manager status

$ npm install yo$ sudo ynpm i -g generator-ypr -otractor$ cd your-repo-dir$ yo yprotractor:existing$ ynpm update

Page 8: Protractor intro

$ npm install protractor

$ git clone xxx.git && cd xxx$ ynpm i

$ protractor tests/spec/ protractor.conf.js -- seleniumAddress="..." -- baseUrl="..."

protractor.conf.js

Run

Page 9: Protractor intro

$ npm install protractor

$ git clone xxx.git && cd xxx$ ynpm i

$ protractor tests/spec/ protractor.conf.js -- seleniumAddress="..." -- baseUrl="..."

Run

Using the selenium server at http://10.82.57.93:4444/wd/hub1..2ok 1 Page onload test should match store titlenot ok 2 Universal header shoppingcart checking after click items... ...

# tests 2# pass 1# fail 1

Page 10: Protractor intro

mocha Chai%Asser*on%LibraryProtractor API 1.3.0

Test,Scripts

Page 11: Protractor intro

mocha Chai%Asser*on%LibraryProtractor API 1.3.0

describe('Page onload test', function () {

it('should match store title', function () {

});

});

Page 12: Protractor intro

mocha Chai%Asser*on%LibraryProtractor API 1.3.0

describe('Page onload test', function () {

it('should match store title', function () {

});

});

browser.get('/');

/* global browser, $, it, describe, before */

browser.getTitle()

Page 13: Protractor intro

mocha Chai%Asser*on%LibraryProtractor API 1.3.0

describe('Page onload test', function () {

it('should match store title', function () {

});

});

expect( ).to.eventually.equal('����');

var chai = require(‘chai’), expect = chai.expect, chaiAsPromised = require(‘chai-as-promised’);

chai.use(chaiAsPromised);

browser.get('/');

/* global browser, $, it, describe, before */

browser.getTitle()

Page 14: Protractor intro

Chai%Asser*on%Librarymocha Protractor API 1.3.0

describe('Page onload test', function () {var node, present;

it('store logo should exist', function () {

node = element(by.css(‘.ylogo’));present = node.isPresent();console.log(‘present: ’, present);expect(present).to.equal(true);

});});

Page 15: Protractor intro

Chai%Asser*on%Librarymocha Protractor API 1.3.0

describe('Page onload test', function () {var node, present;

it('store logo should exist', function () {

node = element(by.css(‘.ylogo’));present = node.isPresent();console.log(‘present: ’,present);expect(present).to.eveutually.equal(true);node.isPresent().then(function (_present) {

console.log(‘_present: ’, _present);expect(_present).to.equal(true);

}); });});

Page 16: Protractor intro

Chai%Asser*on%Librarymocha Protractor API 1.3.0

describe('Page onload test', function () {var node, present;

it('check if link works', function () {

node = $(‘.ylogo’);node.getAttribute('href').then(function (_linkUrl) {

browser.getCurrentUrl().then(function (curUrl) { expect(_curUrl).to.contain(_linkUrl);

}).then(function () {

node.click(); });

browser.wait(function () { return browser.getCurrentUrl().then(function (_curUrl) {

return _curUrl === _linkUrl; }, TIMELIMIT);

}); });});

Page 17: Protractor intro

Chai%Asser*on%Librarymocha Protractor API 1.3.0

describe('Page onload test', function () {var node, present;

it('check if link works', function () {

node = $(‘.ylogo’);node.getAttribute('href').then(function (_linkUrl) {

linkUrl = _linkUrl;return browser.getCurrentUrl();

}).then(function (curUrl) { expect(_curUrl).to.contain(_linkUrl);}).then(function () {

node.click(); .then(function () {

browser.wait(function () { return browser.getCurrentUrl().then(function (_curUrl) {

return _curUrl === linkUrl; }, TIMELIMIT);

}); });});

Page 18: Protractor intro

Chai%Asser*on%Librarymocha Protractor API 1.3.0

describe('Page onload test', function () {var node, present;

it('check if link works', function () {

node = $(‘.ylogo’);protractor.promise.all([browser.getCurrentUrl(), node.getAttribute('href')]).then(function (_res) {

curUrl = _res[0];linkUrl = _res[1];node.click();browser.wait(function () {

return browser.getCurrentUrl().then(function (_curUrl) {

return _curUrl === linkUrl;}, TIMELIMIT);

}); });});

Page 19: Protractor intro

Tips

describe.only('Test task A', function () {

it('sub-task 1', function () {});it('sub-task 2', function () {});

});

describe('Test task B', function () {it('sub-task 1', function () {});

});

describe('Test task C', function () {it.only('sub-task 1', function () {});it('sub-task 2', function () {});

});

describe('Test task D', function () {it('sub-task 1', function () {});it('sub-task 2', function () {});

});

only skip

Page 20: Protractor intro

Tips

only%only%is%only

onlydescribe.only('Test task A', function () {

it.skip('sub-task 1', function () {});it('sub-task 2', function () {});

});

describe('Test task B', function () {it('sub-task 1', function () {});

});

describe.only('Test task C', function () {it.skip('sub-task 1', function () {});it.skip('sub-task 2', function () {});it('sub-task 2', function () {});

});

describe('Test task D', function () {it('sub-task 1', function () {});

});

skip

Page 21: Protractor intro

Tips$ protractor tests/spec/protractor.conf.js --seleniumAddress="..." --baseUrl="..." --specs=tests/spec/test/universal.spec.js --suite=uni

protractor.conf.js

Page 22: Protractor intro

after

Tips

describe.only('Test task A', function () {var hambgNode;beforeEach(function () { hambgNode = $('.header .myStore ');});it('sub-test 1', function () {});it('sub-test 2', function () {});

});

describe('Test task B', function () {beforeEach(function () { hambgNode = $('.header .myStore ');});it('sub-test 1', function () {});

});

before beforeEach afterEach

Page 23: Protractor intro

Source

mochaChai%Asser*on%LibraryProtractor API 1.3.0