#!/usr/bin/env sh set -o nounset cd `dirname $0` DIR=`pwd` CASPER=$(which casperjs) INCLUDE="" EXCLUDE="" VERBOSE=0 VAGRANT=0 BUILD=0 CASPERJS_HOST="localhost" CASPERJS_PORT=80 CASPERJS_USER="jdoe" CASPERJS_PASS="password" CASPERJS_PATH="icinga2-web" if [ ! -x $CASPER ]; then echo "CasperJS is not installed but required to run frontend tests\n"\ "Take a look at http://casperjs.org/installation.html to see how the installation works for your system" exit 1 fi; PARAM="0" for arg in $@;do if [ ! "$PARAM" = "0" ]; then export $PARAM=$arg PARAM="0" continue fi; case $arg in -v|--verbose) VERBOSE=1 ;; -V|--vagrant) VAGRANT=1 ;; -i|--include) PARAM="INCLUDE" continue ;; -e|--exclude) PARAM="EXCLUDE" continue ;; -b|--build) BUILD=1 continue ;; -h|--host) PARAM="CASPERJS_HOST" continue ;; -p|--port) PARAM="CASPERJS_PORT" continue ;; --path) PARAM="CASPERJS_PATH" continue ;; -U|--user) PARAM="CASPERJS_USER" continue ;; -P|--pass) PARAM="CASPERJS_PASS" continue ;; **) if [ "$arg" != "--help" ]; then echo "Unknown option $arg" fi; printf "%b" "Testrunner for interface tests\n\n" printf "%b" "Usage: $0 [--verbose] [--include %include%] [--exclude %exclude%] [--build]\n\n" printf "%b" " --verbose \t\t\t Print verbose output when testing\n" printf "%b" " --include %filelist%\t\t Include only files matching this patterns\n" printf "%b" " --exclude %filelist%\t\t Exclude files matching this patterns\n" printf "%b" " --build \t\t\t Write test results to ../../build/log/casper_results.xml\n" printf "%b" " --host \t\t\t Host to run frontend tests on, default is localhost\n" printf "%b" " --port \t\t\t Port to use for the host, default is 80 \n" printf "%b" " --path \t\t\t Base path where icinga can be found (default is icingaweb)\n" printf "%b" " --user \t\t\t User to use for authentication (default jdoe)\n" printf "%b" " --pass \t\t\t Password to use for authentication (default password)\n" printf "%b" " --help \t\t\t Print this message\n\n" exit 1 esac; done; # # If vagrant is set the tests are ran in the vagrant VM # if [ $VAGRANT -eq 1 ] && [ $USER != "vagrant" ]; then # Check if vagrant is installed if [ ! -n `which vagrant` ]; then echo "Vagrant is not installed on your system!" exit 1 fi # Call the script in the Vagrant VM with the same parameters vagrant ssh -c "/vagrant/test/frontend/runtests $@" exit $? fi if [ "$CASPER" = "" -o ! -x $CASPER ]; then echo "CasperJS is not installed but required to run frontend tests\n"\ "Take a look at http://casperjs.org/installation.html to see how the installation works for your system" exit 1 fi; EXEC="$CASPER test --ignore-ssl-errors=true " # # If build is set, the results are written for our jenkins server # if [ $BUILD -eq 1 ];then mkdir -p $DIR/../../build/log EXEC="$EXEC --xunit=$DIR/../../build/log/casper_results.xml" fi; if [ "$PARAM" != "0" ]; then echo "Missing parameter for $PARAM" exit 1 fi; FILELIST="" # # Default : Run regression and cases directory # if [ "$INCLUDE" = "" -a "$EXCLUDE" = "" ];then FILELIST="./cases ./regression" fi; # # Include patterns set with the --include directive # if [ "$INCLUDE" != "" ];then NAME="\(" GLUE="" for INC in $INCLUDE;do NAME="$NAME${GLUE}${INC}.*js" GLUE="\|" done; NAME=$NAME"\)$" FILELIST=`find . | grep "$NAME"` fi; # # Exclude patterns that match the include directive # if [ "$EXCLUDE" != "" ];then NAME="\(" GLUE="" for EXC in $EXCLUDE;do NAME="$NAME${GLUE}${EXC}.*js" GLUE="\|" done; NAME=$NAME"\)$" if [ "$FILELIST" = "" ]; then FILELIST=`find .|grep ".*js$"` fi FILELIST=`echo $FILELIST | grep -v "$NAME"` fi; export CASPERJS_HOST=$CASPERJS_HOST export CASPERJS_PORT=$CASPERJS_PORT export CASPERJS_USER=$CASPERJS_USER export CASPERJS_PASS=$CASPERJS_PASS export CASPERJS_PATH=$CASPERJS_PATH echo Executing $EXEC $FILELIST for JSFILE in $FILELIST;do $EXEC $JSFILE; done; exit 0