How to write Web automated tests — Selenium (3/7)
--
In this article we will add web automation tests to the previously created foundation. Detailed overview you can found at the previous article.
Code from this chapter can be found here.
Add Selenium dependencies
First of all, add selenium dependencies to the pom.xml file:
Download gecko and chrome drivers
Download chromedriver from here and geckodriver from here. Place all drivers in the drivers folder:
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!