7. Setup
$ npm install webdriver-manager
$ webdriver-manager update
--standalone
$ webdriver-manager start
$ 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
8. $ npm install protractor
Run
$ git clone xxx.git && cd xxx
$ ynpm i
$ protractor tests/spec/
protractor.conf.js --
seleniumAddress="..." --
baseUrl="..."
protractor.conf.js
9. $ npm install protractor
Run
$ git clone xxx.git && cd xxx
$ ynpm i
$ protractor tests/spec/
protractor.conf.js --
seleniumAddress="..." --
baseUrl="..."
Using the selenium server at
http://10.82.57.93:4444/wd/
hub
1..2
ok 1 Page onload test should
match store title
not ok 2 Universal header
shoppingcart checking after
click items
... ...
# tests 2
# pass 1
# fail 1
11. mocha
Protractor API 1.3.0 Chai%Asser*on%Library
describe('Page onload test', function () {
it('should match store title', function () {
});
});
12. mocha
Chai%Asser*on%Library Protractor API 1.3.0
/* global browser, $, it, describe, before */
describe('Page onload test', function () {
it('should match store title', function () {
});
});
browser.get('/');
browser.getTitle()
13. mocha Protractor API 1.3.0 Chai%Asser*on%Library
/* global browser, $, it, describe, before */
var chai = require(‘chai’),
expect = chai.expect,
chaiAsPromised = require(‘chai-as-promised’);
chai.use(chaiAsPromised);
describe('Page onload test', function () {
it('should match store title', function () {
});
});
browser.get('/');
expect( browser.getTitle()
).to.eventually.equal('');
14. mocha Chai%Asser*on%Library 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);
});
});
15. mocha Chai%Asser*on%Library 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);
});
});
});
16. mocha Chai%Asser*on%Library 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);
});
});
});
17. mocha Chai%Asser*on%Library 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);
});
});
});
18. mocha Chai%Asser*on%Library 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);
});
});
});
19. Tips
only skip
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 () {});
});
20. Tips
only
describe.only('Test task A', function ()
{
it.skip('sub-task 1', function ()
{});
it('sub-task 2', function () {});
skip
only%only%is%only
});
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 () {});
});