This project aims to enable the execution of test runners (Selenium, RestAssured, and experimentally Playwright) through Docker. The solution consists of a docker-compose setup capable of running tests defined in Gherkin without additional dependencies, providing high portability and ease of use.
- Docker
- Docker Compose
docker-compose.yaml
: Docker Compose configuration file to set up Selenium Grid, Chrome and Firefox nodes, and Allure reporting service.src/test/java
: Directory containing your test classes and test suite XML file.
flowchart TD
subgraph DockerEcosystem [Docker Ecosystem]
subgraph TestRunner [Maven]
A[Test Runner]:::runner -->|Executes| B[mvn test]:::command
B -->|Locally uses| H[WebDriverManager]:::local-drivers
end
B -->|Send test execution to| C[Selenium Hub]:::hub
C -->|Communicates via Event Bus| D[Chrome Node]:::node
C -->|Communicates via Event Bus| E[Firefox Node]:::node
B -->|Sends test results To| F[Allure Service]:::allure
end
classDef runner fill:#696262, stroke:#d94a4a;
classDef command fill:#222922, stroke:#4ad94a;
classDef hub fill:#222222, stroke:#4a4ad9;
classDef node fill:#333333, stroke:#d94ad9;
classDef allure fill:#414141, stroke:#d9d94a;
classDef local-drivers fill:#323939, stroke:#4ad9d9;
class A runner;
class B command;
class C hub;
class D node;
class E node;
class F allure;
class H local-drivers;
%% Posizionamento verticale
style TestRunner stroke-width:3px;
style DockerEcosystem stroke-width:4px;
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Build and start the services:
docker-compose up --build
-
Run your test:
docker-compose up --no-deps test-runner
There are two general usage modes for running tests:
- Virtualized Execution:
Browser nodes are instantiated in Docker containers, and the tests are executed using Maven inside a docker container.
The test-runner service in the docker-compose.yaml file is configured to run your tests using Maven. It will execute the tests defined in the src/test/java/runners/runner.xml file.
docker-compose up --build
docker-compose up command will build the Docker images declared on docker-compose.yaml and start the Selenium Grid, Chrome and Firefox nodes, and Allure reporting service.
The test-runner service will be started, and the tests will be executed.
After the tests have been executed, you can view the Allure report by navigating to http://localhost:4040 in your web browser.
If you want to run the tests again, you can use the following command:
docker-compose up --no-deps test-runner
Browser type can be specified by setting the BROWSER environment variable in the docker-compose.yaml file.
- Local Execution: Browser nodes are instantiated locally, and the tests are executed using Maven.
mvn clean test -DsuiteXmlFile=src/test/java/runners/runner.xml
If the -DsuiteXmlFile parameter is not specified, all tests will be executed.
Browser type can be specified by editing the hardcoded string on steps/cucumber/Step.java:26
After the tests have been executed, you can view the Allure report by navigating to http://localhost:4040 in your web browser.
Selenium Hub: The central component of Selenium Grid.
Chrome and Firefox Nodes: Browser nodes that connect to the Selenium Hub.
Test Runner: A Maven container that runs the tests.
Allure: A service to generate and serve Allure reports.
Volumes: The docker-compose.yaml file includes volumes for allure-results and allure-reports to store test results and reports.
Plugins: The pom.xml file includes the maven-cucumber-reporting plugin to generate Cucumber HTML reports.
Environment Variables: The docker-compose.yaml file sets environment variables for the browser and Selenium Hub host.
TestNG Configuration: The src/test/java/runners/runner.xml file configures TestNG with Allure reporting.
Screenshot Utility: The project includes a ScreenshotUtil class to capture screenshots on test failure.
In addition to Selenium and RestAssured, it is also possible to run tests using an experimental runner for Playwright. This allows for cross-browser testing with a modern automation framework.