set -e
+start_ceph() {
+ cd $FULL_PATH_BUILD_DIR
+
+ MGR=2 RGW=1 ../src/vstart.sh -n -d
+ sleep 10
+
+ # Create an Object Gateway User
+ ./bin/radosgw-admin user create --uid=dev --display-name=Developer --system
+ # Set the user-id
+ ./bin/ceph dashboard set-rgw-api-user-id dev
+ # Obtain and set access and secret key for the previously created user. $() is safer than backticks `..`
+ ./bin/ceph dashboard set-rgw-api-access-key $(./bin/radosgw-admin user info --uid=dev | jq -r .keys[0].access_key)
+ ./bin/ceph dashboard set-rgw-api-secret-key $(./bin/radosgw-admin user info --uid=dev | jq -r .keys[0].secret_key)
+ # Set SSL verify to False
+ ./bin/ceph dashboard set-rgw-api-ssl-verify False
+
+ CYPRESS_BASE_URL=$(./bin/ceph mgr services | jq -r .dashboard)
+}
+
stop() {
if [ "$REMOTE" == "false" ]; then
- cd $BUILD_DIR
+ cd ${FULL_PATH_BUILD_DIR}
../src/stop.sh
fi
exit $1
}
-BASE_URL=''
-DEVICE=''
-REMOTE='false'
+check_device_available() {
+ failed=false
+
+ if [ "$DEVICE" == "docker" ]; then
+ [ -x "$(command -v docker)" ] || failed=true
+ else
+ cd $DASH_DIR/frontend
+ npx cypress verify
+
+ case "$DEVICE" in
+ chrome)
+ [ -x "$(command -v chrome)" ] || [ -x "$(command -v google-chrome)" ] ||
+ [ -x "$(command -v google-chrome-stable)" ] || failed=true
+ ;;
+ chromium)
+ [ -x "$(command -v chromium)" ] || [ -x "$(command -v chromium-browser)" ] || failed=true
+ ;;
+ esac
+ fi
-while getopts 'd:r:' flag; do
+ if [ "$failed" = "true" ]; then
+ echo "ERROR: $DEVICE not found. You need to install $DEVICE or \
+ use a different device. Supported devices: chrome (default), chromium, electron or docker."
+ stop 1
+ fi
+}
+
+: ${CYPRESS_BASE_URL:=''}
+: ${CYPRESS_LOGIN_PWD:=''}
+: ${CYPRESS_LOGIN_USER:=''}
+: ${DEVICE:="chrome"}
+: ${NO_COLOR:=1}
+: ${CYPRESS_ARGS:=''}
+: ${REMOTE:='false'}
+
+while getopts 'd:p:r:u:' flag; do
case "${flag}" in
d) DEVICE=$OPTARG;;
+ p) CYPRESS_LOGIN_PWD=$OPTARG;;
r) REMOTE='true'
- # jq is expecting a string literal, otherwise it will fail on the url ':'.
- # We need to ensure that jq gets a json string for assignment; we achieve
- # that by introducing literal double quotes (i.e., '"').
- BASE_URL='"'$OPTARG'"';;
+ CYPRESS_BASE_URL=$OPTARG;;
+ u) CYPRESS_LOGIN_USER=$OPTARG;;
esac
done
-if [ "$DEVICE" == "" ]; then
- if [ -x "$(command -v google-chrome)" ] || [ -x "$(command -v google-chrome-stable)" ]; then
- DEVICE="chrome"
- elif [ -x "$(command -v docker)" ]; then
- DEVICE="docker"
- else
- echo "ERROR: Chrome and Docker not found. You need to install one of \
-them to run the e2e frontend tests."
- stop 1
- fi
-fi
-
DASH_DIR=`pwd`
+[ -z "$BUILD_DIR" ] && BUILD_DIR=build
+cd ../../../../${BUILD_DIR}
+FULL_PATH_BUILD_DIR=`pwd`
-cd ../../../../build
-BUILD_DIR=`pwd`
+[[ "$(command -v npm)" == '' ]] && . ${FULL_PATH_BUILD_DIR}/src/pybind/mgr/dashboard/node-env/bin/activate
-if [ "$BASE_URL" == "" ]; then
- MGR=2 RGW=1 ../src/vstart.sh -n -d
- sleep 10
+: ${CYPRESS_CACHE_FOLDER:="${FULL_PATH_BUILD_DIR}/src/pybind/mgr/dashboard/cypress"}
- # Create an Object Gateway User
- ./bin/radosgw-admin user create --uid=dev --display-name=Developer --system
- # Set the user-id
- ./bin/ceph dashboard set-rgw-api-user-id dev
- # Obtain and set access and secret key for the previously created user
- ./bin/ceph dashboard set-rgw-api-access-key `./bin/radosgw-admin user info --uid=dev | jq .keys[0].access_key | sed -e 's/^"//' -e 's/"$//'`
- ./bin/ceph dashboard set-rgw-api-secret-key `./bin/radosgw-admin user info --uid=dev | jq .keys[0].secret_key | sed -e 's/^"//' -e 's/"$//'`
- # Set SSL verify to False
- ./bin/ceph dashboard set-rgw-api-ssl-verify False
+export CYPRESS_BASE_URL CYPRESS_CACHE_FOLDER CYPRESS_LOGIN_USER CYPRESS_LOGIN_PWD NO_COLOR
- BASE_URL=`./bin/ceph mgr services | jq .dashboard`
+check_device_available
+
+if [ "$CYPRESS_BASE_URL" == "" ]; then
+ start_ceph
fi
cd $DASH_DIR/frontend
-jq .[].target=$BASE_URL proxy.conf.json.sample > proxy.conf.json
-
-. $BUILD_DIR/src/pybind/mgr/dashboard/node-env/bin/activate
-npm ci
-
-if [ $DEVICE == "chrome" ]; then
- npm run e2e || stop 1
- stop 0
-elif [ $DEVICE == "docker" ]; then
- failed=0
- docker run -d -v $(pwd):/workdir --net=host --name angular-e2e-container rogargon/angular-e2e || failed=1
- docker exec angular-e2e-container npm run e2e || failed=1
- docker stop angular-e2e-container
- docker rm angular-e2e-container
- stop $failed
-else
- echo "ERROR: Device not recognized. Valid devices are 'chrome' and 'docker'."
- stop 1
-fi
+
+case "$DEVICE" in
+ docker)
+ failed=0
+ docker run \
+ -v $(pwd):/e2e \
+ -w /e2e \
+ --env CYPRESS_BASE_URL \
+ --env CYPRESS_LOGIN_USER \
+ --env CYPRESS_LOGIN_PWD \
+ --name=e2e \
+ --network=host \
+ cypress/included:4.4.0 || failed=1
+ stop $failed
+ ;;
+ *)
+ npx cypress run $CYPRESS_ARGS --browser $DEVICE --headless || stop 1
+ ;;
+esac
+
+stop 0