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

Alan #3

Open
wants to merge 4 commits into
base: main
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
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
# test_automation_setup
# 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 +
58 changes: 58 additions & 0 deletions READMEv2.MD
Original file line number Diff line number Diff line change
@@ -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 +
8 changes: 8 additions & 0 deletions inspector/start.sh
Original file line number Diff line number Diff line change
@@ -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.45.1 npx -y playwright open google.com
7 changes: 7 additions & 0 deletions runner/build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

echo starting build....

docker build . -t runner:playwright

echo build finished
30 changes: 21 additions & 9 deletions runner/mount/test_run.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import re
import time
from playwright.sync_api import Page, expect


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()
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)
7 changes: 7 additions & 0 deletions runner/start.sh
Original file line number Diff line number Diff line change
@@ -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