Skip to content

Commit

Permalink
TASK: Unify shell scripts for local and saucelabs testing
Browse files Browse the repository at this point in the history
  • Loading branch information
markusguenther committed Sep 24, 2024
1 parent 28ababa commit fa3023f
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 112 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ test:

## Executes integration tests on saucelabs.
test-e2e-saucelabs:
bash Tests/IntegrationTests/e2e-saucelabs.sh
bash Tests/IntegrationTests/e2e.sh --saucelabs

## Executes integration tests locally.
test-e2e:
bash Tests/IntegrationTests/e2e.sh chrome:--disable-search-engine-choice-screen
bash Tests/IntegrationTests/e2e.sh --browser chrome:--disable-search-engine-choice-screen

## Executes integration tests locally in a docker-compose setup.
test-e2e-docker: build-e2e-testing
Expand Down
78 changes: 0 additions & 78 deletions Tests/IntegrationTests/e2e-saucelabs.sh

This file was deleted.

166 changes: 134 additions & 32 deletions Tests/IntegrationTests/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,148 @@
#!/usr/bin/env bash

set -ex
# Global variables
BROWSER=""
USE_SAUCELABS=false

if [ -z "$1" ]; then
echo "No testcafe browser supplied, e.g. 'chrome:headless'"
fi
# Function to parse arguments and save values to global variables
parse_arguments() {
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-s|--saucelabs)
USE_SAUCELABS=true
;;
-b|--browser)
BROWSER="$2"
shift
;;
*)
echo "Unknown option: $1"
usage
exit 1
;;
esac
shift
done
}

cd ../../..
# Function to print usage information
usage() {
cat <<EOF
Usage: $0 [options]
rm -rf DummyDistributionPackages || true
mv DistributionPackages DummyDistributionPackages
mkdir DistributionPackages
Options:
-h, --help Show this help message
-s, --saucelabs Enable remote browser from SauceLabs
-b, --browser Specify local browser to use
EOF
}

ln -s "../Packages/Application/Neos.Neos.Ui/Tests/IntegrationTests/SharedNodeTypesPackage" DistributionPackages/Neos.TestNodeTypes

for fixture in Packages/Application/Neos.Neos.Ui/Tests/IntegrationTests/Fixtures/*/; do
echo "$fixture"
function check_testcafe_browser {
if [ -z "$BROWSER" ] && [ "$USE_SAUCELABS" = false ]; then
echo "No testcafe browser supplied, e.g. 'chrome:headless'"
exit 1
fi
}

ln -s "../${fixture}SitePackage" DistributionPackages/Neos.TestSite
function check_saucelabs_setup {
if [ "$USE_SAUCELABS" = true ]; then
check_saucectl_variables
check_saucectl_installed
fi
}

# TODO: optimize this
composer reinstall neos/test-nodetypes
composer reinstall neos/test-site
# make sure neos is installed even if patching led to the removal (bug)
composer update neos/neos-development-collection
./flow flow:cache:flush --force
./flow flow:cache:warmup
./flow configuration:show --path Neos.ContentRepository.contentDimensions
# Check if SAUCE_USERNAME and SAUCE_ACCESS_KEY are set
function check_saucectl_variables {
if [[ -n "$SAUCE_USERNAME" && -n "$SAUCE_ACCESS_KEY" ]]; then
echo "SAUCE_USERNAME and SAUCE_ACCESS_KEY are set. Configuring saucectl..."
#saucectl configure
else
echo "SAUCE_USERNAME or SAUCE_ACCESS_KEY is not set. Skipping saucectl configuration."
exit 1
fi
}

if ./flow site:list | grep -q 'Node name'; then
./flow site:prune '*'
# Check if saucectl is installed
function check_saucectl_installed {
if ! command -v saucectl &> /dev/null; then
echo "saucectl is not installed. Installing saucectl..."
# Install saucectl via npm (assuming npm is installed)
npm install -g saucectl
fi
./flow site:import --package-key=Neos.TestSite
./flow resource:publish
}

# get dimension from fixture
function get_dimension() {
dimension=$(basename "$1")
echo "$dimension"
}

# Function that gets a fixture as parameter. With the fixture we
# load the related site package and import the site.
function initialize_neos_site() {
local fixture=$1

ln -s "../${fixture}SitePackage" DistributionPackages/Neos.TestSite

# TODO: optimize this
composer reinstall neos/test-nodetypes
composer reinstall neos/test-site
# make sure neos is installed even if patching led to the removal (bug)
composer update neos/neos-development-collection
./flow flow:cache:flush --force
./flow flow:cache:warmup
./flow configuration:show --path Neos.ContentRepository.contentDimensions

if ./flow site:list | grep -q 'Node name'; then
./flow site:prune '*'
fi
./flow site:import --package-key=Neos.TestSite
./flow resource:publish
}

cd Packages/Application/Neos.Neos.Ui
yarn run testcafe "$1" "../../../${fixture}*.e2e.js" \
--selector-timeout=10000 --assertion-timeout=30000
function run_tests() {
cd ../../..
rm -f DistributionPackages/Neos.TestSite

done
rm -rf DummyDistributionPackages || true
mv DistributionPackages DummyDistributionPackages
mkdir DistributionPackages

ln -s "../Packages/Application/Neos.Neos.Ui/Tests/IntegrationTests/SharedNodeTypesPackage" DistributionPackages/Neos.TestNodeTypes

for fixture in Packages/Application/Neos.Neos.Ui/Tests/IntegrationTests/Fixtures/*/; do
dimension=$(get_dimension "$fixture")
initialize_neos_site "$fixture"

# go tp the Neos.Neos.Ui package and run the tests
cd Packages/Application/Neos.Neos.Ui

if [[ $BROWSER ]]; then
yarn run testcafe "$BROWSER" "../../../${fixture}*.e2e.js" --selector-timeout=10000 --assertion-timeout=30000
fi

if [[ $USE_SAUCELABS ]]; then
saucectl run --config .sauce/config${dimension}.yml
fi

# cd back to the root directory and clean up
cd ../../..
rm -f DistributionPackages/Neos.TestSite
done

rm -rf DistributionPackages
mv DummyDistributionPackages DistributionPackages
}

# Parse arguments
parse_arguments "$@"

# check if incoming parameters are correct
check_testcafe_browser
check_saucelabs_setup

rm -rf DistributionPackages
mv DummyDistributionPackages DistributionPackages
# Run the tests
run_tests

0 comments on commit fa3023f

Please sign in to comment.