-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial testing * Added tests for documents * Added well-and-monitoring-data test * Updates on testing * Minor updates on tests * Minor spelling
- Loading branch information
1 parent
90dc963
commit 7c11732
Showing
20 changed files
with
1,218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use nix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Validation Tests | ||
|
||
These tests are designed to run from your local machine (i.e. not from a GitHub action or CI). | ||
They are intended to verify basic functionality is working after a deployment is made to staging, and before deployment to production. | ||
|
||
## Essential reading: | ||
|
||
* https://playwright.dev/ | ||
* https://direnv.net/docs/installation.html | ||
|
||
## Setting up your environment | ||
|
||
Before you can run or record tests, you need to set up your environment. | ||
|
||
Running these tests require playwright set up on your local machine, as well as NodeJS. | ||
|
||
### NixOS | ||
|
||
If you are a NixOS user, you can set up direnv and then cd into this directory in your shell. | ||
|
||
When you do so the first time, you will be prompted to allow direnv which you can do using this command: | ||
|
||
|
||
```bash | ||
direnv allow | ||
``` | ||
|
||
> This may take a while the first time as NixOS builds you a sandbox environment. | ||
### NON-NixOS | ||
|
||
For a non-NixOS user(Debian/Ubuntu) set up your environment by the following commands: | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
To install playwright browsers with OS-level dependencies use: | ||
|
||
|
||
```bash | ||
npm playwright install --with-deps | ||
``` | ||
|
||
**NOTE:** This only works with Debian/Ubuntu as they receive official support from playwright. It will also request your master password to install the dependencies. | ||
|
||
## Recording a test | ||
|
||
There is a bash helper script that will let you quickly create a new test: | ||
|
||
``` | ||
Usage: ./record-test.sh TESTNAME | ||
e.g. ./record-test.sh mytest | ||
will write a new test to tests/mytest.spec.ts | ||
Do not use spaces in your test name. | ||
Test files MUST END in .spec.ts | ||
After recording your test, close the test browser. | ||
You can then run your test by doing: | ||
./run-tests.sh | ||
``` | ||
|
||
## Running a test | ||
|
||
```bash | ||
./run-tests.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Setting BASE_URL for test site" | ||
BASE_URL=https://ggis.un-igrac.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
source base-url.sh | ||
|
||
source playwright-path.sh | ||
|
||
echo "This script will write a new test to tests/deleteme.spec.ts" | ||
echo "then delete it, leaving only the auth config." | ||
echo "" | ||
echo "When the playwright browser opens, log in to the site then exit." | ||
echo "After recording your test, close the test browser." | ||
echo "Recording auth token to auth.json" | ||
|
||
# File exists and write permission granted to user | ||
# show prompt | ||
echo "Continue? y/n" | ||
read ANSWER | ||
case $ANSWER in | ||
[yY] ) echo "Writing auth.json" ;; | ||
[nN] ) echo "Cancelled."; exit ;; | ||
esac | ||
|
||
$PLAYWRIGHT \ | ||
codegen \ | ||
--target playwright-test \ | ||
--save-storage=auth.json \ | ||
-o tests/deleteme.spec.ts \ | ||
$BASE_URL | ||
|
||
# We are only interested in sawps-auth.json | ||
rm tests/deleteme.spec.ts | ||
|
||
echo "Auth file creation completed." | ||
echo "You can then run your tests by doing e.g.:" | ||
echo "playwright test --project chromium" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "NodeJS will be installed if not present" | ||
echo "Sudo password will be required" | ||
|
||
# Download and import Nodesource GPG key | ||
sudo apt-get update | ||
sudo apt-get install -y ca-certificates curl gnupg | ||
sudo mkdir -p /etc/apt/keyrings | ||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg | ||
|
||
# Create deb repository | ||
NODE_MAJOR=18 | ||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list | ||
|
||
# Update repository and install | ||
sudo apt-get update | ||
sudo apt-get install nodejs -y | ||
|
||
echo "Done" | ||
echo "" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "staging-tests", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@playwright/test": "^1.40.0", | ||
"@types/node": "^20.9.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "This script will discover the path to your playwright install" | ||
echo "If you are not in a NixOS environment and it is not installed," | ||
echo "playwright will be installed." | ||
echo "" | ||
echo "At the end of calling this script, you should have a PLAYWRIGHT" | ||
echo "" | ||
|
||
# Are we on nixos or a distro with Nix installed for packages | ||
# Y | ||
# Are we in direnv? | ||
# Y: should all be set up | ||
# N: run nix-shell | ||
#N | ||
# Are we in a deb based distro? | ||
# Are we in an rpm based distro? | ||
# Are we on macOS? | ||
# Are we in windows? | ||
|
||
HAS_PLAYWRIGHT=$(which playwright | grep -v "which: no" | wc -l) | ||
PLAYWRIGHT="playwright" | ||
if [ $HAS_PLAYWRIGHT -eq 0 ]; then | ||
PLAYWRIGHT="npx playwright" | ||
|
||
# check if OS is a deb based distro and uses apt | ||
USES_APT=$(which apt | grep -w "apt" | wc -l) | ||
if [ $USES_APT -eq 1 ]; then | ||
# check if nodejs is installed | ||
HAS_NODEJS=$(which node | grep -w "node" | wc -l) | ||
# if nodejs is present then | ||
if [ $HAS_NODEJS -eq 0 ]; then | ||
source nodesource-install.sh | ||
fi | ||
# check if npm is present | ||
HAS_NPM=$(which npm | grep -w "npm" | wc -l) | ||
NPM="npm" | ||
if [ $HAS_NPM -eq 1 ]; then | ||
PACKAGE_JSON=$(ls | grep -w "package.json" | wc -l) | ||
PLAYWRIGHT_INSTALL=$($NPM ls --depth 1 playwright | grep -w "@playwright/test" | wc -l) | ||
|
||
if [ $PLAYWRIGHT_INSTALL -eq 0 ] && [ $PACKAGE_JSON -eq 0 ]; then | ||
$NPM init playwright@latest | ||
|
||
elif [ $PLAYWRIGHT_INSTALL -eq 0 ]; then | ||
$NPM install | ||
$PLAYWRIGHT install --with-deps chromium | ||
fi | ||
|
||
fi | ||
|
||
fi | ||
|
||
fi | ||
|
||
echo "Done." | ||
echo "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: './tests', | ||
/* Extend normal timeout */ | ||
timeout: 2 * 60 * 1000, | ||
/* Extend expect timeout */ | ||
expect: { timeout: 30000 }, | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* 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 ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'html', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: 'https://ggis.un-igrac.org/', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
|
||
//{ | ||
// name: 'firefox', | ||
// use: { ...devices['Desktop Firefox'] }, | ||
//}, | ||
|
||
//{ | ||
// name: 'webkit', | ||
// use: { ...devices['Desktop Safari'] }, | ||
//}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// url: 'http://127.0.0.1:3000', | ||
// reuseExistingServer: !process.env.CI, | ||
// }, | ||
}); |
Oops, something went wrong.