Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
409 views
in Selenium by
recategorized by
I need to pass parameters using testng.xml. How do i do that?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
 
Best answer

You can pass parameters like this.

 

In class:

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class ParameterizedTest1 {
    @Test
    @Parameters("myName")
    public void parameterTest(String myName) {
        System.out.println("Parameterized value is : " + myName);
    }
}

In testng.xml

 

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
    <test name="test1">
	<parameter name="myName" value="manisha"/> 
	<classes>
	    <class name="ParameterizedTest1" />
	    </classes>
    </test>
</suite>

 

by
Couldn't get this to work while passing multiple parameters.
by The go-to Tester (181 points)
Try using {} for getting multiple parameters.

@Parameters({"myName1","myName2","myName3"})


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

...