#!/bin/bash # # Installs Chrome or Firefox if missing, starts Browserstack Local or Sauce Connect if needed # and runs Karma and Protractor tests # BINDIR=$PWD/browsers/bin SCRIPTDIR=$(dirname $0) if [ -z $BROWSER ]; then BROWSER="chrome" fi if [ -z $BVER ]; then BVER="stable" fi if [ ! -n "$BROWSERBIN" ]; then if [[ $OSTYPE == darwin* ]]; then echo "We are running on Mac OS let's check if the browsers are already installed" case ${BROWSER}-${BVER} in chrome-stable) BROWSERBIN="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";; chrome-beta) BROWSERBIN="/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome";; chrome-unstable) BROWSERBIN="/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary";; firefox-stable) BROWSERBIN="/Applications/Firefox.app/Contents/MacOS/firefox";; firefox-beta) BROWSERBIN="/Applications/Firefox Beta.app/Contents/MacOS/firefox";; firefox-unstable) BROWSERBIN="/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox";; esac else # We can't install ie on Travis if [ "$BROWSER" != 'ie' ] && [ "$BROWSER" != 'electron' ]; then BROWSERBIN=$BINDIR/$BROWSER-$BVER fi fi fi if [ "$BROWSER" == "safari" ] || ([ -n "$BROWSERBIN" ] && [ ! -x $BROWSERBIN ] && [ ! -n "$SAUCELABS" ] && [ ! -n "$BROWSERSTACK" ] && [ "$BROWSER" != 'edge' ]); then # If the browser isn't already installed then we install it using travis multirunner # Travis multirunner also handles setting up Safari to allow camera access and fake devices echo "Installing browser using travis multirunner." ./node_modules/travis-multirunner/setup.sh fi if [ -n "$SAUCELABS" ]; then $SCRIPTDIR/sauceconnect-start fi if [ -n "$BROWSERSTACK" ]; then $SCRIPTDIR/browserstacklocal-start fi if [ "$BROWSER" == 'chrome' ] || [ "$BROWSER" == 'firefox' ]; then export BROWSERBIN="$BROWSERBIN" # Karma uses ${BROWSER}_BIN, eg. CHROME_BIN, to override the path to the browser BROWSER_UPPER=$(echo "$BROWSER" | tr '[:lower:]' '[:upper:]') export ${BROWSER_UPPER}_BIN="$BROWSERBIN" fi unit=0 if [ -n "$UNIT_CMD" ]; then echo "Starting Unit Test Command: $UNIT_CMD for $BROWSER" eval $UNIT_CMD unit=$? fi integration=0 if [ -n "$INTEGRATION_CMD" ]; then echo "Running Integration Test Command: $INTEGRATION_CMD for $BROWSER" eval $INTEGRATION_CMD integration=$? fi $SCRIPTDIR/sauceconnect-stop $SCRIPTDIR/browserstacklocal-stop exit $(( $unit || $integration ))