> For the complete documentation index, see [llms.txt](https://gyansetu-selenium.gitbook.io/selenium-testing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-selenium.gitbook.io/selenium-testing/creating-and-running-webdriver-test-suit-using-testng.xml-file.md).

# Creating And Running WebDriver Test Suit Using testng.xml File

#### &#x20;Creating And Running WebDriver Test Suit Using testng.xml File

&#x20;Creating testng.xml File&#x20;

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

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTl8R2K5DiNohD-tj-3%2Fimage.png?alt=media\&token=fb510c3d-c857-4cdb-9bd3-6ede7676c598)

#### &#x20;In above testng.xml code,

&#x20;: **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.

&#x20;: **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.

&#x20;: 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.&#x20;

#### Executing testng.xml File&#x20;

To Run\
&#x20;Right click on testng.xml file -> Run As -> Select TestNG Suite&#x20;

#### Creating Single Or Multiple Tests For Multiple Classes In WebDriver&#x20;

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

&#x20;"**BaseClass**" will be used for initializing and closing webdriver instance,

&#x20;"**ClassOne**" and "ClassTwo" will be used as test classes.

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTl9Grc9QnhFqSF5LcT%2Fimage.png?alt=media\&token=88c38026-a12e-4329-893f-735bc1b247b5)

#### &#x20;BaseClass.java

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTl9NQJPtNHFZON3eE_%2Fimage.png?alt=media\&token=eaae145b-e181-4dfc-b7d1-3cc32fa6cda9)

#### &#x20;ClassOne.java

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTl9TGXqlPm2yuHeed5%2Fimage.png?alt=media\&token=5830ef8a-9503-4659-a0db-9f0a923dbcd7)

#### &#x20;ClassTwo.java

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTl9Z7c_bCjXdNqPIxc%2Fimage.png?alt=media\&token=33a98aca-af55-41c2-979e-0a5caa2eb81b)

#### &#x20;Configure testng.xml to run two classes in one test

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTl9eBBmFgrzIUECu9l%2Fimage.png?alt=media\&token=91c7c083-9903-4012-86a4-c56ad6ddb9e3)

#### &#x20;Configure testng.xml to run two classes in two tests

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTl9kDWioAF2P5zCl4W%2Fimage.png?alt=media\&token=1644ad9d-fb62-4896-af13-3b9db8b9cd0b)

#### &#x20;Creating Test Suite Using Class From Different Packages

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTl9rof2YtbI0jX08Ao%2Fimage.png?alt=media\&token=8e66f61a-72a2-4e97-9e94-c1442ec31c80)

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTl9uyQUCv-qOVYCZ0c%2Fimage.png?alt=media\&token=d3533660-252e-48c8-a2d3-c35f983f216a)

#### &#x20;Testng.xml

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlA6ozhRPqwjnLkgNy%2Fimage.png?alt=media\&token=07d2408a-e437-48fb-8c5e-89a7b12a4975)

#### &#x20;Including Only Selected Test Method

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlAEng3P5Ko9uHUVDF%2Fimage.png?alt=media\&token=9c08833c-0e0c-445c-bf9d-2d4a583c5dee)

#### &#x20;Include only specific package in test suite from multiple packages

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlAOMLSg2ylzGL6jiF%2Fimage.png?alt=media\&token=c197958a-d1c1-4d8b-8552-f3d17ba94d93)

#### &#x20;Exclude specific package in test suite from multiple packages

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlAVPmPoz2eVwlo2xF%2Fimage.png?alt=media\&token=5c88e960-12e5-4f3e-b588-ec0f08844cad)

&#x20;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.

#### &#x20;Parallel Testing with multiple Browser

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlAjmOmRhblHBeA81n%2Fimage.png?alt=media\&token=7efb5cc4-d45b-48a3-b4dc-75bfd9dc6955)

#### &#x20;Testng.xml

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlAuCz8Wque7roWTKf%2Fimage.png?alt=media\&token=853f4962-a19f-40b9-8208-1cce68eb7c33)

#### &#x20;OutPut

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlB-3MZwXbKwD4P7-0%2Fimage.png?alt=media\&token=f9ded688-8dd0-48b7-a127-817c3b96ac56)

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlB5PpAap_T8g2lHX4%2Fimage.png?alt=media\&token=fa4aa7f7-16a9-476c-b403-e2a246443863)

#### &#x20;OutPut

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlBAUX3eDGGPzTKViU%2Fimage.png?alt=media\&token=7ca31da8-47f1-470e-8094-206549d76244)

#### &#x20;Using dependsOnMethods Of TestNG In Selenium WebDriver Test Case

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

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlBIVlww-mbnteqyZu%2Fimage.png?alt=media\&token=37a2980d-20a2-4d7d-a9ff-acde4e5f328d)

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlBMiYPbKOnkTAOUbJ%2Fimage.png?alt=media\&token=a43d035d-f642-44c0-bddf-7367d777b619)

#### &#x20;Testng.xml

![](https://106491783-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LTW0eWU2biq082hmKEn%2F-LTl85HQ_KSdtFivZWA7%2F-LTlBTBWICiHYGO4Oy5R%2Fimage.png?alt=media\&token=360c6270-3e28-49c7-8eb6-046abc80e103)
