|
17 | 17 | # creates a local webserver to serve test files, and run protractor.
|
18 | 18 | #
|
19 | 19 | # Usage:
|
20 |
| -# $ buildtools/run_protractor.sh |
| 20 | +# |
| 21 | +# ./buildtools/run_tests.sh [--saucelabs [--tunnelIdentifier=<tunnelId>]] |
| 22 | +# |
| 23 | +# Can take up to two arguments: |
| 24 | +# --saucelabs: Use SauceLabs instead of phantomJS. |
| 25 | +# --tunnelIdentifier=<tunnelId>: when using SauceLabs, specify the tunnel |
| 26 | +# identifier. Otherwise, uses the environment variable TRAVIS_JOB_NUMBER. |
| 27 | +# |
| 28 | +# Prefer to use the `npm test` command as explained below. |
| 29 | +# |
| 30 | +# Run locally with PhantomJS: |
| 31 | +# $ npm test |
| 32 | +# It will start a local Selenium Webdriver server as well as the HTTP server |
| 33 | +# that serves test files. |
| 34 | +# |
| 35 | +# Run locally using SauceLabs: |
| 36 | +# Go to your SauceLab account, under "My Account", and copy paste the |
| 37 | +# access key. Now export the following variables: |
| 38 | +# $ export SAUCE_USERNAME=<your username> |
| 39 | +# $ export SAUCE_ACCESS_KEY=<the copy pasted access key> |
| 40 | +# Then, start SauceConnect: |
| 41 | +# $ ./buildtools/sauce_connect.sh |
| 42 | +# Take note of the "Tunnel Identifier" value logged in the terminal. |
| 43 | +# Run the tests: |
| 44 | +# $ npm run -- --saucelabs --tunnelIdentifier=<the tunnel identifier> |
| 45 | +# This will start the HTTP Server locally, and connect through SauceConnect |
| 46 | +# to SauceLabs remote browsers instances. |
| 47 | +# |
| 48 | +# Travis will run `npm test -- --saucelabs`. |
21 | 49 |
|
22 | 50 | cd "$(dirname $(dirname "$0"))"
|
23 | 51 |
|
24 |
| -./node_modules/.bin/webdriver-manager update |
25 |
| - |
26 | 52 | function killServer () {
|
27 |
| - # Selenium Webdriver starts one child process from this one. |
28 |
| - # This command kills them all. |
29 |
| - kill -- -$seleniumPid |
| 53 | + if [ "$seleniumStarted" = true ]; then |
| 54 | + echo "Stopping Selenium..." |
| 55 | + ./node_modules/.bin/webdriver-manager shutdown |
| 56 | + ./node_modules/.bin/webdriver-manager clean |
| 57 | + fi |
| 58 | + echo "Killing HTTP Server..." |
30 | 59 | kill $serverPid
|
31 | 60 | }
|
32 | 61 |
|
33 |
| -# Start Selenium Webdriver. |
34 |
| -./node_modules/.bin/webdriver-manager start &>/dev/null & |
35 |
| -seleniumPid=$! |
36 |
| - |
37 | 62 | # Start the local webserver.
|
38 | 63 | ./node_modules/.bin/gulp serve &
|
39 | 64 | serverPid=$!
|
| 65 | +echo "Local HTTP Server started with PID $serverPid." |
40 | 66 |
|
41 | 67 | trap killServer EXIT
|
42 | 68 |
|
43 |
| -# Wait for servers to come up. |
44 |
| -sleep 10 |
45 |
| - |
46 |
| -./node_modules/.bin/protractor protractor.conf.js |
| 69 | +# If --saucelabs option is passed, forward it to the protractor command adding |
| 70 | +# the second argument that is required for local SauceLabs test run. |
| 71 | +if [[ $1 = "--saucelabs" ]]; then |
| 72 | + seleniumStarted=false |
| 73 | + sleep 2 |
| 74 | + echo "Using SauceLabs." |
| 75 | + # $2 contains the tunnelIdentifier argument if specified, otherwise is empty. |
| 76 | + ./node_modules/.bin/protractor protractor.conf.js --saucelabs $2 |
| 77 | +else |
| 78 | + echo "Using PhantomJS." |
| 79 | + # Updates Selenium Webdriver. |
| 80 | + ./node_modules/.bin/webdriver-manager update |
| 81 | + # Start Selenium Webdriver. |
| 82 | + ./node_modules/.bin/webdriver-manager start &>/dev/null & |
| 83 | + seleniumStarted=true |
| 84 | + echo "Selenium Server started." |
| 85 | + # Wait for servers to come up. |
| 86 | + sleep 10 |
| 87 | + ./node_modules/.bin/protractor protractor.conf.js |
| 88 | +fi |
0 commit comments