Ideal 
Test,Scripts 
Selenium,Server 
protractor.conf.js Actual 
Browser,Drivers
Setup 
$ npm install protractor
Setup 
$ npm install protractor 
$ npm install yo 
$ sudo ynpm i -g generator-ypr 
-otractor 
$ cd your-repo-dir 
$ yo yprotractor:existing 
$ ynpm update
Setup 
$ npm install protractor 
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
Setup 
$ npm install protractor 
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
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
$ npm install protractor 
Run 
$ git clone xxx.git && cd xxx 
$ ynpm i 
$ protractor tests/spec/ 
protractor.conf.js -- 
seleniumAddress="..." -- 
baseUrl="..." 
protractor.conf.js
$ 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
Test,Scripts 
mocha Protractor API 1.3.0 Chai%Asser*on%Library
mocha 
Protractor API 1.3.0 Chai%Asser*on%Library 
describe('Page onload test', function () { 
it('should match store title', function () { 
}); 
});
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()
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('');
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); 
}); 
});
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); 
}); 
}); 
});
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); 
}); 
}); 
});
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); 
}); 
}); 
});
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); 
}); 
}); 
});
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 () {}); 
});
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 () {}); 
});
Tips 
$ protractor tests/spec/protractor.conf.js --seleniumAddress=... 
--baseUrl=... --specs=tests/spec/test/universal.spec.js 
--suite=uni 
protractor.conf.js
before beforeEach after 
afterEach 
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 () {}); 
});
Source 
mocha 
Protractor API 1.3.0 Chai%Asser*on%Library

Introduction to Protractor

  • 2.
    Ideal Test,Scripts Selenium,Server protractor.conf.js Actual Browser,Drivers
  • 3.
    Setup $ npminstall protractor
  • 4.
    Setup $ npminstall protractor $ npm install yo $ sudo ynpm i -g generator-ypr -otractor $ cd your-repo-dir $ yo yprotractor:existing $ ynpm update
  • 5.
    Setup $ npminstall protractor 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
  • 6.
    Setup $ npminstall protractor 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
  • 7.
    Setup $ npminstall 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 installprotractor Run $ git clone xxx.git && cd xxx $ ynpm i $ protractor tests/spec/ protractor.conf.js -- seleniumAddress="..." -- baseUrl="..." protractor.conf.js
  • 9.
    $ npm installprotractor 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
  • 10.
    Test,Scripts mocha ProtractorAPI 1.3.0 Chai%Asser*on%Library
  • 11.
    mocha Protractor API1.3.0 Chai%Asser*on%Library describe('Page onload test', function () { it('should match store title', function () { }); });
  • 12.
    mocha Chai%Asser*on%Library ProtractorAPI 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 API1.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 ProtractorAPI 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 ProtractorAPI 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 ProtractorAPI 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 ProtractorAPI 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 ProtractorAPI 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('Testtask 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 () {}); });
  • 21.
    Tips $ protractortests/spec/protractor.conf.js --seleniumAddress=... --baseUrl=... --specs=tests/spec/test/universal.spec.js --suite=uni protractor.conf.js
  • 22.
    before beforeEach after afterEach 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 () {}); });
  • 23.
    Source mocha ProtractorAPI 1.3.0 Chai%Asser*on%Library