Skip to content

WIP: testing protractor for PRs #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,21 @@ env:
- secure: "fq/U7VDMWO8O8SnAQkdbkoSe2X92PVqg4d044HmRYVmcf6YbO48+xeGJ8yOk0pCBwl3ISO4Q2ot0x546kxfiYBuHkZetlngZxZCtQiFT9kyId8ZKcYdXaIW9OVdw3Gh3tQyUwDucfkVhqcs52D6NZjyE2aWZ4/d1V4kWRO/LMgo="
matrix:
# Order: a slower build first, so that we don't occupy an idle travis worker waiting for others to complete.
- MODE=saucelabs_required
- MODE=browserstack_required
- MODE=saucelabs_optional
- MODE=browserstack_optional
- MODE=saucelabs_unit_required
- MODE=browserstack_unit_required
- MODE=saucelabs_unit_optional
- MODE=browserstack_unit_optional
- MODE=saucelabs_e2e_required
- MODE=browserstack_e2e_required
- MODE=saucelabs_e2e_optional
- MODE=browserstack_e2e_optional

matrix:
allow_failures:
- env: "MODE=saucelabs_optional"
- env: "MODE=browserstack_optional"
- env: "MODE=saucelabs_unit_optional"
- env: "MODE=browserstack_unit_optional"
- env: "MODE=saucelabs_e2e_optional"
- env: "MODE=browserstack_e2e_optional"

install:
- npm install
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"karma-firefox-launcher": "^0.1.7",
"karma-jasmine": "^0.3.6",
"karma-sauce-launcher": "^0.2.14",
"protractor": "^3.0.0",
"tslint": "^3.2.2",
"typescript": "^1.7.5"
"typescript": "^1.7.5",
"webdriver-manager": "^8.0.0"
}
}
18 changes: 15 additions & 3 deletions scripts/ci/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,22 @@ teardown_tunnel() {
esac
}

# Run the tests for this run (either unit or e2e).
run_tests() {
case "$MODE" in
*unit*)
npm run build
karma start test/karma.conf.js --single-run --no-auto-watch --reporters='dots'
;;
*e2e*)
./scripts/ci/test-e2e-js.sh
;;
*)
;;
esac
}

start_tunnel
wait_for_tunnel
npm run build
karma start test/karma.conf.js --single-run --no-auto-watch --reporters='dots'
run_tests
teardown_tunnel

30 changes: 30 additions & 0 deletions scripts/ci/test-e2e-js.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -ex

echo =============================================================================
# go to project dir
SCRIPT_DIR=$(dirname $0)
cd ${SCRIPT_DIR}/../..

./node_modules/.bin/webdriver-manager update

function killServer () {
kill $serverPid
}

./node_modules/.bin/ng serve&
serverPid=$!

# If this scipt is killed, ensure that the server is terminated.
trap killServer EXIT

# Wait for server to come up!
sleep 10

# Let protractor use default browser unless one is specified.
OPTIONS="";
if [[ -n "$E2E_BROWSERS" ]]; then
OPTIONS="--browsers=$E2E_BROWSERS";
fi

./node_modules/.bin/protractor test/protractor-js.conf.js ${OPTIONS}
10 changes: 10 additions & 0 deletions src/e2e/button-e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe('protractor sanity test', function() {
var url = 'index.html';

beforeEach(() => { browser.get(url); });

it('should sanity check the demo-app', () => {
var button = element.all(by.css('button')).first();
expect(button.getAttribute('md-button')).toBeDefined();
});
});
19 changes: 19 additions & 0 deletions test/protractor-js.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Configuration for running e2e tests with Protractor.
*/
exports.config = {
framework: 'jasmine2',
useAllAngular2AppRoots: true,

baseUrl: 'http://localhost:4200/',
specs: ['../dist/e2e/button-e2e-spec.js'],

// Specific options for jasmine.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 60000
},

sauceUser: process.env.SAUCE_USERNAME,
sauceKey: process.env.SAUCE_ACCESS_KEY,
};