Selenium Grid is the best way to run your Selenium based tests as Dockerized and parallel with wide range browser choice.Selenium Grid based on with Hub-Node concept.The one hub as a main machine creates one or one more node and runs test on these nodes.With that simply Selenium Hub provides you
- Central entry point for all tests
- Management and control of the nodes / environment where the browsers run
- Running tests in parallel
- Cross platform testing
- Load balancing
To run our tests with Selenium Grid we need to some dependencies on our maven project.
On our test we need to use RemoteWebDriver instead of WebDriver.And we can do it simply adding WebDriverManager in our “pom.xml”.WebDrivermanager is a library which allows to automate the management of the drivers required by Selenium WebDriver.
Our code will be like this on the Setup.
To setup our dockerized environment , we can use Dockerfile on our system.Below example we have a hub with port 4444 and nodes of these hub via Chrome node and Firefox node.These all nodes had their ports also.Save the below lines on your root path as a “Dockerfile.yaml”.
The simple command will create all of nodes and hub for us.
docker-compose up -d
And to connect and run our tests on the hub , simply we can create test sets named as “Chrome” and “Firefox”.With that we can classify which tests will run on which browser we wanted.Our testng.xml file will be like.
If you done everything correctly your test will run with this command
mvn clean test -Dmaven.repo.local=.m2/repository