Skip to content

Commit

Permalink
Add running voiceover on chrome and firefox (#26)
Browse files Browse the repository at this point in the history
* install requested browser for voiceover

* add steps to start webdriver

* Update run-tester.sh

* update url

* add check server loop

* Update run-tester.sh

* Update voiceover-test.yml

* try arm64 fix

* Create install-geckodriver.sh

* handle x86_64

* make executable

* use different path strategy

* clean up run tester script

* no need to path or ln

* snake case variables

* remove token

* remove curl verbose flag
  • Loading branch information
outofambit authored Jul 22, 2024
1 parent 4b3983f commit e476836
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 9 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/voiceover-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ on:
- "13"
- "14"
default: "14"
browser:
description: |
The browser to use for testing, "chrome" or "firefox" or "safari", default "safari"
required: false
type: string

env:
ARIA_AT_WORK_DIR: ${{ inputs.work_dir || 'tests/alert' }}
ARIA_AT_CALLBACK_URL: ${{ inputs.callback_url }}
ARIA_AT_STATUS_URL: ${{ inputs.status_url }}
ARIA_AT_CALLBACK_HEADER: ${{ inputs.callback_header || 'x-header-param:empty' }}
BROWSER: ${{ inputs.browser || 'safari' }}

jobs:
voiceover-test:
Expand All @@ -72,6 +78,20 @@ jobs:
cache: "npm"
cache-dependency-path: "**/package-lock.json"

- uses: browser-actions/setup-chrome@v1
if: inputs.browser == 'chrome'
with:
chrome-version: stable

- uses: browser-actions/setup-firefox@v1
if: inputs.browser == 'firefox'

- name: Install geckodriver
if: inputs.browser == 'firefox'
env:
token: ${{ secrets.GITHUB_TOKEN }}
run: ./install-geckodriver.sh

- name: Setup Environment
uses: guidepup/[email protected]

Expand Down
59 changes: 59 additions & 0 deletions install-geckodriver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -euo pipefail

os="$(uname)"
arch="$(uname -m)"
api_token="$token"
api_url="https://api.github.com/repos/mozilla/geckodriver/releases/latest"

if [[ "$os" == "Darwin" ]]; then

# Add Authorization header if a token is provided
if [ -n "$api_token" ]; then
auth_header="Authorization: token $api_token"
else
auth_header=""
fi
# Make the API request and extract the tag_name
latest_version=$(curl -s -H "$auth_header" "$api_url" | awk -F'"' '/tag_name/{print $4}')

if [ -z "$latest_version" ]; then
echo "Failed to get latest version"
exit 1
fi

echo "Found latest version of geckodriver ${latest_version}"

mkdir -p geckodriver
(
cd geckodriver

case "$arch" in
"arm64")
echo "Downloading geckodriver"
wget https://github.com/mozilla/geckodriver/releases/download/${latest_version}/geckodriver-${latest_version}-macos-aarch64.tar.gz

tar xzf geckodriver-${latest_version}-macos-aarch64.tar.gz
;;
"x86_64")
echo "Downloading geckodriver"
wget https://github.com/mozilla/geckodriver/releases/download/${latest_version}/geckodriver-${latest_version}-macos.tar.gz
tar xzf geckodriver-${latest_version}-macos.tar.gz
;;
*)
echo "Unsupported architecture - $arch"
exit 1
;;
esac

chmod +x geckodriver
echo "geckodriver available at ${PWD}"
)
echo "Running geckodriver --version"
geckodriver/geckodriver --version
exit 0
else
echo "Unsupported OS - ${os}"
exit 1
fi
75 changes: 66 additions & 9 deletions run-tester.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,83 @@

set -euo pipefail

# This URL is used for firefox and chrome, and is only a placeholder for safari.
# When run in macOS, the test harness does not use WebDriver because
# SafariDriver's "glass pane" feature interferes with testing. Provide a valid
# URL simply as a placeholder.
url_placeholder=http://example.com
# SafariDriver's "glass pane" feature interferes with testing.
webdriver_url=http://127.0.0.1:4444

aria-at-automation-driver/package/bin/at-driver serve --port 3031 > at-driver.log 2>&1 &

atdriver_pid=$!
# Initialize so we can set up trap right away
webdriver_pid=0
atdriver_pid=0

function clean_up {
kill -9 ${atdriver_pid} || true
if [[ ${webdriver_pid} -ne 0 ]]; then
kill -9 ${webdriver_pid} || true
fi
if [[ ${atdriver_pid} -ne 0 ]]; then
kill -9 ${atdriver_pid} || true
fi
}
trap clean_up EXIT

aria-at-automation-driver/package/bin/at-driver serve --port 3031 > at-driver.log 2>&1 &
atdriver_pid=$!

poll_url() {
local url="$1"
local attempt=0
echo "Polling ${url}"

while [ ${attempt} -lt 30 ]; do
((attempt++))

response=$(curl -s -o /dev/null -w "%{http_code}" -m 2 "$url" || true)

if [ ${response:--1} -ge 99 ]; then
echo "Success: ${response} after ${attempt} tries"
return 0
else
echo "Attempt ${attempt}: URL ${url} returned HTTP ${response}. Retrying in 1 second..."
sleep 1
fi
done

echo "Error: Max attempts reached. ${url} is not responding."
exit 1
}

case ${BROWSER} in
chrome)
echo "Starting chromedriver"
chromedriver --port=4444 --log-level=INFO > webdriver.log 2>&1 &
webdriver_pid=$!
echo "Started chromedriver"
poll_url $webdriver_url
;;

firefox)
echo "Starting geckodriver"
geckodriver/geckodriver > webdriver.log 2>&1 &
webdriver_pid=$!
echo "Started geckodriver"
poll_url $webdriver_url
;;

safari)
;;

*)
echo "Unknown browser (${BROWSER})"
exit 1
;;
esac

node aria-at-automation-harness/bin/host.js run-plan \
--plan-workingdir aria-at/build/${ARIA_AT_WORK_DIR} \
--debug \
--agent-web-driver-url=${url_placeholder} \
--agent-web-driver-url=${webdriver_url} \
--agent-at-driver-url=ws://127.0.0.1:3031/session \
--reference-hostname=127.0.0.1 \
--agent-web-driver-browser=safari \
--agent-web-driver-browser=${BROWSER} \
'{reference/**,test-*-voiceover_macos.*}' 2>&1 | \
tee harness-run.log

0 comments on commit e476836

Please sign in to comment.