How to pass parameter through testng.xml file to a test case in Selenium Webdriver?

0 votes
Jun 12 in Selenium by Revathi
34 views

1 answer to this question.

0 votes

Hello Revathi, to pass parameter through testng.xml file to a test case, we can define the parameters in the testng.xml file and then reference those parameters in the source files. Create a java test class, say, ParameterizedTest.java and add a test method say parameterizedTest() to the test class. This method takes a string as input parameter. Add the annotation @Parameters(“browser”) to this method.

public class ParameterizedTest {

@Test

@Parameters("browser")

public void parameterizedTest(String browser){

if(browser.equals("firefox")){

System.out.println("Open Firefox Driver");

}else if(browser.equals("chrome")){

System.out.println("Open Chrome Driver");

}

}

}

We could set the parameter using the below syntax in the testng.xml file:

<parameter name="browser" value="firefox"/>

Here, name attribute represents the parameter name and value represents the value of that parameter.

answered Jun 12 by Abha
• 15,320 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
244 views
0 votes
1 answer
0 votes
1 answer

What is the role of TestNG & JUnit frameworks in Selenium?

Well TestNG and JUnit are test frameworks ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,590 points
188 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
616 views
0 votes
1 answer
0 votes
1 answer

How to run a group of test cases using TestNG in Selenium Webdriver?

Hey Kajal, TestNG allows you to perform ordered ...READ MORE

answered Jun 12 in Selenium by Abha
• 15,320 points
44 views