This archetype generates a new Maven project that can be used as a start point to develop tests in Java with Selenium WebDriver and TestNG.
To create a project from this archetype:
mvn archetype:generate -DarchetypeGroupId=ru.stqa.selenium -DarchetypeArtifactId=webdriver-testng-archetype -DarchetypeVersion=4.0 -DgroupId=<mygroupId> -DartifactId=<myartifactId>
where mygroupId is a group id of the project you are creating, and myartifactId is an artifact id of the project you are creating.
The project follows the standard Maven structure, so all the tests go in the src/test/java folder. Tests should inherit from the TestNgTestBase class that performs common setup and teardown tasks. This class uses WebDriverFactory to manage drivers.
SampleTestNgTest class (in src/test/java) is an example of a test class for testing the homepage of a web application. In the setup method of this class, the PageFactory class is used
to help supporting the PageObjects pattern.
The project uses Maven profiles to set configuration parameters. There are three profile groups: 1) to specify a browser, 2) to specify the target application properties, 3) to specify Selenium Grid location.
For example, to run tests in Chrome on the localhost without grid use this profile set:
mvn -P chrome,localhost,nogrid test
Default profile set is firefox,localhost,nogrid
The target application URL and the grid location should be specifies in the pom.xml file in the corresponding profiles.
Driver capabilities can be tuned in the files src/test/resources/*.capabilities.
The environment use docker for create a environment and test your aplicação when you use localhost instance, The file docker-compose is a configuration of oficial image for create this environment:
Selenium-hub It's a management node of selenium, it will expose the port 444
selenium-node-firefox Its a node that contains only a client instance installed with firefox,it will expose the port 590- for to access via VNC
selenium-node-chrome Its a node that contains only a client instance installed with chrome ,it will expose the port 5901 for to access via VNC
docker-compose up
For the exemple works, we need first the docker and docker compose installed on enviroment.
Create a folder called 'projects'
mkdir projetcts
cd projetcts
Now we create a project called sample;
mvn archetype:generate -DarchetypeGroupId=ru.stqa.selenium -DarchetypeArtifactId=webdriver-testng-archetype -DarchetypeVersion=4.0 -DgroupId=com.webdriver -DartifactId=sample
For view the executation inside of docker Chrome
vncviewer localhost:5900 &
For view the executation inside of docker Firefox
vncviewer localhost:5901 &
References: