This project demonstrates running a Selenium test in a Docker container using Python and Chrome in headless mode. The test script opens Google, prints the page title, and saves a screenshot.
test.py: Selenium test script.Dockerfile: Builds the Docker image with Chrome, ChromeDriver, and Python dependencies.requirements.txt: Python dependencies..vscode/tasks.json: VS Code tasks for building and running the Docker container..env: Environment variables for the container./screenshots: Directory for storing screenshots (created automatically).
- Docker installed
- Visual Studio Code (optional, for integrated tasks)
docker build --pull --no-cache -t selenium-app .mkdir -p ./screenshots && chmod 777 ./screenshotsdocker run --rm -v $(pwd)/screenshots:/screenshots --env-file .env selenium-appAlternatively, use VS Code tasks:
- Docker Build: Builds the image.
- Prepare Screenshots Folder: Creates and sets permissions for the screenshots directory.
- Docker Run: Runs the test and saves the screenshot to
./screenshots/google.png.
- The script prints the page title to the console.
- Screenshot is saved to
./screenshots/google.png.
- Modify
test.pyto change the test logic or target URL. - Add environment variables to
.envas needed.