Please install below tools to use this framework
Below libraries are used to automate the web browsers
- TestNG - a testing framework used to write selenium tests.
- Selenium WebDriver - automated a browser locally, as a real user would experience or on remote machines using selenium grid.
- WebDriverManager - a library to download drivers for chrome or firefox.
- Faker - a library to generate random data
You can run either default , qa or remote profiles. The default runs on the properties defined in application.properties, qa will run on the properties defined in application-qa.properties, remote is used to run tests on Selenium Grid.
For the default profile you just need to execute mvn test task.
mvn clean test -Dfile=testng.xml
To execute the qa profile the environment variable -Dspring.profiles.active should be set. The following command line should be used:
mvn clean test -Dspring.profiles.active=qa -Dfile=testng.xml
If you don't pass any browser name property in application.properties or via commandline , by default tests will be launched in Chrome. If you want to execute the tests on any other browser of you choice say Firefox, all you need to do is change the browser property in application.properties or application-*.properties. Same thing can be achieved via command line(I prefer to do in this way) by running the below command
mvn clean test -Dspring.prilfes.active=qa -Dbrowser=chromeheadless -Dfile=testng.mxl
- chrome
- chromeheadless
- firefox
- firefoxheadless
Framework is designed to handle the parallel execution on browsers. Parallel execution can be enabled by introducing parallel="tests" and thread-count=2 for suite tag of testng.xml. thread-count property is configurable. You can set the value according to your need.
Know more about TestNG parallel execution here.
You can also execute the test scenarios through IntelliJ, VS Code or Eclpise.
To run the test locally on your machine
- Right click on the test class file from tests folder under test package and click on
Run as TestNG class in eclipseorRun in IntelliJ. - Right-click on
testng.xmlfile and click run.
To run testst remotely(selenium grid)
- Go to root directory of the framework (make sure
Dcokerfile is in root directory) and build the image by running command
docker build -t dragon12/springboot-selenium .
- Now Start the
selenium gridin background by running command
docker-compose up -d selenium-hub chrome firefox
- Now run the below command to execute our tests on docker container
echo "PROFILE=remote" > .env && docker-compose up rune2e
docker-compose up -d --scale firefox=2 --scale chrome=2
Run the below command to bring the selenium hub down
docker-compose down