[英]How can I pass a string from main class to another class using TestNG in java?
I have 2 classes, 1 is test class for running testng code and another is main class. 我有2个类,其中1个是运行testng代码的测试类,另一个是主类。 I want to pass string value from main class to test class for running testng code.
我想将字符串值从主类传递给测试类以运行testng代码。 Please help me to execute main class.
请帮助我执行主要课程。
main class code : 主类代码:
public static void main(String[] args) {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[]{
packagename.classname.class });
testng.addListener(tla);
testng.run();
}
testng class code : testng类代码:
Select product_name_dropdown = new Select(driver.findElement(By.xpath("")));
product_name_dropdown.selectByVisibleText(product_name);
I want to pass value of product_name variable from main class to testng class. 我想将product_name变量的值从主类传递到testng类。
You have to use the setParameters(Map<String,String params)
method of XmlSuite or XmlTest
class to pass parameters . 您必须使用
XmlSuite or XmlTest
类的setParameters(Map<String,String params)
方法来传递参数 。
Map<String, String> param = new HashMap<String, String>();
param.put("name", "CrazyForSure");
suite.setParameters(param);
And annotate your Test method with this parameter using @Parameters
. 然后使用
@Parameters
使用此参数注释您的Test方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.