Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated testing scripts and playwright version #180

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions playwright/ci-test/base-url.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

echo "Setting BASE_URL for test site"
BASE_URL=http://localhost:8888

35 changes: 35 additions & 0 deletions playwright/ci-test/create-auth.sh
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 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"
23 changes: 23 additions & 0 deletions playwright/ci-test/nodesource-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

echo "NodeJS will be installed if not present"
echo "sudo password will be required"

USES_APT=$(which apt | grep -w "apt" | wc -l)
USES_RPM=$(which rpm | grep -w "rpm" | wc -l)

if [ $USES_APT -eq 1 ]; then
curl -SLO https://deb.nodesource.com/nsolid_setup_deb.sh
sudo chmod 500 nsolid_setup_deb.sh
sudo ./nsolid_setup_deb.sh 20
sudo apt-get install nodejs -y

elif [ $USES_RPM -eq 1 ]; then
curl -SLO https://rpm.nodesource.com/nsolid_setup_rpm.sh
sudo chmod 500 nsolid_setup_rpm.sh
sudo ./nsolid_setup_rpm.sh 20
sudo yum install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1
fi

echo "Done"
echo ""
4 changes: 1 addition & 3 deletions playwright/ci-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
},
"homepage": "https://github.com/unicef-drp/GeoRepo-OS",
"devDependencies": {
"@playwright/test": "^1.39.0",
"@playwright/test": "^1.40.1",
"@types/node": "^20.8.6"
},
"dependencies": {
},
"overrides": {}
}
83 changes: 83 additions & 0 deletions playwright/ci-test/playwright-path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/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 2> /dev/null | 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 2> /dev/null | grep -w "apt" | wc -l)
# check if OS is an rpm-based distro
USES_RPM=$(which rpm | grep -w "rpm" | 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)

if [ $HAS_NPM -eq 1 ]; then
NPM="npm"
PLAYWRIGHT_INSTALL=$($NPM ls --depth 1 playwright | grep -w "@playwright/test" | wc -l)

if [ $PLAYWRIGHT_INSTALL -eq 0 ]; then
$NPM install -D @playwright/test@latest
$NPM ci
$PLAYWRIGHT install --with-deps chromium
fi

fi

elif [ $USES_RPM -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)

if [ $HAS_NPM -eq 1 ]; then
NPM="npm"
PLAYWRIGHT_INSTALL=$($NPM ls --depth 1 playwright | grep -w "@playwright/test" | wc -l)

if [ $PLAYWRIGHT_INSTALL -eq 0 ]; then
$NPM install -D @playwright/test@latest
$NPM ci
$PLAYWRIGHT install
fi

fi
fi
fi

echo "Done."
echo ""
44 changes: 44 additions & 0 deletions playwright/ci-test/record-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

source base-url.sh

source playwright-path.sh

if [ -z "$1" ]
then
echo "Usage: $0 TESTNAME"
echo "e.g. $0 mytest"
echo "will write a new test to tests/mytest.spec.ts"
echo "Do not use spaces in your test name."
echo ""
echo "After recording your test, close the test browser."
echo "You can then run your test by doing:"
echo "npx playwright test tests/mytest.spec.py"
exit
else
echo "Recording test to tests/${1}"
fi

if [ -w "tests/${1}.spec.ts" ]; then
# File exists and write permission granted to user
# show prompt
echo "File tests/${1}.spec.ts exists. Overwrite? y/n"
read ANSWER
case $ANSWER in
[yY] ) echo "Writing recorded test to tests/${1}.spec.ts" ;;
[nN] ) echo "Cancelled."; exit ;;
esac
fi
TESTNAME=$1

$PLAYWRIGHT \
codegen \
--target playwright-test \
--load-storage=auth.json \
-o tests/$1.spec.ts \
$BASE_URL


echo "Test recording completed."
echo "You can then run your test by doing:"
echo "./run-tests.sh"
14 changes: 14 additions & 0 deletions playwright/ci-test/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

source playwright-path.sh

echo "This script will run the tests defined in tests/"
echo "Before running the tests you need to create the auth config"
echo ""

$PLAYWRIGHT \
test \
--ui \
--project chromium

echo "--done--"
26 changes: 14 additions & 12 deletions playwright/staging-tests/nodesource-install.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/usr/bin/env bash

echo "NodeJS will be installed if not present"
echo "Sudo password will be required"
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
USES_APT=$(which apt | grep -w "apt" | wc -l)
USES_RPM=$(which rpm | grep -w "rpm" | wc -l)

# 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
if [ $USES_APT -eq 1 ]; then
curl -SLO https://deb.nodesource.com/nsolid_setup_deb.sh
sudo chmod 500 nsolid_setup_deb.sh
sudo ./nsolid_setup_deb.sh 20
sudo apt-get install nodejs -y

# Update repository and install
sudo apt-get update
sudo apt-get install nodejs -y
elif [ $USES_RPM -eq 1 ]; then
curl -SLO https://rpm.nodesource.com/nsolid_setup_rpm.sh
sudo chmod 500 nsolid_setup_rpm.sh
sudo ./nsolid_setup_rpm.sh 20
sudo yum install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1
fi

echo "Done"
echo ""
2 changes: 1 addition & 1 deletion playwright/staging-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.33.0"
"@playwright/test": "^1.40.1"
}
}
80 changes: 53 additions & 27 deletions playwright/staging-tests/playwright-path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,65 @@ echo ""
# Are we on macOS?
# Are we in windows?

HAS_PLAYWRIGHT=$(which playwright | grep -v "which: no" | wc -l)
HAS_PLAYWRIGHT=$(which playwright 2> /dev/null | grep -v "which: no" | wc -l)
PLAYWRIGHT="playwright"
if [ $HAS_PLAYWRIGHT -eq 0 ]; then
PLAYWRIGHT="npx playwright"
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
# check if OS is a deb based distro and uses apt
USES_APT=$(which apt 2> /dev/null | grep -w "apt" | wc -l)
# check if OS is an rpm-based distro
USES_RPM=$(which rpm | grep -w "rpm" | wc -l)

fi
if [ $USES_APT -eq 1 ]; then
# check if nodejs is installed
HAS_NODEJS=$(which node | grep -w "node" | wc -l)

fi
# 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)

if [ $HAS_NPM -eq 1 ]; then
NPM="npm"
PLAYWRIGHT_INSTALL=$($NPM ls --depth 1 playwright | grep -w "@playwright/test" | wc -l)

if [ $PLAYWRIGHT_INSTALL -eq 0 ]; then
$NPM install -D @playwright/test@latest
$NPM ci
$PLAYWRIGHT install --with-deps chromium
fi

fi

elif [ $USES_RPM -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)

if [ $HAS_NPM -eq 1 ]; then
NPM="npm"
PLAYWRIGHT_INSTALL=$($NPM ls --depth 1 playwright | grep -w "@playwright/test" | wc -l)

if [ $PLAYWRIGHT_INSTALL -eq 0 ]; then
$NPM install -D @playwright/test@latest
$NPM ci
$PLAYWRIGHT install
fi

fi
fi
fi

echo "Done."
Expand Down
Loading