Running Tests in Docker | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Advanced Tricks and Techniques
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore how to run Playwright tests in a Docker container . Using containers is advantageous for running tests in environments like CI/CD servers , as they preserve the necessary configuration for successful execution. Key Concepts Docker Overview : Docker allows running applications in isolated environments called containers, which are more lightweight than virtual machines . Installation : To use Docker, download Docker Desktop from docker.com and install it on your system (Mac, Windows, or Linux). Docker vs. Virtual Machines : Unlike virtual machines that allocate fixed resources, Docker containers use host resources on demand, making them more efficient. Setting Up Playwright in Docker To run Playwright tests in Docker: Create a Dockerfile in your project root. Specify a base image recommended by Playwright. Create a working directory and copy project files into the container. Install dependencies using npm install and npx playwright install . Build the Docker image using docker build -t your_image_name . . Running Tests To execute tests inside the container: docker run -it your_image_name After running the tests, reports are generated inside the container. To access them on the host machine, use a docker-compose.yaml file to define services and volumes for report extraction. Conclusion Docker simplifies running tests in isolated environments, ensuring consistency across different systems. By creating a Dockerfile and a docker-compose file, you can effectively manage dependencies and test execution.