Development

Driver Manager for Selenium Web Driver and Extent Reports

Using Selenium with Java and TestNG (2)

Driver Manager for Selenium Web Driver

This blog post explains how to initiate the Chrome and IE browsers using maven setup.

To run selenium web driver in chrome/IE browsers, download the preferred version of Chrome Driver/ IE Driver server for web driver and save it in local.

Now set the property for chrome driver/IE driver, specify its location via the webdriver.chrome.driver / webdriver.ie.driver as below

System.setProperty(“webdriver.chrome.driver”, “pathofchromedriver\\chromedriver.exe”);

Or

System.setProperty(“webdriver.ie.driver”, “pathofiedriver\\chromedriver.exe”);

If the path is not set or the path is wrong, below error will be thrown once the script is started.

Error: The path to the driver executable must be set by the webdriver.chrome.driver system property

In this example, all the dependencies in pom.xml are added by avoiding the above difficulties.

Steps to Implement

  1. Create a java project in the eclipse with the project structure as shown below

2. Create an DriverManager.java which includes two methods such as chromeTest() and internetTest().

3. Add all the maven dependencies in pom.xml file

a. testng dependencies

b. selenium dependencies

Covid 19
COVID-19: Digital Insights For Enterprise Action

Access Perficient’s latest insights into how you can leverage digital technologies to not only respond to the pandemic, but drive your operations forward and deliver experiences your customers need.

Get Informed

c. webdrivermanager dependencies

4. Run the project RunAs –> TestNG to observe the test is executed in Chrome and IE browsers successfully.

Extent Reports

While working with selenium automation testing, usually the frameworks like TestNG, JUnit are being used in combination with Java to report the result at the end of the test execution.

This example shows how to generate the reports using Extent Reports.

Below are the advantages of Extent Reports

  1. Test Execution results will be shown in the form of PIE chart
  2. It can generate online or offline reports
  3. It can change the test method name in the report
  4. It can generate stepwise log information in the report
  5. It can segregate the tests using Test Categories.
  6. It can insert any custom HTML in the logs by using an HTML tag
  7. It can add recording of test runs in the report
  8. Generate Step summary.
  9. It can filter reports depends on status.
  10. It provides execution history.
  11. It fetches system details like OS, Java Version, and Memory and so on.

Steps to Implement

  1. Create a java project in the eclipse with the project structure as shown below

2. Create an ExtentBlog.java which include the method test() .

  • Create an instance for ExtentReports
    • ExtentReports exReport;
  • Inside the test() method, create a local path to save this report.
    • String extentReport = “D:\\Extent\\extent.html”;
  • Adding a test to the report
    • exReport = new ExtentReports(extentReport, true);
    • extentReport is a file-path
    • marked replace existing report as true
  • Now create a new instance of ExtentTest to start the tests.In this example, test name is “My First Test”
    • ExtentTest extest = startTest(“My First Test”);
  • Initiate the chrome browser by maven setup
    • getInstance().setup();
    • driver = new ChromeDriver();
  • End the test
    • endTest(extest);

3. Create a pom.xml file which includes all the maven dependencies

a. testng dependencies

b. selenium dependencies

c. extentreports dependencies

d. webdrivermanager dependencies

4. Run the project RunAs –> TestNG to observe the reports generated in the path specified.

Screenshot displayed below is the stepwise log information report

The reports of fail status, error status, fatal status, warning status can also be generated.

Depending on the Pass, Fail, Info, Warning and Error status, result report shows with different colored annotations for quick look.

In dashboard view report, the environment details, total tests run, total steps generated, Total time taken to run the test, Test view pie chart, Step view pie chart as well as pass percentage can be generated.

About the Author

More from this Author

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to the Weekly Blog Digest:

Sign Up
Categories