From bd5893b720aa44128e35ffa847773ea8652e53e1 Mon Sep 17 00:00:00 2001 From: Dan Caseley Date: Sat, 14 Dec 2024 22:42:59 +0000 Subject: [PATCH] WIP: Web e2e --- .github/workflows/test-e2e.yaml | 37 ++++++++++++++++ e2e/run_tests_web | 75 +++++++++++++++++++++++++++++++++ e2e/web/wikipedia/failing.yaml | 6 +++ e2e/web/wikipedia/tour.yaml | 16 +++++++ 4 files changed, 134 insertions(+) create mode 100755 e2e/run_tests_web create mode 100644 e2e/web/wikipedia/failing.yaml create mode 100644 e2e/web/wikipedia/tour.yaml diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml index bff56c597d..c34d7f9ba4 100644 --- a/.github/workflows/test-e2e.yaml +++ b/.github/workflows/test-e2e.yaml @@ -46,6 +46,43 @@ jobs: path: build/Products retention-days: 1 + test-web: + name: Test on Web + runs-on: ubuntu-latest + needs: build + + steps: + - name: Clone repository (only needed for the e2e directory) + uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 11 + + - name: Set up Chrome + uses: browser-actions/setup-chrome@v1 + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + name: maestro-cli-jdk11-run_id${{ github.run_id }} + + - name: Add Maestro CLI executable to PATH + run: | + unzip maestro.zip -d maestro_extracted + echo "$PWD/maestro_extracted/maestro/bin" >> $GITHUB_PATH + + - name: Check if Maestro CLI executable starts up + run: | + maestro --help + maestro --version + + - name: Run tests + run: | + maestro --platform=web test + test-android: name: Test on Android runs-on: ubuntu-latest diff --git a/e2e/run_tests_web b/e2e/run_tests_web new file mode 100755 index 0000000000..39514b0867 --- /dev/null +++ b/e2e/run_tests_web @@ -0,0 +1,75 @@ +#!/usr/bin/env sh +set -eu + +# Runs all tests in the web directory. + +command -v maestro >/dev/null 2>&1 || { echo "maestro is required" && exit 1; } + +[ "$(basename "$PWD")" = "e2e" ] || { echo "must be run from e2e directory" && exit 1; } + +ALL_PASS=true + +_h1() { + printf "=>\n=> %s\n=>\n" "$1" +} + +_h2() { + printf "==> [%s] %s\n" "$1" "$2" +} + +_h3() { + printf "==> [%s] [%s] => %s\n" "$1" "$2" "$3" +} + +platform="web" +exclude_tags="ai" + +mkfifo pipe +trap 'rm -f pipe' EXIT + +# Run passing tests +for workspace_dir in ./web/*; do + WORKSPACE_PASS=true + app_name="$(basename "$workspace_dir")" + _h1 "run tests for \"$app_name\" on platform \"$platform\"" + + ### + ### Run passing tests + ### + _h2 "$app_name" "run passing tests" + + while IFS= read -r line; do + _h3 "$app_name" "passing" "$line" + done < pipe & + + maestro --verbose --platform "$platform" test --include-tags passing --exclude-tags "$exclude_tags" "$workspace_dir" 1>pipe 2>&1 || WORKSPACE_PASS=false + + if [ "$WORKSPACE_PASS" = "false" ]; then + _h2 "$app_name" "FAIL! Expected all pass, but at least some failed instead" + ALL_PASS=false + fi + + ### + ### Run failing tests + ### + WORKSPACE_PASS=true # Reset for failing flows + _h2 "$app_name" "run failing tests" + + while IFS= read -r line; do + _h3 "$app_name" "failing" "$line" + done < pipe & + + maestro --verbose --platform "$platform" test --include-tags failing --exclude-tags "$exclude_tags" "$workspace_dir" 1>pipe 2>&1 && WORKSPACE_PASS=false + + if [ "$WORKSPACE_PASS" = "false" ]; then + _h2 "$app_name" "FAIL! Expected all to fail, but at least some passed instead" + ALL_PASS=false + fi +done + +if [ "$ALL_PASS" = "false" ]; then + _h1 "FAILURE: some tests failed!" + exit 1 +else + _h1 "SUCCESS: all tests passed!" +fi diff --git a/e2e/web/wikipedia/failing.yaml b/e2e/web/wikipedia/failing.yaml new file mode 100644 index 0000000000..399f0f44a2 --- /dev/null +++ b/e2e/web/wikipedia/failing.yaml @@ -0,0 +1,6 @@ +url: https://en.wikipedia.org +tags: + - failing +--- +- launchApp +- assertVisible: 'ZZ_ Non-existent text' \ No newline at end of file diff --git a/e2e/web/wikipedia/tour.yaml b/e2e/web/wikipedia/tour.yaml new file mode 100644 index 0000000000..90cde694c5 --- /dev/null +++ b/e2e/web/wikipedia/tour.yaml @@ -0,0 +1,16 @@ +url: https://en.wikipedia.org +tags: + - passing +--- +- launchApp +- tapOn: + leftOf: + text: 'Donate' + index: 2 +- inputText: 'Maestro' +- assertVisible: 'Title of respect given to a master musician' +- pressKey: 'Enter' +- assertVisible: 'https://en.wikipedia.org/wiki/Maestro' +- copyTextFrom: + id: 'firstHeading' +- assertTrue: ${maestro.copiedText == 'Maestro'} \ No newline at end of file