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

Development: Improve and simplify local playwright setup #9796

Merged
merged 30 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ac2cf03
changed playwright setup
SimonEntholzer Nov 16, 2024
cbfc6c5
Merge branch 'develop' into feature/playwright/simplify-setup
SimonEntholzer Nov 16, 2024
3ff01f2
change port for docker compose
SimonEntholzer Nov 16, 2024
1bec0c1
flip ports
SimonEntholzer Nov 16, 2024
d256a8e
use local profile for local playwright
SimonEntholzer Nov 16, 2024
9e7af01
use local profile for local playwright
SimonEntholzer Nov 16, 2024
f65b9e3
undo changes as it seems we need a client
SimonEntholzer Nov 16, 2024
f511df7
Merge branch 'develop' into feature/playwright/simplify-setup
SimonEntholzer Dec 4, 2024
f73eaf8
simplify setup scripts
SimonEntholzer Dec 4, 2024
7973c1f
improve readme
SimonEntholzer Dec 4, 2024
adeb013
Merge branch 'develop' into feature/playwright/simplify-setup
SimonEntholzer Dec 6, 2024
a931452
replace placeholder
SimonEntholzer Dec 6, 2024
dbb16c7
undo
SimonEntholzer Dec 6, 2024
10d4115
simplify more
SimonEntholzer Dec 6, 2024
e988f2e
improved docs
SimonEntholzer Dec 6, 2024
7a83192
remove configuration copy from macos setup
SimonEntholzer Dec 6, 2024
7ef9160
improved docs
SimonEntholzer Dec 6, 2024
0f1fb62
re-add import User file
SimonEntholzer Dec 6, 2024
7700d30
remove local profile
SimonEntholzer Dec 6, 2024
910395d
und package json change
SimonEntholzer Dec 6, 2024
b9ad82f
make package json work on bamboo and locally
SimonEntholzer Dec 7, 2024
13d4115
Merge branch 'develop' into feature/playwright/simplify-setup
SimonEntholzer Dec 7, 2024
9757a05
Merge branch 'develop' into feature/playwright/simplify-setup
SimonEntholzer Dec 7, 2024
35031ca
update docs
SimonEntholzer Dec 7, 2024
38fdf31
Merge branch 'develop' into feature/playwright/simplify-setup
SimonEntholzer Dec 10, 2024
889887e
changed cd to absolute paths
SimonEntholzer Dec 10, 2024
b0e9a78
remove note as scripts can be called from anywhere now
SimonEntholzer Dec 10, 2024
4a91a81
Merge branch 'develop' into feature/playwright/simplify-setup
SimonEntholzer Dec 10, 2024
b013289
also use absolute path in start playwright script
SimonEntholzer Dec 10, 2024
842dbaf
Merge remote-tracking branch 'refs/remotes/origin/feature/playwright/…
SimonEntholzer Dec 10, 2024
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
2 changes: 1 addition & 1 deletion docker/artemis/config/dev-local-vc-local-ci.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://docs.artemis.cit.tum.de/dev/setup.html#debugging-with-docker
_JAVA_OPTIONS: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005

SPRING_PROFILES_ACTIVE: artemis,scheduling,localci,localvc,buildagent,core,dev,docker
SPRING_PROFILES_ACTIVE: artemis,scheduling,localci,localvc,buildagent,core,dev,docker,local

# Integrated Code Lifecycle settings with Jira
ARTEMIS_USERMANAGEMENT_USEEXTERNAL="false"
Expand Down
33 changes: 20 additions & 13 deletions docs/dev/playwright.rst
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,47 @@ Playwright tests rely on the Playwright Node.js library, browser binaries, and s

.. code-block:: text

PLAYWRIGHT_USERNAME_TEMPLATE=artemis_test_user_USERID
PLAYWRIGHT_PASSWORD_TEMPLATE=artemis_test_user_USERID
PLAYWRIGHT_USERNAME_TEMPLATE=artemis_test_user_
PLAYWRIGHT_PASSWORD_TEMPLATE=artemis_test_user_
ADMIN_USERNAME=artemis_admin
ADMIN_PASSWORD=artemis_admin
ALLOW_GROUP_CUSTOMIZATION=true
STUDENT_GROUP_NAME=students
TUTOR_GROUP_NAME=tutors
EDITOR_GROUP_NAME=editors
INSTRUCTOR_GROUP_NAME=instructors
CREATE_USERS=true
BASE_URL=http://localhost:9000
EXERCISE_REPO_DIRECTORY=test-exercise-repos
FAST_TEST_TIMEOUT_SECONDS=45
SLOW_TEST_TIMEOUT_SECONDS=180


Make sure ``BASE_URL`` matches your Artemis client URL and ``ADMIN_USERNAME`` and
``ADMIN_PASSWORD`` match your Artemis admin user credentials.

3. Configure test users

Playwright tests require users with different roles to simulate concurrent user interactions. You can configure
user IDs and check their corresponding user roles in the ``src/test/playwright/support/users.ts`` file. Usernames
are defined automatically by replacing the ``USERID`` part in ``PLAYWRIGHT_USERNAME_TEMPLATE`` with the
corresponding user ID. If users with such usernames do not exist, set ``CREATE_USERS`` to ``true`` on the
``playwright.env`` file for users to be created during the setup stage. If users with the same usernames but
different user roles already exist, change the user IDs to different values to ensure that new users are created
with roles defined in the configuration.
Playwright tests require users with different roles to simulate concurrent user interactions. If you already
have generated test users, you can skip this step. Generate users with the help of the user creation scripts under
`supportingScripts/playwright`:

.. code-block:: bash

setupUsers.sh

You can configure user IDs and check their corresponding user roles in the ``src/test/playwright/support/users.ts`` file.
Usernames are defined automatically by appending the userId to the ``PLAYWRIGHT_USERNAME_TEMPLATE``.
At the moment it is discouraged to change the template string, as the user creation script does not support other names yet.

4. Setup Playwright package and its browser binaries:

Install Playwright browser binaries, set up the environment to ensure Playwright can locate these binaries, and
create test users (if creating users is enabled in the configuration) with the following command:
Install Playwright browser binaries, set up the environment to ensure Playwright can locate these binaries.
On some operating systems this might not work, and playwright needs to be manually installed via a package manager.

.. code-block:: bash

npm run playwright:setup
npm run playwright:install


5. Open Playwright UI

Expand Down
30 changes: 30 additions & 0 deletions src/main/resources/config/application-local-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
artemis:
telemetry:
enabled: false # setting this to false will disable sending any information to the telemetry service
user-management:
use-external: false
internal-admin:
username: artemis_admin
password: artemis_admin
login:
account-name: TUM
version-control:
url: http://localhost:8080
use-version-control-access-token: true
show-clone-url-without-token: true
continuous-integration:
# Only necessary on ARM-based systems, the default is amd64 for Intel/AMD systems
# ARM-based systems include Apple M-series, Raspberry Pi, etc.
image-architecture: amd64
# Only necessary on Windows:
specify-concurrent-builds: true
# The number of concurrent builds that can be executed
concurrent-build-size: 2
server:
port: 8080
url: http://localhost
eureka:
client:
enabled: false
info:
operatorName: Test Operator
29 changes: 0 additions & 29 deletions src/test/playwright/init/ImportUsers.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"playwright:test:parallel": "cross-env PLAYWRIGHT_JUNIT_OUTPUT_NAME=./test-reports/results-parallel.xml playwright test e2e --project=fast-tests --project=slow-tests",
"playwright:test:sequential": "cross-env PLAYWRIGHT_JUNIT_OUTPUT_NAME=./test-reports/results-sequential.xml playwright test e2e --project=sequential-tests --workers 1",
"playwright:open": "playwright test e2e --ui",
"playwright:setup": "npx playwright install --with-deps chromium && playwright test init",
"playwright:install": "npx playwright install --with-deps chromium",
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
"merge-reports": "junit-merge ./test-reports/results-parallel.xml ./test-reports/results-sequential.xml -o ./test-reports/results.xml",
"update": "ncu -i --format group"
}
Expand Down
5 changes: 2 additions & 3 deletions src/test/playwright/playwright.env
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
PLAYWRIGHT_USERNAME_TEMPLATE=artemis_test_user_USERID
PLAYWRIGHT_PASSWORD_TEMPLATE=artemis_test_user_USERID
PLAYWRIGHT_USERNAME_TEMPLATE=artemis_test_user_
PLAYWRIGHT_PASSWORD_TEMPLATE=artemis_test_user_
ADMIN_USERNAME=artemis_admin
ADMIN_PASSWORD=artemis_admin
ALLOW_GROUP_CUSTOMIZATION=true
STUDENT_GROUP_NAME=students
TUTOR_GROUP_NAME=tutors
EDITOR_GROUP_NAME=editors
INSTRUCTOR_GROUP_NAME=instructors
CREATE_USERS=true
BASE_URL=http://localhost:9000
EXERCISE_REPO_DIRECTORY=test-exercise-repos
FAST_TEST_TIMEOUT_SECONDS=45
Expand Down
27 changes: 27 additions & 0 deletions supporting_scripts/playwright/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Easy Artemis set up and running playwright locally

Running playwright locally involves three steps:
1. Run an Artemis application instance, with client and server.
2. If no users have been set up, set up users.
3. Install and run playwright.

Note: run all setup scripts from within this directory. (cd supporting_scripts/playwright)

## 1. Start Artemis

To start Artemis, depending on your OS, either run `runArtemisInDocker_macOS.sh` or `runArtemisInDocker_linux.sh`.
This will set up the database, start Artemis inside a docker container, and start the client via npm.
After this step, you are be able to access Artemis locally as you usually would be.
Note that you need to run the scripts in step 2 and 3 in another shell, as the client needs to keep running.
In case you stop the client, you can simply re-run it at the root of the Artemis project with `npm run start`.

## 2. Setup users

Playwright needs users for it's tests. If you do not have users set up, you can simply do so by running:
`setupUsers.sh`
This will create 20 test users.

## 3. Setup Playwright and run Playwright in UI-mode

Simply run: `startPlaywright.sh`. This will install the necessary dependencies for playwright and start it in UI mode.
If you already have playwright installed, you can also start playwright directly from the `src/test/playwright` directory with `npm run playwright:open`.
31 changes: 31 additions & 0 deletions supporting_scripts/playwright/runArtemisInDocker_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

set -e

cd ../..

# configure application and start

if [ ! -f src/main/resources/config/application-local.yml ]; then
cp src/main/resources/config/application-local-template.yml src/main/resources/config/application-local.yml
fi

echo "Copied configuration"

cd docker

echo "Pulling newest artemis docker image"
docker pull ghcr.io/ls1intum/artemis

SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
echo "Updating docker group ID in the docker compose file"
sed -i "s/999/$(getent group docker | cut -d: -f3)/g" artemis-dev-local-vc-local-ci-mysql.yml

docker compose -f artemis-dev-local-vc-local-ci-mysql.yml up -d
echo "Finished docker compose"
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved

cd ..

echo "Installing Artemis npm dependencies and start Artemis client"

npm install
npm run start
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
37 changes: 37 additions & 0 deletions supporting_scripts/playwright/runArtemisInDocker_macOS.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

set -e

cd ../..

# configure application and start

if [ ! -f src/main/resources/config/application-local.yml ]; then
cp src/main/resources/config/application-local-template.yml src/main/resources/config/application-local.yml
fi

echo "Copied configuration"

cd docker
open -a Docker

SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
echo "Pulling newest artemis docker image"
docker pull ghcr.io/ls1intum/artemis

echo "Updating docker group ID in the docker compose file"
PRIMARY_GROUP_ID=$(dscl . -read /Groups/docker PrimaryGroupID | awk '{print $2}')
if [ -n "$PRIMARY_GROUP_ID" ]; then
sed -i '' "s/999/$PRIMARY_GROUP_ID/g" artemis-dev-local-vc-local-ci-mysql.yml
else
echo "PrimaryGroupID not found, skipping replacement"
fi
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved

docker compose -f artemis-dev-local-vc-local-ci-mysql.yml up -d
echo "Finished docker compose"

cd ..

echo "Installing Artemis npm dependencies and start Artemis client"

npm install
npm run start
18 changes: 18 additions & 0 deletions supporting_scripts/playwright/setupUsers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

# We use the supporting scripts to create users

set -e

cd ..

if [ ! -d "venv" ]; then
python -m venv venv
fi
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved

source venv/bin/activate
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved

cd course-scripts/quick-course-setup

python3 -m pip install -r requirements.txt
python3 create_users.py
SimonEntholzer marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions supporting_scripts/playwright/startPlaywright.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

set -e

cd ../..

echo "Installing Playwright and dependencies"

cd src/test/playwright

npm install

npm run playwright:install || true

echo "Starting Playwright in UI mode"
npm run playwright:open
Loading