Creating And Running WebDriver Test Suit Using testng.xml File

Creating And Running WebDriver Test Suit Using testng.xml File

Creating testng.xml File

To create testng.xml file, Right click on project folder and Go to New -> File ->testng.xml

In above testng.xml code,

: suite tag defines the TestNG suite. You can give any name to your suite using 'name' attribute. In above given example, We have given "Suite One" to our test suite.

: test tag defines the TestNG test. You can give any name to your test using 'name' attribute. In above given example, We have given "Test One" to our test

. : classes tag defines multiple class. We can multiple test class under classes tag. In our example we have only one class.

: class tag defines the class name which you wants to consider in test execution. In above given example, we have defined name="TestNGOne.ClassOne" where ' TestNGOne ' describes package name and 'ClassOne' describes class name.

Executing testng.xml File

To Run Right click on testng.xml file -> Run As -> Select TestNG Suite

Creating Single Or Multiple Tests For Multiple Classes In WebDriver

First of all, Create 3 classes under project = TestNGOne and package = TestNGTest as bellow.

"BaseClass" will be used for initializing and closing webdriver instance,

"ClassOne" and "ClassTwo" will be used as test classes.

BaseClass.java

ClassOne.java

ClassTwo.java

Configure testng.xml to run two classes in one test

Configure testng.xml to run two classes in two tests

Creating Test Suite Using Class From Different Packages

Testng.xml

Including Only Selected Test Method

Include only specific package in test suite from multiple packages

Exclude specific package in test suite from multiple packages

We are defining two attributes 'parallel' and 'thread-count' at suite level. As we want test methods to be executed in parallel, we have provided 'methods'. And 'thread-count' attribute is to use to pass the number of maximum threads to be created.

Parallel Testing with multiple Browser

Testng.xml

OutPut

OutPut

Using dependsOnMethods Of TestNG In Selenium WebDriver Test Case

Dependency means if one @Test method fails or skipped from execution then its dependent @Test method must not be executed.

Testng.xml

Last updated