From ac2cf03839b60a9aeb3f0ec804db1194b51e99e8 Mon Sep 17 00:00:00 2001 From: Simon Entholzer Date: Sat, 16 Nov 2024 15:04:25 +0100 Subject: [PATCH 01/19] changed playwright setup --- docs/dev/playwright.rst | 33 +++++++++++-------- .../config/application-local-template.yml | 30 +++++++++++++++++ src/test/playwright/init/ImportUsers.spec.ts | 29 ---------------- src/test/playwright/init/initialize_users.sh | 20 +++++++++++ src/test/playwright/package.json | 3 +- src/test/playwright/playwright.env | 5 ++- 6 files changed, 74 insertions(+), 46 deletions(-) create mode 100644 src/main/resources/config/application-local-template.yml delete mode 100644 src/test/playwright/init/ImportUsers.spec.ts create mode 100644 src/test/playwright/init/initialize_users.sh diff --git a/docs/dev/playwright.rst b/docs/dev/playwright.rst index af16556675b5..2259a9a52ec1 100644 --- a/docs/dev/playwright.rst +++ b/docs/dev/playwright.rst @@ -29,8 +29,8 @@ 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 @@ -38,31 +38,38 @@ Playwright tests rely on the Playwright Node.js library, browser binaries, and s 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, or simply run: + + .. code-block:: bash + + npm run playwright:setup-users + + 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 diff --git a/src/main/resources/config/application-local-template.yml b/src/main/resources/config/application-local-template.yml new file mode 100644 index 000000000000..401adf70dffd --- /dev/null +++ b/src/main/resources/config/application-local-template.yml @@ -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 diff --git a/src/test/playwright/init/ImportUsers.spec.ts b/src/test/playwright/init/ImportUsers.spec.ts deleted file mode 100644 index 8ccf886c770b..000000000000 --- a/src/test/playwright/init/ImportUsers.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { test } from '../support/fixtures'; -import { admin, instructor, studentFour, studentOne, studentThree, studentTwo, tutor } from '../support/users'; -import { USER_ID, USER_ROLE, users } from '../support/users'; - -test.describe('Setup users', async () => { - if (process.env.CREATE_USERS == 'true') { - test.beforeEach('Creates all required users', async ({ login, userManagementAPIRequests }) => { - await login(admin); - for (const userKey in USER_ID) { - const user = users.getUserWithId(USER_ID[userKey]); - const getUserResponse = await userManagementAPIRequests.getUser(user.username); - if (!getUserResponse.ok()) { - await userManagementAPIRequests.createUser(user.username, user.password, USER_ROLE[userKey]); - } - } - }); - } - - test('Logs in once with all required users', async ({ login }) => { - // If Artemis hasn't imported the required users from Jira we have to force this by logging in with these users once - await login(admin); - await login(instructor); - await login(tutor); - await login(studentOne); - await login(studentTwo); - await login(studentThree); - await login(studentFour); - }); -}); diff --git a/src/test/playwright/init/initialize_users.sh b/src/test/playwright/init/initialize_users.sh new file mode 100644 index 000000000000..163b01747d00 --- /dev/null +++ b/src/test/playwright/init/initialize_users.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# We use the supporting scripts to create users + +set -e + +cd ../../../supporting_scripts + +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 + +cd ../../../src/test/playwright diff --git a/src/test/playwright/package.json b/src/test/playwright/package.json index 3b34e25864e8..3c05b575f9c7 100644 --- a/src/test/playwright/package.json +++ b/src/test/playwright/package.json @@ -19,7 +19,8 @@ "playwright:test:fast": "cross-env PLAYWRIGHT_JUNIT_OUTPUT_NAME=./test-reports/results-fast.xml playwright test e2e --project=fast-tests", "playwright:test:slow": "cross-env PLAYWRIGHT_JUNIT_OUTPUT_NAME=./test-reports/results-slow.xml playwright test e2e --project=slow-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", + "playwright:setup-users": "/bin/sh init/initialize_users.sh", "merge-reports": "junit-merge ./test-reports/results-fast.xml ./test-reports/results-slow.xml -o ./test-reports/results.xml", "update": "ncu -i --format group" } diff --git a/src/test/playwright/playwright.env b/src/test/playwright/playwright.env index b60373794a3b..b94fac3f3589 100644 --- a/src/test/playwright/playwright.env +++ b/src/test/playwright/playwright.env @@ -1,5 +1,5 @@ -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 @@ -7,7 +7,6 @@ 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 From 3ff01f2b14d375afe07f69040e5a07b0b93efb7b Mon Sep 17 00:00:00 2001 From: Simon Entholzer Date: Sat, 16 Nov 2024 19:18:52 +0100 Subject: [PATCH 02/19] change port for docker compose --- docker/artemis-dev-local-vc-local-ci-mysql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/artemis-dev-local-vc-local-ci-mysql.yml b/docker/artemis-dev-local-vc-local-ci-mysql.yml index 25f62aaf048c..e440829b626c 100644 --- a/docker/artemis-dev-local-vc-local-ci-mysql.yml +++ b/docker/artemis-dev-local-vc-local-ci-mysql.yml @@ -17,7 +17,7 @@ services: group_add: - "999" ports: - - "8080:8080" + - "8080:9000" - "5005:5005" # Java Remote Debugging port declared in the java cmd options # expose the port to make it reachable docker internally even if the external port mapping changes expose: From 1bec0c11390781f6da74cd311d3e6dc5403270ff Mon Sep 17 00:00:00 2001 From: entholzer Date: Sat, 16 Nov 2024 21:05:45 +0100 Subject: [PATCH 03/19] flip ports --- docker/artemis-dev-local-vc-local-ci-mysql.yml | 2 +- src/test/playwright/playwright.env | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/artemis-dev-local-vc-local-ci-mysql.yml b/docker/artemis-dev-local-vc-local-ci-mysql.yml index e440829b626c..25f62aaf048c 100644 --- a/docker/artemis-dev-local-vc-local-ci-mysql.yml +++ b/docker/artemis-dev-local-vc-local-ci-mysql.yml @@ -17,7 +17,7 @@ services: group_add: - "999" ports: - - "8080:9000" + - "8080:8080" - "5005:5005" # Java Remote Debugging port declared in the java cmd options # expose the port to make it reachable docker internally even if the external port mapping changes expose: diff --git a/src/test/playwright/playwright.env b/src/test/playwright/playwright.env index b94fac3f3589..6556b535a213 100644 --- a/src/test/playwright/playwright.env +++ b/src/test/playwright/playwright.env @@ -7,7 +7,7 @@ STUDENT_GROUP_NAME=students TUTOR_GROUP_NAME=tutors EDITOR_GROUP_NAME=editors INSTRUCTOR_GROUP_NAME=instructors -BASE_URL=http://localhost:9000 +BASE_URL=http://localhost:8080 EXERCISE_REPO_DIRECTORY=test-exercise-repos FAST_TEST_TIMEOUT_SECONDS=45 SLOW_TEST_TIMEOUT_SECONDS=180 From d256a8e86d8e10b3f62c7725d54981414060f075 Mon Sep 17 00:00:00 2001 From: entholzer Date: Sat, 16 Nov 2024 21:16:53 +0100 Subject: [PATCH 04/19] use local profile for local playwright --- docker/artemis/config/dev-local-vc-local-ci.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/artemis/config/dev-local-vc-local-ci.env b/docker/artemis/config/dev-local-vc-local-ci.env index e9099fa60bd9..a88d9ab0b21f 100644 --- a/docker/artemis/config/dev-local-vc-local-ci.env +++ b/docker/artemis/config/dev-local-vc-local-ci.env @@ -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" From 9e7af0132daed0e4c3a410f1455a95dd937ca411 Mon Sep 17 00:00:00 2001 From: entholzer Date: Sat, 16 Nov 2024 21:29:31 +0100 Subject: [PATCH 05/19] use local profile for local playwright --- .../course-scripts/quick-course-setup/create_users.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/supporting_scripts/course-scripts/quick-course-setup/create_users.py b/supporting_scripts/course-scripts/quick-course-setup/create_users.py index 2e702db2e92a..56921ee022a0 100644 --- a/supporting_scripts/course-scripts/quick-course-setup/create_users.py +++ b/supporting_scripts/course-scripts/quick-course-setup/create_users.py @@ -13,6 +13,7 @@ config.read('config.ini') # Constants from config file +SERVER_URL: str = config.get('Settings', 'server_url') CLIENT_URL: str = config.get('Settings', 'client_url') MAX_THREADS: int = int(config.get('Settings', 'max_threads')) @@ -21,7 +22,7 @@ def make_create_user_post_request(session: Session, user_details: dict) -> None: """Send a POST request to create a user.""" - url = f"{CLIENT_URL}/admin/users" + url = f"{SERVER_URL}/admin/users" headers = {"Content-Type": "application/json"} response = session.post(url, json=user_details, headers=headers) From f65b9e338cfb919693141cdfac4de67953da3afa Mon Sep 17 00:00:00 2001 From: entholzer Date: Sat, 16 Nov 2024 21:42:01 +0100 Subject: [PATCH 06/19] undo changes as it seems we need a client --- src/test/playwright/playwright.env | 2 +- .../course-scripts/quick-course-setup/create_users.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/playwright/playwright.env b/src/test/playwright/playwright.env index 6556b535a213..b94fac3f3589 100644 --- a/src/test/playwright/playwright.env +++ b/src/test/playwright/playwright.env @@ -7,7 +7,7 @@ STUDENT_GROUP_NAME=students TUTOR_GROUP_NAME=tutors EDITOR_GROUP_NAME=editors INSTRUCTOR_GROUP_NAME=instructors -BASE_URL=http://localhost:8080 +BASE_URL=http://localhost:9000 EXERCISE_REPO_DIRECTORY=test-exercise-repos FAST_TEST_TIMEOUT_SECONDS=45 SLOW_TEST_TIMEOUT_SECONDS=180 diff --git a/supporting_scripts/course-scripts/quick-course-setup/create_users.py b/supporting_scripts/course-scripts/quick-course-setup/create_users.py index 56921ee022a0..2e702db2e92a 100644 --- a/supporting_scripts/course-scripts/quick-course-setup/create_users.py +++ b/supporting_scripts/course-scripts/quick-course-setup/create_users.py @@ -13,7 +13,6 @@ config.read('config.ini') # Constants from config file -SERVER_URL: str = config.get('Settings', 'server_url') CLIENT_URL: str = config.get('Settings', 'client_url') MAX_THREADS: int = int(config.get('Settings', 'max_threads')) @@ -22,7 +21,7 @@ def make_create_user_post_request(session: Session, user_details: dict) -> None: """Send a POST request to create a user.""" - url = f"{SERVER_URL}/admin/users" + url = f"{CLIENT_URL}/admin/users" headers = {"Content-Type": "application/json"} response = session.post(url, json=user_details, headers=headers) From f73eaf838673638c2fec4f0c13b479e435c23431 Mon Sep 17 00:00:00 2001 From: entholzer Date: Wed, 4 Dec 2024 19:44:24 +0100 Subject: [PATCH 07/19] simplify setup scripts --- docs/dev/playwright.rst | 10 ++--- src/test/playwright/package.json | 1 - supporting_scripts/playwright/README.md | 27 ++++++++++++++ .../playwright/runArtemisInDocker_linux.sh | 31 ++++++++++++++++ .../playwright/runArtemisInDocker_macOS.sh | 37 +++++++++++++++++++ .../playwright/setupUsers.sh | 4 +- .../playwright/startPlaywright.sh | 16 ++++++++ 7 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 supporting_scripts/playwright/README.md create mode 100755 supporting_scripts/playwright/runArtemisInDocker_linux.sh create mode 100755 supporting_scripts/playwright/runArtemisInDocker_macOS.sh rename src/test/playwright/init/initialize_users.sh => supporting_scripts/playwright/setupUsers.sh (79%) mode change 100644 => 100755 create mode 100755 supporting_scripts/playwright/startPlaywright.sh diff --git a/docs/dev/playwright.rst b/docs/dev/playwright.rst index 2259a9a52ec1..b8844775edfe 100644 --- a/docs/dev/playwright.rst +++ b/docs/dev/playwright.rst @@ -51,15 +51,15 @@ Playwright tests rely on the Playwright Node.js library, browser binaries, and s 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, or simply run: + `supportingScripts/playwright`: .. code-block:: bash - npm run playwright:setup-users + 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. + 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: diff --git a/src/test/playwright/package.json b/src/test/playwright/package.json index 23ddfbc4be40..4dd82f3ce01d 100644 --- a/src/test/playwright/package.json +++ b/src/test/playwright/package.json @@ -20,7 +20,6 @@ "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:install": "npx playwright install --with-deps chromium", - "playwright:setup-users": "/bin/sh init/initialize_users.sh", "merge-reports": "junit-merge ./test-reports/results-parallel.xml ./test-reports/results-sequential.xml -o ./test-reports/results.xml", "update": "ncu -i --format group" } diff --git a/supporting_scripts/playwright/README.md b/supporting_scripts/playwright/README.md new file mode 100644 index 000000000000..c8f1f1912d6d --- /dev/null +++ b/supporting_scripts/playwright/README.md @@ -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. + diff --git a/supporting_scripts/playwright/runArtemisInDocker_linux.sh b/supporting_scripts/playwright/runArtemisInDocker_linux.sh new file mode 100755 index 000000000000..a9ccb4bf0ff8 --- /dev/null +++ b/supporting_scripts/playwright/runArtemisInDocker_linux.sh @@ -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 + +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 diff --git a/supporting_scripts/playwright/runArtemisInDocker_macOS.sh b/supporting_scripts/playwright/runArtemisInDocker_macOS.sh new file mode 100755 index 000000000000..b9db7b3ffdc8 --- /dev/null +++ b/supporting_scripts/playwright/runArtemisInDocker_macOS.sh @@ -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 + +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 + +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 diff --git a/src/test/playwright/init/initialize_users.sh b/supporting_scripts/playwright/setupUsers.sh old mode 100644 new mode 100755 similarity index 79% rename from src/test/playwright/init/initialize_users.sh rename to supporting_scripts/playwright/setupUsers.sh index 163b01747d00..fb88d3638729 --- a/src/test/playwright/init/initialize_users.sh +++ b/supporting_scripts/playwright/setupUsers.sh @@ -4,7 +4,7 @@ set -e -cd ../../../supporting_scripts +cd .. if [ ! -d "venv" ]; then python -m venv venv @@ -16,5 +16,3 @@ cd course-scripts/quick-course-setup python3 -m pip install -r requirements.txt python3 create_users.py - -cd ../../../src/test/playwright diff --git a/supporting_scripts/playwright/startPlaywright.sh b/supporting_scripts/playwright/startPlaywright.sh new file mode 100755 index 000000000000..d97049b7ab13 --- /dev/null +++ b/supporting_scripts/playwright/startPlaywright.sh @@ -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 From 7973c1f7d7fa452e7059b746f591cbbb23916e34 Mon Sep 17 00:00:00 2001 From: entholzer Date: Wed, 4 Dec 2024 19:49:21 +0100 Subject: [PATCH 08/19] improve readme --- supporting_scripts/playwright/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supporting_scripts/playwright/README.md b/supporting_scripts/playwright/README.md index c8f1f1912d6d..955d4c8f5d40 100644 --- a/supporting_scripts/playwright/README.md +++ b/supporting_scripts/playwright/README.md @@ -24,4 +24,4 @@ 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`. From a9314524e7fd9f89b96bb38cac1a82eb8604f74e Mon Sep 17 00:00:00 2001 From: entholzer Date: Fri, 6 Dec 2024 17:41:03 +0100 Subject: [PATCH 09/19] replace placeholder --- src/test/playwright/playwright.env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/playwright/playwright.env b/src/test/playwright/playwright.env index b94fac3f3589..c91a46aa32de 100644 --- a/src/test/playwright/playwright.env +++ b/src/test/playwright/playwright.env @@ -1,5 +1,5 @@ -PLAYWRIGHT_USERNAME_TEMPLATE=artemis_test_user_ -PLAYWRIGHT_PASSWORD_TEMPLATE=artemis_test_user_ +PLAYWRIGHT_USERNAME_TEMPLATE=artemis_test_user_USERID +PLAYWRIGHT_PASSWORD_TEMPLATE=artemis_test_user_USERID ADMIN_USERNAME=artemis_admin ADMIN_PASSWORD=artemis_admin ALLOW_GROUP_CUSTOMIZATION=true From dbb16c742d597b5a5ca2cd616177bca14464b529 Mon Sep 17 00:00:00 2001 From: entholzer Date: Fri, 6 Dec 2024 17:50:05 +0100 Subject: [PATCH 10/19] undo --- src/test/playwright/playwright.env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/playwright/playwright.env b/src/test/playwright/playwright.env index c91a46aa32de..b94fac3f3589 100644 --- a/src/test/playwright/playwright.env +++ b/src/test/playwright/playwright.env @@ -1,5 +1,5 @@ -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 From 10d41156113998d1c144c36117df3ac7b2b3746b Mon Sep 17 00:00:00 2001 From: entholzer Date: Fri, 6 Dec 2024 19:38:58 +0100 Subject: [PATCH 11/19] simplify more --- .../config/application-local-template.yml | 30 ------------------- .../playwright/runArtemisInDocker_linux.sh | 9 ------ .../playwright/runArtemisInDocker_macOS.sh | 3 -- 3 files changed, 42 deletions(-) delete mode 100644 src/main/resources/config/application-local-template.yml diff --git a/src/main/resources/config/application-local-template.yml b/src/main/resources/config/application-local-template.yml deleted file mode 100644 index 401adf70dffd..000000000000 --- a/src/main/resources/config/application-local-template.yml +++ /dev/null @@ -1,30 +0,0 @@ -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 diff --git a/supporting_scripts/playwright/runArtemisInDocker_linux.sh b/supporting_scripts/playwright/runArtemisInDocker_linux.sh index a9ccb4bf0ff8..e5717dcbe0ff 100755 --- a/supporting_scripts/playwright/runArtemisInDocker_linux.sh +++ b/supporting_scripts/playwright/runArtemisInDocker_linux.sh @@ -4,19 +4,10 @@ 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 - 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 diff --git a/supporting_scripts/playwright/runArtemisInDocker_macOS.sh b/supporting_scripts/playwright/runArtemisInDocker_macOS.sh index b9db7b3ffdc8..3ecf921774bf 100755 --- a/supporting_scripts/playwright/runArtemisInDocker_macOS.sh +++ b/supporting_scripts/playwright/runArtemisInDocker_macOS.sh @@ -15,9 +15,6 @@ echo "Copied configuration" cd docker open -a Docker -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 From e988f2e88b46419aa45c4faf713c03ca5fc205b4 Mon Sep 17 00:00:00 2001 From: entholzer Date: Fri, 6 Dec 2024 19:54:53 +0100 Subject: [PATCH 12/19] improved docs --- docs/dev/playwright.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/dev/playwright.rst b/docs/dev/playwright.rst index b8844775edfe..d99219ef784b 100644 --- a/docs/dev/playwright.rst +++ b/docs/dev/playwright.rst @@ -7,6 +7,12 @@ 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. + +For a fast test setup with fewer 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. + +If you want to manually install playwright, you can follow these steps: 1. Install dependencies: @@ -50,8 +56,8 @@ Playwright tests rely on the Playwright Node.js library, browser binaries, and s 3. Configure test users 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`: + 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 From 7a8319289ea99ad25d402ada213b90d0f1cc3423 Mon Sep 17 00:00:00 2001 From: entholzer Date: Fri, 6 Dec 2024 19:55:48 +0100 Subject: [PATCH 13/19] remove configuration copy from macos setup --- supporting_scripts/playwright/runArtemisInDocker_macOS.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/supporting_scripts/playwright/runArtemisInDocker_macOS.sh b/supporting_scripts/playwright/runArtemisInDocker_macOS.sh index 3ecf921774bf..9c3210e158f1 100755 --- a/supporting_scripts/playwright/runArtemisInDocker_macOS.sh +++ b/supporting_scripts/playwright/runArtemisInDocker_macOS.sh @@ -4,14 +4,6 @@ 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 From 7ef91601cb6263337420fd9ddc5b7c8cfe8e6e2d Mon Sep 17 00:00:00 2001 From: entholzer Date: Fri, 6 Dec 2024 20:38:13 +0100 Subject: [PATCH 14/19] improved docs --- docs/dev/playwright.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/dev/playwright.rst b/docs/dev/playwright.rst index d99219ef784b..5486615a4db4 100644 --- a/docs/dev/playwright.rst +++ b/docs/dev/playwright.rst @@ -8,9 +8,15 @@ 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`. + + +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. -For a fast test setup with fewer 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. If you want to manually install playwright, you can follow these steps: From 0f1fb62a94de40786350ceea9d9c66027be9f864 Mon Sep 17 00:00:00 2001 From: entholzer Date: Fri, 6 Dec 2024 22:33:10 +0100 Subject: [PATCH 15/19] re-add import User file --- src/test/playwright/init/importUsers.spec.ts | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/playwright/init/importUsers.spec.ts diff --git a/src/test/playwright/init/importUsers.spec.ts b/src/test/playwright/init/importUsers.spec.ts new file mode 100644 index 000000000000..8ccf886c770b --- /dev/null +++ b/src/test/playwright/init/importUsers.spec.ts @@ -0,0 +1,29 @@ +import { test } from '../support/fixtures'; +import { admin, instructor, studentFour, studentOne, studentThree, studentTwo, tutor } from '../support/users'; +import { USER_ID, USER_ROLE, users } from '../support/users'; + +test.describe('Setup users', async () => { + if (process.env.CREATE_USERS == 'true') { + test.beforeEach('Creates all required users', async ({ login, userManagementAPIRequests }) => { + await login(admin); + for (const userKey in USER_ID) { + const user = users.getUserWithId(USER_ID[userKey]); + const getUserResponse = await userManagementAPIRequests.getUser(user.username); + if (!getUserResponse.ok()) { + await userManagementAPIRequests.createUser(user.username, user.password, USER_ROLE[userKey]); + } + } + }); + } + + test('Logs in once with all required users', async ({ login }) => { + // If Artemis hasn't imported the required users from Jira we have to force this by logging in with these users once + await login(admin); + await login(instructor); + await login(tutor); + await login(studentOne); + await login(studentTwo); + await login(studentThree); + await login(studentFour); + }); +}); From 7700d30110dbeebd44189d98b4225ccaad42c39a Mon Sep 17 00:00:00 2001 From: entholzer Date: Fri, 6 Dec 2024 22:47:26 +0100 Subject: [PATCH 16/19] remove local profile --- docker/artemis/config/dev-local-vc-local-ci.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/artemis/config/dev-local-vc-local-ci.env b/docker/artemis/config/dev-local-vc-local-ci.env index a88d9ab0b21f..e9099fa60bd9 100644 --- a/docker/artemis/config/dev-local-vc-local-ci.env +++ b/docker/artemis/config/dev-local-vc-local-ci.env @@ -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,local +SPRING_PROFILES_ACTIVE: artemis,scheduling,localci,localvc,buildagent,core,dev,docker # Integrated Code Lifecycle settings with Jira ARTEMIS_USERMANAGEMENT_USEEXTERNAL="false" From 910395d1fdd75c6e3b6d2f46bf5e708e46627d4e Mon Sep 17 00:00:00 2001 From: entholzer Date: Fri, 6 Dec 2024 22:49:53 +0100 Subject: [PATCH 17/19] und package json change --- src/test/playwright/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/playwright/package.json b/src/test/playwright/package.json index 8077fa1988b7..eeac0766746c 100644 --- a/src/test/playwright/package.json +++ b/src/test/playwright/package.json @@ -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:install": "npx playwright install --with-deps chromium", + "playwright:setup": "npx playwright install --with-deps chromium && 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" } From b9ad82fb2017bafa0bfcf8acf4d31656d4616b32 Mon Sep 17 00:00:00 2001 From: entholzer Date: Sat, 7 Dec 2024 08:48:28 +0100 Subject: [PATCH 18/19] make package json work on bamboo and locally --- src/test/playwright/package.json | 1 + supporting_scripts/playwright/startPlaywright.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/playwright/package.json b/src/test/playwright/package.json index eeac0766746c..edf8f37cdfcd 100644 --- a/src/test/playwright/package.json +++ b/src/test/playwright/package.json @@ -20,6 +20,7 @@ "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", "merge-reports": "junit-merge ./test-reports/results-parallel.xml ./test-reports/results-sequential.xml -o ./test-reports/results.xml", "update": "ncu -i --format group" } diff --git a/supporting_scripts/playwright/startPlaywright.sh b/supporting_scripts/playwright/startPlaywright.sh index d97049b7ab13..aeaeb539b610 100755 --- a/supporting_scripts/playwright/startPlaywright.sh +++ b/supporting_scripts/playwright/startPlaywright.sh @@ -10,7 +10,7 @@ cd src/test/playwright npm install -npm run playwright:install || true +npm run playwright:setup-local || true echo "Starting Playwright in UI mode" npm run playwright:open From 35031cafd7e4215fed784b5f3bc12b68a16df3e7 Mon Sep 17 00:00:00 2001 From: entholzer Date: Sat, 7 Dec 2024 16:48:00 +0100 Subject: [PATCH 19/19] update docs --- docs/dev/playwright.rst | 4 +++- src/test/playwright/package.json | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/dev/playwright.rst b/docs/dev/playwright.rst index 5486615a4db4..c4edd85d5399 100644 --- a/docs/dev/playwright.rst +++ b/docs/dev/playwright.rst @@ -80,7 +80,9 @@ If you want to manually install playwright, you can follow these steps: .. code-block:: bash - npm run playwright:install + npm run playwright:setup-local + npm run playwright:init + 5. Open Playwright UI diff --git a/src/test/playwright/package.json b/src/test/playwright/package.json index edf8f37cdfcd..5e37ba3caba9 100644 --- a/src/test/playwright/package.json +++ b/src/test/playwright/package.json @@ -21,6 +21,7 @@ "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" }