0% found this document useful (0 votes)
105 views6 pages

Playwright With Docker

Playwright

Uploaded by

gsndharavkatyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views6 pages

Playwright With Docker

Playwright

Uploaded by

gsndharavkatyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

https://www.linkedin.

com/in/sonumadheshiya/
https://www.linkedin.com/in/sonumadheshiya/

Playwright : Mastering the Essentials - Part 7

Running Playwright Tests in Docker :

This document will guide you through building a Docker image for your Playwright tests,
creating a container from that image, and running your tests inside the container.

1. Create a Dockerfile

Create a Dockerfile in the root directory of your Playwright project.

Dockerfile Example:

2. Build the Docker Image

Once your Dockerfile is ready, build the Docker image. This image will contain all the
necessary dependencies to run Playwright tests.
https://www.linkedin.com/in/sonumadheshiya/

Command to Build the Image:

• -t sonu-playwright : Tags the image with the name sonu-playwright.


• . : Specifies the current directory as the build context.

Running Command to Build the Image :

3. Check Docker Images:

After building the image, verify that it has been created:

Lists all Docker images, including sonu-playwright.

4. Run a Container from the Image

Create and run a container from the sonu-playwright image.

Command to Run the Container:


https://www.linkedin.com/in/sonumadheshiya/

• -it : Runs the container interactively with a terminal attached.

• --name sonu-playwright-container : Names the container sonu-playwright-


container.

• sonu-playwright : The name of the Docker image to use for the container.

Result After Command to Run the Container:

5. Check Docker Containers:

After running the container, check the status of all containers:

Lists all Docker containers, including sonu-playwright-container, and their statuses (running,
stopped, etc.).

6. View Test Results

The Playwright tests will execute inside the container, and the results will be displayed in
your terminal.
https://www.linkedin.com/in/sonumadheshiya/

7. Accessing the Container (Optional)

If you need to access the container’s shell:

Command to Access the Container:

/bin/bash: Opens a Bash shell in the container, overriding the Dockerfile’s CMD.

8. Stopping and Removing the Container

After running your tests, you can stop and remove the container.

Command to Stop the Container:

Command to Remove the Container:

9. Clean Up Docker Resources

Command to Remove the Image:

• sonu-playwright: The name of the Docker image to remove.

Command to Remove All Stopped Containers:


https://www.linkedin.com/in/sonumadheshiya/

Summary of Commands:

• Build the Image: docker build -t sonu-playwright .


• Check Images: docker images
• Run the Container: docker run -it --name sonu-playwright-container sonu-playwright
• Check Containers: docker ps -a
• Stop the Container: docker stop sonu-playwright-container
• Remove the Container: docker rm sonu-playwright-container
• Remove the Image: docker rmi sonu-playwright

Stay tuned with Sonu Madheshiya on LinkedIn for more interesting content
on automation testing.

You might also like