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: Run e2e tests on bamboo #9964

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 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
76405b4
Merge branch 'develop' into feature/playwright/simplify-setup-3
SimonEntholzer Dec 7, 2024
e1b80dc
Merge branch 'feature/playwright/simplify-setup' into feature/playwri…
SimonEntholzer Dec 8, 2024
0291567
Merge branch 'develop' into feature/playwright/simplify-setup-3
SimonEntholzer Dec 8, 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
47 changes: 34 additions & 13 deletions docs/dev/playwright.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ Set up Playwright locally
To run the tests locally, developers need to set up Playwright on their machines.
End-to-end tests test entire workflows; therefore, they require the whole Artemis setup - database, client, and server to be running.
Playwright tests rely on the Playwright Node.js library, browser binaries, and some helper packages.
To run playwright tests locally, you need to start the Artemis server and client, have the correct users set up and install and run playwright.
This setup should be used for debugging, and creating new tests for your code, but needs intellij to work, and relies on fully setting up your local Artemis instance
following :ref:`the server setup guide<dev_setup>`.


For a quick test setup with only three steps, you can use the scripts provided in `supportingScripts/playwright`.
The README explains what you need to do.
It sets up Artemis inside a dockerized environment, creates users and directly starts playwright. The main drawback with this setup is, that you cannot
easily change the version of Artemis itself.


If you want to manually install playwright, you can follow these steps:

1. Install dependencies:

Expand All @@ -29,40 +41,49 @@ 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 the
`supportingScripts/playwright` folder:

.. 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:setup-local
npm run playwright:init



5. Open Playwright UI

Expand Down
2 changes: 2 additions & 0 deletions src/test/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"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:setup-local": "npx playwright install --with-deps chromium",
"playwright:init": "playwright test init",
"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`.
22 changes: 22 additions & 0 deletions supporting_scripts/playwright/runArtemisInDocker_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

set -e

cd ../..

echo "Copied configuration"

cd docker

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"

cd ..

echo "Installing Artemis npm dependencies and start Artemis client"

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

set -e

cd ../..

cd docker
open -a Docker

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

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

source venv/bin/activate

cd course-scripts/quick-course-setup

python3 -m pip install -r requirements.txt
python3 create_users.py
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:setup-local || true

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