Skip to content

Commit

Permalink
Merge pull request #1357 from stephen-ritter/feature/run-local-playwr…
Browse files Browse the repository at this point in the history
…ight-tests

Ability to Run Playwright Tests Locally
  • Loading branch information
ryanmelt authored Aug 15, 2024
2 parents b20ac6f + edf0a6d commit 2320f76
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 18 deletions.
17 changes: 4 additions & 13 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
shell: 'script -q -e -c "bash {0}"'
run: ./openc3.sh build
- name: Install playwright dependencies
run: yarn; yarn playwright install --with-deps; yarn playwright --version
run: ./playwright.sh install-playwright
working-directory: playwright
- name: Check for test.only
run: yarn playwright test --list --forbid-only
Expand All @@ -53,24 +53,15 @@ jobs:
# Build a test plugin for playwright and a copy so we can 'upgrade'
- name: Build plugin
shell: 'script -q -e -c "bash {0}"'
run: |
./openc3.sh cliroot generate plugin PW_TEST
cd openc3-cosmos-pw-test
../openc3.sh cliroot generate target PW_TEST
../openc3.sh cliroot rake build VERSION=1.0.0
sudo cp openc3-cosmos-pw-test-1.0.0.gem openc3-cosmos-pw-test-1.0.1.gem
../openc3.sh cliroot validate openc3-cosmos-pw-test-1.0.0.gem
run: ./playwright.sh build-plugin
working-directory: playwright
# Ensure we're connected and running
- name: Wait for build
run: yarn playwright test --project=chromium tests/wait-for-build.spec.ts
working-directory: playwright
- name: Run Playwright tests
# Run separately to allow for parallelism
run: |
yarn playwright test --project=chromium --grep-invert enterprise
# Don't run against firefox in parallel because tests persist things
# in the backend and there are race conditions
# yarn playwright test --project=firefox
run: ./playwright.sh run-chromium --grep-invert enterprise
working-directory: playwright
- name: Generate coverage
run: yarn fixlinux; yarn cobertura
Expand Down
2 changes: 1 addition & 1 deletion openc3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ case $1 in
test )
scripts/linux/openc3_setup.sh
${DOCKER_COMPOSE_COMMAND} -f compose.yaml -f compose-build.yaml build
scripts/linux/openc3_test.sh $2
scripts/linux/openc3_test.sh "${@:2}"
;;
util )
set -a
Expand Down
4 changes: 2 additions & 2 deletions playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default defineConfig({
globalTimeout: 60 * 60 * 1000,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 1 : 0,
/* Retry once on CI */
retries: process.env.CI ? 1 : 2,
workers: 1,
/* See if explict WORKERS count was given, otherwise allow parallelism on CI/CD */
// workers: process.env.WORKERS
Expand Down
48 changes: 48 additions & 0 deletions playwright/playwright.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

usage() {
echo "Usage: $1 [install-playwright, build-plugin, reset-storage-state, run-local, run-chromium]" >&2
echo "* install-playwright: installs playwright and its dependencies" >&2
echo "* build-plugin: builds the plugin to be used in the playwright tests" >&2
echo "* reset-storage-state: clear out cached data" >&2
echo "* run-chromium: runs the playwright tests against a locally running version of Cosmos using Chrome" >&2
exit 1
}

if [ "$#" -eq 0 ]; then
usage $0
fi

case $1 in
install-playwright )
# Attempt to clean up downloaded browser binaries
# https://playwright.dev/docs/ci#directories-to-cache
[ -d $HOME/.cache/ms-playwright ] && rm -rf $HOME/.cache/ms-playwright # linux
[ -d $HOME/Library/Caches/ms-playwright ] && rm -rf $HOME/Library/Caches/ms-playwright # mac

rm -rf node_modules

yarn; yarn playwright install --with-deps; yarn playwright --version

./reset_storage_state.sh
;;

build-plugin )
rm -rf openc3-cosmos-pw-test
../openc3.sh cli generate plugin PW_TEST
cd openc3-cosmos-pw-test
../../openc3.sh cli generate target PW_TEST
../../openc3.sh cli rake build VERSION=1.0.0
cp openc3-cosmos-pw-test-1.0.0.gem openc3-cosmos-pw-test-1.0.1.gem
../../openc3.sh cli validate openc3-cosmos-pw-test-1.0.0.gem
cd -
;;

reset-storage-state )
./reset_storage_state.sh
;;

run-chromium )
yarn playwright test "${@:2}" --project=chromium
;;
esac
9 changes: 9 additions & 0 deletions playwright/reset_storage_state.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# https://stackoverflow.com/a/246128
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Initialize an empty storageState.
# The script that populates this file also attempts to read it, and so needs some initial state.
echo "{}" > ${SCRIPT_DIR}/storageState.json
echo "{}" > ${SCRIPT_DIR}/adminStorageState.json
4 changes: 2 additions & 2 deletions playwright/tests/admin/plugins.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ test('installs a new plugin', async ({ page, utils }) => {
// Opens the file chooser.
await page.locator('text=Click to install').click({ force: true }),
])
await fileChooser.setFiles(`../${plugin}/${pluginGem}`)
await fileChooser.setFiles(`./${plugin}/${pluginGem}`)
await expect(page.locator('.v-dialog:has-text("Variables")')).toBeVisible()
await page.locator('data-test=edit-submit').click()
await expect(page.locator('[data-test=plugin-alert]')).toContainText(
Expand Down Expand Up @@ -402,7 +402,7 @@ test('upgrades existing plugin', async ({ page, utils }) => {
)
.click(),
])
await fileChooser.setFiles(`../${plugin}/${pluginGem1}`)
await fileChooser.setFiles(`./${plugin}/${pluginGem1}`)
await expect(page.locator('.v-dialog:has-text("Variables")')).toBeVisible()
await page.locator('data-test=edit-submit').click()
await expect(page.locator('.v-dialog:has-text("Modified")')).toBeVisible()
Expand Down
38 changes: 38 additions & 0 deletions scripts/linux/openc3_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,44 @@ case $1 in
rspec
cd -
;;

playwright )
case $2 in
install-playwright )
cd playwright
./playwright.sh install-playwright
cd -
;;

build-plugin )
cd playwright
./playwright.sh build-plugin
cd -
;;

run-chromium )
cd playwright
./playwright.sh run-chromium "${@:3}"
cd -
;;

reset-storage-state )
cd playwright
./playwright.sh reset-storage-state
cd -
;;

* )
echo "Usage:" >&2
echo "* install-playwright: installs playwright and its dependencies" >&2
echo "* build-plugin: builds the plugin to be used in the playwright tests" >&2
echo "* run-chromium: runs the playwright tests against a locally running version of Cosmos using Chrome" >&2
echo "* reset-storage-state: clear out cached data" >&2
;;

esac
;;

hash )
${DOCKER_COMPOSE_COMMAND} -f compose.yaml up -d
cd playwright
Expand Down

0 comments on commit 2320f76

Please sign in to comment.