Protractor E2E Boostrapping (Local and via Browserstack)
JS
R
JavaScriptRecipe for boostraping Protractor E2E locally and remotely via BrowserStack. Protractor 5.3 http://www.protractortest.org/#/ https://github.com/angular/protractor Magic: Protractor will read the tests specs and will send requests to a Selenium Web Driver server which will control a local browser (Chrome).
1// ============================================
2// run-tests.sh
3echo "CodeRecipes E2E Tests Framework Starting..."
4if [ "$NODE_ENV" = "production" ] || [ "$NODE_ENV" = "development" ] ; then
5 echo $NODE_ENV
6 ./node_modules/.bin/protractor protractor.conf.js
7fi
8# troubleshooting
9webdriver-manager update --standalone false --gecko false
10
11// ============================================
12# protractor.conf.js
13if (process.env.NODE_ENV === 'production') {
14 exports.config = {
15 specs: ['e2e/login-spec.js'],
16 seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub',
17 capabilities: {
18 'browserstack.user': 'xxxxx',
19 'browserstack.key': 'yyyyy',
20 'browserstack.debug': true,
21 browserName: 'chrome'
22 }
23 // 'multiCapabilities': [{
24 // 'browserName': 'Chrome'
25 // },{
26 // 'browserName': 'Safari'
27 // },{
28 // 'browserName': 'Firefox'
29 // },{
30 // 'browserName': 'IE'
31 // }]
32 };
33} else {
34 exports.config = {
35 specs: ['e2e/login-spec.js'],
36 directConnect: true
37 };
38}
39
40// ============================================
41# /e2e/login-spec.js
42describe('Login screen', function() {
43 it('should login on the platform', function() {
44 browser.get('https://mysite.com');
45
46 element(by.model('formData.email')).sendKeys('user@name.pt');
47 element(by.model('formData.password')).sendKeys('password');
48 element(by.buttonText('Log in')).click();
49
50 var EC = protractor.ExpectedConditions;
51 browser.wait(EC.urlContains('logged'), 5000);
52 });
53});
54
55// ============================================
56# package.json
57 "scripts": {
58 "start": "gulp",
59 "test": "./run-tests.sh"
60 }
61
62Created on 2/26/2018