Friday, 15 August 2014

Configure testng.xml In Eclipse For Creating And Running WebDriver Test Suit Using testng.xml File



Usage Of testng.xml File

In TestNG framework, We need to create testng.xml file for below purpose

-> To create and handle multiple test classes.

-> we can configure our web test as per our needs in testng.xml file.

-> we can set dependency

-> include or exclude any method or any classes or any package.

-> Set Priority



Creating TestNG.xml file



1) For creating testNG.xml file, we need to right click on project -> New-> file -> open new file wizard

2) In New File wizard select project and give file name as "TestNG.xml" and then click Finish button.

3) It will add TestNG.xml file under our current project.

4) Then add below lines in TestNG.xml file (Select Source tab for type below code in Eclipse)


<suite name="TestNG_Suite">
<test name="TestNG_Test">
<classes>
<class name="TestNG_Package.TestNG_Test1"></class>
</classes>
</test>
</suite>



Here,

-> <suite> :

 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> :

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> :

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


-> <class> :

class tag defines the class name which you wants to consider in test execution.


Example :

In above given example, we have defined name="TestNG_Package.TestNG_Test1"

Here 'TestNG_Package' describes package name
and 'TestNG_Test1' describes class name.

So in above example we are going to run only one class.



5) Running TestNG.xml file


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

It will start execution of Test_Test1 class.



6)  View test execution HTML report generated by TestNG


- Right click on Project named as "TestNG_Project and select Refresh.

- then Folder with name = "test-output" will be created under your project folder.

- Explorer that "test-output" folder. then we can see the "index.html" file.

- Right click on "index.html" file then select open with -> Web browser - To see the HTML report in Eclipse.

No comments:

Post a Comment