Execute Selenium Tests with testng.xml

Once the test cases are written in the testScripts package, the next step is to execute them using TestNG. The testng.xml file is a configuration file provided by the TestNG framework, which allows you to define and organize test execution flexibly and powerfully.

Using testng.xml, you can 

     Group and prioritize test classes and methods
     Pass parameters to tests
     Include or exclude specific test cases
     Set parallel execution (if needed)

For more info about testng.xml, follow this URL: https://www.qafeast.com/java-testng/testng.xml

Create a testng.xml file in the root directory of the project and define the tests as shown in the example below.

Example testng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="SmokeSuite">
<test name="HomePage Test">
<classes>
<class name="testScripts.HomePageTests"/>
</classes>
</test>
<test name="TextBox Page Text">
<classes>
<class name="testScripts.TextBoxTests"/>
</classes>
</test>
</suite>


In testng.xml

<suite>: Defines a test suite. A suite can contain multiple tests.
<test>: Represents a group of test classes.
<classes>: Contains the list of fully qualified class names to be executed.

How to run the testng.xml file

From IDE: 

     Right-click on the testng.xml file
     Select the run option. 

From CMD: 

     Go the Directory, where testng.xml presents
     Run command mvn clean test

TestNG HTML Report

TestNG automatically generates HTML reports that provide insights of the test execution. You can find the report target > surefire-reports > Surefire suite > index.html

These reports help identify:

     Which test cases passed or failed
     The execution time for each test
     Any errors or exceptions thrown

You can also find emailable-report.html which is lightweight html report, testng-result,xml, which is xml report useful for CI/CD integration.

For advanced reporting, consider integrating third-party libraries like ExtentReports or Allure.

 

Related Tutorials

Related Questions






Read more