Permalink
Browse files

fix(ci): Travis should be able to correctly test PRs

Because of security restrictions on Travis CI, PR builds don't have access to encrypted environment
variables required for the BrowserStack local connection to work.

To work around this limitation, PR builds will now use PhantomJS instead of BrowserStack for all the tests
that don't require a real browser.

The main build will execute tests using a real browser.

Fixes #17
  • Loading branch information...
jan-molak committed Jan 20, 2017
1 parent a78f2d5 commit 9829726e75d842c953055480db990bb5bf8a94c3
Showing with 55 additions and 19 deletions.
  1. +2 −1 .travis.yml
  2. +4 −1 package.json
  3. +23 −8 spec/cookbook/html_form.recipe.ts
  4. +26 −9 spec/protractor-cookbook.conf.js
View
@@ -12,7 +12,8 @@ before_install:
before_script:
- npm prune
script:
- npm run verify
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then npm run verify:pull-request; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then npm run verify; fi'
after_success:
- npm run publish
branches:
View
@@ -14,14 +14,17 @@
"lint": "tslint --project=tsconfig.json --config=tslint.json --format=prose",
"package": "tsc --project tsconfig-export.json",
"verify": "npm run clean && npm run lint && npm test && npm run package && npm run report",
"verify:pull-request": "npm run clean && npm run lint && npm run spec:pull-request && npm run package && npm run report",
"rebuild": "npm run clean && npm run verify",
"commit": "git-cz",
"webdriver-manager": "webdriver-manager",
"webdriver:update": "npm run webdriver-manager update",
"spec:api": "nyc --report-dir=./staging/reports/coverage/api mocha --opts ./spec/mocha.opts 'spec/api/**/*.spec.*'",
"spec:cookbook": "nyc --report-dir=./staging/reports/coverage/cookbook protractor ./spec/protractor-cookbook.conf.js",
"spec:cookbook": "nyc --report-dir=./staging/reports/coverage/cookbook protractor ./spec/protractor-cookbook.conf.js --params.browsers=chrome",
"spec:cookbook:pull-request": "nyc --report-dir=./staging/reports/coverage/cookbook protractor ./spec/protractor-cookbook.conf.js --params.browsers=phantomjs",
"spec:integration": "nyc --report-dir=./staging/reports/coverage/integration mocha --opts ./spec/mocha.opts 'spec/integration/*/*.ts'",
"spec": "npm run spec:api && npm run spec:cookbook && npm run spec:integration",
"spec:pull-request": "npm run spec:api && npm run spec:cookbook:pull-request && npm run spec:integration",
"coverage:merge": "istanbul-merge --out=./staging/reports/coverage/coverage-final.json ./staging/reports/coverage/**/coverage-final.json",
"coverage:report": "nyc report --reporter=html --reporter=lcov --temp-directory=./staging/reports/coverage --report-dir=./staging/reports/coverage",
"report": "npm run coverage:merge && npm run coverage:report",
@@ -80,12 +80,27 @@ describe ('When demonstrating the usage of an HTML form, a test scenario', funct
expect(james.toSee(Text.of(SingleCountry.Result))).eventually.equal('France'),
])));
it ('can interact with multi-choice select box', () =>
james.attemptsTo(
Select.values('Poland', 'France').from(MultiCountry.Selector),
).then(() => Promise.all([
expect(james.toSee(SelectedValues.of(MultiCountry.Selector))).eventually.deep.equal(['Poland', 'France']),
expect(james.toSee(Text.of(MultiCountry.Result))).eventually.equal('Poland, France'),
])));
describe('when a real browser is available', () => {
before(ensureARealBrowserIsAvailable);
it('can interact with multi-choice select box', () =>
james.attemptsTo(
Select.values('Poland', 'France').from(MultiCountry.Selector),
).then(() => Promise.all([
expect(james.toSee(SelectedValues.of(MultiCountry.Selector))).eventually.deep.equal([ 'Poland', 'France' ]),
expect(james.toSee(Text.of(MultiCountry.Result))).eventually.equal('Poland, France'),
])));
});
// see https://github.com/jan-molak/serenity-js/issues/17
function ensureARealBrowserIsAvailable() {
return protractor.browser.driver.getCapabilities().
then(capabilities => capabilities.get('browserName')).
then(name => {
if (name === 'phantomjs') {
this.skip();
}
});
}
});
@@ -1,10 +1,27 @@
'use strict';
require('ts-node/register');
var path = require('path'),
var _ = require('lodash'),
path = require('path'),
protractor = require.resolve('protractor'),
node_modules = protractor.substring(0, protractor.lastIndexOf('node_modules') + 12);
var capabilities = {
chrome: {
browserName: 'chrome',
build: process.env.BROWSERSTACK_AUTOMATE_BUILD,
project: process.env.BROWSERSTACK_AUTOMATE_PROJECT,
'browserstack.localIdentifier': process.env.BROWSERSTACK_LOCAL_IDENTIFIER,
'browserstack.local': true,
},
phantomjs: {
'browserName': 'phantomjs',
'phantomjs.binary.path': path.resolve(node_modules, 'phantomjs-prebuilt/lib/phantom/bin/phantomjs'),
}
}
exports.config = {
seleniumServerJar: path.resolve(node_modules, 'protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-2.53.1.jar'),
@@ -14,14 +31,14 @@ exports.config = {
browserstackUser: process.env.BROWSERSTACK_USERNAME,
browserstackKey: process.env.BROWSERSTACK_KEY,
capabilities: {
browserName: 'chrome',
build: process.env.BROWSERSTACK_AUTOMATE_BUILD,
project: process.env.BROWSERSTACK_AUTOMATE_PROJECT,
restartBrowserBetweenTests: false,
'browserstack.localIdentifier': process.env.BROWSERSTACK_LOCAL_IDENTIFIER,
'browserstack.local': true,
},
getMultiCapabilities: function() {
var browsers = (this.params.browsers || 'chrome').split(',');
restartBrowserBetweenTests: false
return _(capabilities)
.pick(browsers)
.values()
.value();
}
};

0 comments on commit 9829726

Please sign in to comment.