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

0 votes
Jun 12, 2019 in Selenium by Revathi
7,238 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, 2019 by Abha
• 28,140 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How to disable a test case in testNG?

You can use the enable method to ...READ MORE

answered Jan 3, 2019 in Selenium by Nabarupa
1,829 views
0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

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,500 points
12,576 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,558 views
0 votes
2 answers

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

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

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
2,472 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,910 points
6,603 views
0 votes
1 answer

How to create a test case with TestNG in Selenium?

Hey Deepak, to create a Test Case ...READ MORE

answered May 22, 2019 in Selenium by Abha
• 28,140 points
964 views
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, 2019 in Selenium by Abha
• 28,140 points
2,692 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP