Wednesday, August 8, 2018

How to pass parameters from testng.xml?

We can pass test data as parameters from testng.xml to the tests directly using TestNG Parameters feature.

To pass any parameter from testng.xml we can define "parameter" tag at suite, test and class level in testng.xml. Syntax is <parameter name="name_of_parameter", value="value_of_parameter"/>. We can add any number of parameters for a test. Please see the below screenshot.

To use the parameters in the test methods, we have to use @Parameters annotation provided by TestNG. And @Parameters annotation can be used with the methods that has @Test, @BeforeXXXX, @AfterXXXX or @Factory annotations. Inside @Parameters annotation we have to give the name of the parameters and these names must be same as what we have given in the testng.xml as shown in the below screenshot.

This how the testng.xml looks like after adding the parameters.

If we run the test method from the class, it will throw an exception. Because the test method is associated with parameters that are defined in the testng.xml file. The test method will not be able to understand what are the parameters.

So we should run the below test using testng.xml and see the result, we have not written selenium code in the test case. Here our main focus is to check how to parameterize the test using testng.xml, that's why are just printing the parameters.

Check the below result, the test case has received the values from the testng.xml and printed in console.

This is how we parameterize the test using testng.xml, generally we pass data like browser type, application url, user credentials and etc from the testng.xml file. We do not prefer to send large in this approach.

Practically this approach is less used, testers use configuration files to maintain such data.

Thanks for reading. Please comment your queries or suggestions on this post. #HappyLearning #HappyTesting #qababu


  1. I am really happy with your blog because your article is very unique and powerful for new reader.
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune

    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

  2. Your articles really impressed for me,because of all information so nice.servicenow training in bangalore

  3. These provided information was really so nice,thanks for giving that post and the more skills to develop after refer that post.opennebula training in bangalore

  4. I gathered a lot of information through this article.Every example is easy to undestandable and explaining the logic easily.openstack training in bangalore

  5. Very useful and information content has been shared out here, Thanks for sharing it.salesforce developer training in bangalore

  6. This is really an awesome post, thanks for it. Keep adding more information to this.vmware training in bangalore

  7. thank you so much for this nice information Article, Digitahanks for sharing your post with us.Real Time Experts training center bangalore

  8. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful . student review for Realtime Experts marathahalli bangalore

  9. I have read your blog its very attractive and impressive. I like it your blog.Real Time Experts Training in Bangalore center address bangalore


Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...