From 751dbc5ae41eb29c4a4dd1c86ae47abc744d5028 Mon Sep 17 00:00:00 2001 From: Jeroen van der Meulen Date: Wed, 12 Jun 2024 10:33:17 +0200 Subject: [PATCH 1/3] Add README and shell scripts --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++++- inspector/start.sh | 8 +++++++ runner/build/build.sh | 7 ++++++ runner/start.sh | 7 ++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100755 inspector/start.sh create mode 100755 runner/build/build.sh create mode 100755 runner/start.sh diff --git a/README.md b/README.md index 76be70f..216cf22 100644 --- a/README.md +++ b/README.md @@ -1 +1,55 @@ -# test_automation_setup \ No newline at end of file +# test_automation_setup + +This repository contains a challenge to help you start learning about automation testing concepts and test development using [Playwright](https://playwright.dev/). + +The goal for this challenge is to get you familiar with developing test cases in Playwright. +One of the key objectives is to facilitate the onboarding process for team members joining the testing team. +It also helps to share the team knowledge with stakeholders involved in the same testing project. + +This challenge is open to anyone with basic IT knowledge, regardless of whether they have prior experience in testing. + +## Environment + +1. **Inspector**: This is a container that includes the Playwright packages required to run a web browser and the inspector tool for creating the tests. +2. **Runner**: This is a container that will run the tests you have made with the inspector tool. It will run them from a volume mount at `/mount/test_run.py` + +## Getting Started + +To get started with this challenge, you need to have the below prerequisites: + +- Visual Studio Code (VSCode) +- Docker or Podman packages equivalent. + +Once you have these prerequisites, you can clone this repository and start the containers with the following steps. + +1. Start the inspector container with start.bat on Windows or start.sh on Linux in the `/inspector` directory. +2. Build the runner Dockerfile with build.bat on Windows or build.sh on Linux in the `/runner/build` directory. + +## Challenge + +1. Start recording all steps within the browser by pressing "record" in the inspector tool window +2. Go to the application in the browser window that has opened +3. Go through the application test scenario step by step +4. Copy the code that the inspector generated and paste it in the test_run.py file in /mount +5. Run the runner container with start.bat on Windows or start.sh on Linux + +## Instructions + +## Conclusion + +By participating in this hands-on experience, you have gained knowledge in how to interact with the playwright automation test suite. + +## Troubleshooting F.A.Q + +### Windows + +### Linux + +```sh + [pid=29][err] Authorization required, but no authorization protocol specified + - [pid=29][err] [29:29:0607/122015.501614:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY + - [pid=29][err] [29:29:0607/122015.501625:ERROR:env.cc(258)] The platform failed to initialize. Exiting. +``` + +xhost local:docker +xhost + \ No newline at end of file diff --git a/inspector/start.sh b/inspector/start.sh new file mode 100755 index 0000000..d89bfa1 --- /dev/null +++ b/inspector/start.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +docker run --rm --name inspector \ + --privileged \ + -v /dev/shm:/dev/shm \ + -v /tmp/.X11-unix/:/tmp/.X11-unix/ \ + -e DISPLAY=unix$DISPLAY \ + mcr.microsoft.com/playwright:v1.44.1 npx -y playwright open google.com diff --git a/runner/build/build.sh b/runner/build/build.sh new file mode 100755 index 0000000..602a878 --- /dev/null +++ b/runner/build/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo starting build.... + +docker build . -t runner:playwright + +echo build finished \ No newline at end of file diff --git a/runner/start.sh b/runner/start.sh new file mode 100755 index 0000000..8eaab69 --- /dev/null +++ b/runner/start.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +docker run --rm --name runner \ + -e DISPLAY=:0 \ + -v /tmp/.X11-unix:/tmp/.X11-unix \ + -v "$PWD"/mount:/test \ + runner:playwright \ No newline at end of file From c2a85bf5f7e9c96b39ba19a9846cda24a0543e93 Mon Sep 17 00:00:00 2001 From: alandevoteam Date: Mon, 24 Jun 2024 11:00:13 +0200 Subject: [PATCH 2/3] Improved test_python --- READMEv2.MD | 58 ++++++++++++++++++++++++++++++++++++++++ runner/mount/test_run.py | 30 ++++++++++++++------- test_run_concept.py | 17 ++++++++++++ 3 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 READMEv2.MD create mode 100644 test_run_concept.py diff --git a/READMEv2.MD b/READMEv2.MD new file mode 100644 index 0000000..250dc73 --- /dev/null +++ b/READMEv2.MD @@ -0,0 +1,58 @@ +# test_automation_setup + +This repository contains a challenge to help you start learning about automation testing concepts and test development using [Playwright](https://playwright.dev/). + +The goal for this challenge is to get you familiar with developing test cases in Playwright. +One of the key objectives is to facilitate the onboarding process for team members joining the testing team. +It also helps to share the team knowledge with stakeholders involved in the same testing project. + +This challenge is open to anyone with basic IT knowledge, regardless of whether they have prior experience in testing. + +## Environment + +1. **Inspector**: This is a container that includes the Playwright packages required to run a web browser and the inspector tool for creating the tests. +2. **Runner**: This is a container that will run the tests you have made with the inspector tool. It will run them from a volume mount at `/mount/test_run.py` + +## Getting Started + +To get started with this challenge, you need to have the below prerequisites: + +- Visual Studio Code (VSCode) +- Docker or Podman packages equivalent. + +Once you have these prerequisites, you can clone this repository and start the containers with the following steps. + +1. Start the inspector container by executing start.bat (for Windows) or start.sh (for Linux) in the terminal. These files are located in the /inspector directory and contain the commands to start the inspector container. +2. Build the runner Dockerfile by executing build.bat (for Windows) or build.sh (for Linux) in the terminal or command line. These files are located in the /runner/build directory and contain the commands to build the runner Dockerfile. + +**Note**: `.bat` and `.sh` files are script files used to automate tasks in Windows and Linux systems respectively. They contain a series of command line instructions that are executed sequentially. Whenever you see these files mentioned in the instructions, remember that they are used to automate a series of command line tasks that can be kicked off in the terminal. + +## Challenge + +In this workshop, the challenge is to create and execute an automated browser test using Playwright, including API interactions. Participants will record, script, and run a test scenario, validating their ability to automate web application testing effectively. + +## Instructions + +1. **Record Steps**: Start by recording all the steps within the browser using the "record" feature in the Playwright's inspector tool window. +2. **Navigate and Interact**: Proceed to the web application in the newly opened browser window and interact with it according to the test scenario you want to automate. Stop the recording once you've finished navigating. +3. **Generate and Copy Code**: The inspector tool will generate code corresponding to your interactions. Copy this code and paste it into the `test_run.py` file located in the `/mount` directory. +4. **Run Test**: Finally, run the test scenario by executing the runner container using `start.bat` (for Windows) or `start.sh` (for Linux). + +## Conclusion + +By participating in this hands-on experience, you have gained knowledge in how to interact with the playwright automation test suite. + +## Troubleshooting F.A.Q + +### Windows + +### Linux + +```sh + [pid=29][err] Authorization required, but no authorization protocol specified + - [pid=29][err] [29:29:0607/122015.501614:ERROR:ozone_platform_x11.cc(244)] Missing X server or $DISPLAY + - [pid=29][err] [29:29:0607/122015.501625:ERROR:env.cc(258)] The platform failed to initialize. Exiting. +``` + +xhost local:docker +xhost + diff --git a/runner/mount/test_run.py b/runner/mount/test_run.py index 6497217..499a0d0 100644 --- a/runner/mount/test_run.py +++ b/runner/mount/test_run.py @@ -3,12 +3,24 @@ def test_example(page: Page) -> None: - page.goto("https://myprivacy.dpgmedia.nl/consent?siteKey=ucf98legs1caotgh&callbackUrl=https%3A%2F%2Fwww.nu.nl%2Fprivacy-gate%2Faccept%3FredirectUri%3D%252F") - page.frame_locator("iframe[title=\"SP Consent Message\"]").get_by_label("Akkoord").click() - page.get_by_label("sluit venster").click() - page.get_by_role("link", name="Astronomen zijn erachter").first.click() - page.get_by_label("Hoofdnavigatie").get_by_label("Sport").click() - page.get_by_role("link", name="Barcelona-trainer Xavi").first.click() - with page.expect_popup() as page1_info: - page.get_by_alt_text("Barcelona-trainer Xavi").click() - page1 = page1_info.value + page.goto("https://menzis.nl/zorgvinder") + # page.get_by_role("button", name="Accept All Cookies").click() + import time + time.sleep(3) + page.get_by_placeholder("Bijvoorbeeld: Fysiotherapie").click() + time.sleep(2) + page.get_by_placeholder("Bijvoorbeeld: Fysiotherapie").fill("Ziekenhuis") + # Simuleer een spatie + page.keyboard.press("Space") + time.sleep(2) # even wachten om ervoor te zorgen dat het effect heeft + page.get_by_text("Ziekenhuis / ZBC").click() + time.sleep(3) + page.get_by_placeholder("Postcode of woonplaats").click() + page.get_by_placeholder("Postcode of woonplaats").fill("Bedum") + # Simuleer een spatie + page.keyboard.press("Space") + time.sleep(2) # even wachten om ervoor te zorgen dat het effect heeft + page.get_by_text("Bedum").click() + page.get_by_role("combobox").select_option("50") + page.get_by_role("button", name="Zoeken").click() + time.sleep(3) diff --git a/test_run_concept.py b/test_run_concept.py new file mode 100644 index 0000000..0f2db1e --- /dev/null +++ b/test_run_concept.py @@ -0,0 +1,17 @@ +import re +from playwright.sync_api import Page, expect + + +def test_example(page: Page) -> None: + page.goto("https://zorgvinder.menzis.nl/") + page.get_by_placeholder("Bijvoorbeeld: Fysiotherapie").click() + page.get_by_placeholder("Bijvoorbeeld: Fysiotherapie").fill("Ziekenhuis") + page.get_by_placeholder("Bijvoorbeeld: Fysiotherapie").press('Space') # Simuleer een spatiebalkdruk + page.wait_for_selector('text="Ziekenhuis / ZBC"') # Wacht tot de tekst "Ziekenhuis / ZBC" zichtbaar is + page.get_by_text("Ziekenhuis / ZBC").click() + page.get_by_placeholder("Postcode of woonplaats").click() + page.get_by_placeholder("Postcode of woonplaats").fill("Bedum") + page.get_by_placeholder("Postcode of woonplaats").press('Space') # Simuleer een spatiebalkdruk + page.get_by_text("Bedum").click() + page.get_by_role("combobox").select_option("50") + page.get_by_role("button", name="Zoeken").click() From 03bff0723c20bea899ab4168b6b4541eb97693e3 Mon Sep 17 00:00:00 2001 From: TvO Date: Mon, 24 Jun 2024 11:29:40 +0200 Subject: [PATCH 3/3] nieuwe oplevering --- tim.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 tim.txt diff --git a/tim.txt b/tim.txt new file mode 100644 index 0000000..95d09f2 --- /dev/null +++ b/tim.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file