Add Selenium dependencies
First of all, add selenium dependencies to the pom.xml file:
Download gecko and chrome drivers
Implement Driver Manager
Create package client and package web inside. Then create class SeleniumDriverManager with the code below:
Method getFirefoxDriverName and getChromeDriverName returns driver name for the current OS, with o without .exe postfix.
Method setChromeDriverPath and setFirefoxDriverPath sets system property with path to the particular driver.
Drive properties initialization
If you use CI agents, parameters webdriver.chrome.driver and webdriver.gecko.driver can be already configured. Check agent description before using.
Let`s add drivers initialization code to the init method from TestInitialization class:
Add feature file
Add web subpackage to the features package and create duck_test.feature file:
This test will open duckduckgo site, perform search request and verify result.
Scenario Driver is initialized marked as Background and will be executed before each Scenario.
Add code below to the duck_test.feature:
Add glue code
Create WebSteps inside steps package and add code below:
Execute the tests
The final version of the execution tool after all manipulation is stored here:
As previously, open console and execute mvn clean test:
Great job! Check Article 4 and find how to implement API automated tests using RestAssured library!