TestNG Tutorials 7: How To Create Customized TestNG XML?

Hello Folks,

In this post, we are going to learn to generate customized testng.xml.

Generation of testng.xml depends upon how you create it. We will see some scenarios in this post.

Scenario 1: Generating testng.xml for an individual class. 

We will take same example of previous post:

You need to select individual class and do right click on it and select “TestNg –> Convert to Testng”.  In preview you can see only selected class is selected in testng.xml as shown below:

Class name is added with package name.

Scenario 2: Create a copy of “MyFirstTest.java” and paste in same package as “MySecondTest.java”. Repeat it and add third class name “MyThirdTest.java”.

 

Now select any two class names using( Use ctrl to select multiple) and do right click on it and select “TestNg –> Convert to Testng”.  In preview you can see only selected classes are selected in testng.xml as shown below:

Scenario 3: In above scenarios, we have selected testng class. In this scenario, select package name “TestNGPrograms” and right click on it and select “TestNg –> Convert to Testng”. You can see all testng class of selected package will be included in testng.xml.

 

Scenario 4: Now create a new package under src and copy same classes of package “TestNGPrograms”. Do right click on Project name “TestNGProjects” and select “TestNg –> Convert to Testng”. You will see all testng classes from both the packages are included in testng.xml. 

So the conclusion is that testng xml is generated for all testng classes which are in scope based on user selection in project hierarchy. Remember you can not select multiple project to generate testng xml.

More about TestNG in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappySelenium

 

 

 

7 thoughts on “TestNG Tutorials 7: How To Create Customized TestNG XML?

  1. How do I navigate to TestNG tutorial 7 from TestNG tutorial 6. In “Next Post” you have link to API post rather than TestNG tutorial 7. I want to finish TestNG instead of jumping to another topic.

  2. Hi Amod,I didn’t understand its usage,where should we use it? And Why ? Pls explain any scenario .Thanks

    1. Hi Yogita,
      I explained with examples. It is useful when you need to create testng.xml with selected classes instead of all classes.

  3. Hi, I have doubt about Selenium plugins, apart from TestNg , the tools like AutoIt , Sikuli, Protractor are also called plugins ? What are the other plugins we use with Selenium?

Leave a Reply to yogita sharma Cancel reply

Your email address will not be published. Required fields are marked *