@Parameters annotation: How to inject test data from testng.xml?

Parameterization is the soul of software testing (it also includes automation testing). We have discussed various techniques here (at inviul) to maintain the test data in our Automation Framework. Today we are going to discuss the uses of @Parameters annotation to inject test data from a testng.xml file. Though the scope of this technique is not broader than @DataProvider technique, still it keeps its significance to leverage parameterization in our automation framework. You can say, this is one of the most important features of TestNG, which you can’t observe in Junit.

In the previous tutorial, we have seen the implementation of @DataProvider annotation in the Selenium project which leverages parameterization in a very broader sense. Before we discuss the implementation of @Parameters annotation which helps in parameterization, let’s have a quick look at some of the techniques to implement parameterization in the Selenium project.

Some of the exclusive TestNG tutorials are-

I believe above tutorials will help you achieve parameterization through various techniques.

Now coming to the implementation of @Parameters annotation in your Selenium project. First of all, you need to create a TestNG class where you will write your test case inside @Test annotation. Test data will be used inside the Test case, so we define some variable name where the value of test data will be stored. We will use this variable where we want its value to be observed.

We will assign a value to this variable from testng.xml by using the following statement:

If you go for any interview, then interviewer generally ask questions related to @Parameters annotation and its uses. You can click below for quick Selenium interview questions.

Exclusively for You: Top 200 Selenium Interview Questions

@Parameters annotation in TestNG

If we have to implement @Parameters annotation in our project, then its implementation will be written below the @Test annotation. Let’s have a look inside the sample program which implement @Parameters annotation in Selenium project using TestNG.

Sample Program to implement @Parameters annotation

Value assignment through the estng.xml file

Below is the assignment of value to the variable name annotated by @Parameters annotation through the estng.xml file.

Console output

 @Parameters annotation output

That’s all about @Parameters annotation. You can ask your doubts here and also you can join our Facebook group for more updates on Automation Testing using Selenium WebDriver.

Join Inviul fb group

Leave a Reply