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

0 votes
6 days ago in Selenium by Revathi
16 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 5 days ago by Abha
• 8,250 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
135 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
148 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
526 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 5 days ago in Selenium by Abha
• 8,250 points
18 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.