[英]How to pass class name dynamically in to class tag in Testng XML
I need to pass the class name dynamically in to <Class>
in Testng XML 我需要动态地将类名传递给Testng XML中的<Class>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
<test thread-count="5" name="Test">
<parameter name="browser" value="chrome"></parameter>
<classes>
<class name="testCaseWithKeywordFramework.TestCase1_Login"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
in the above XML code i want to pass the class name dynamically, can anyone help me in this. 在上面的XML代码中我想动态传递类名,任何人都可以帮助我。
It is possible by creating the suite file itself at run time. 可以通过在运行时创建套件文件来实现。 Check this example - http://www.testautomationguru.com/selenium-webdriver-creating-testng-suite-xml-from-spreadsheet/ 查看此示例 - http://www.testautomationguru.com/selenium-webdriver-creating-testng-suite-xml-from-spreadsheet/
You can invoke TestNG from your own programs very easily: 您可以非常轻松地从自己的程序中调用TestNG:
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { Run2.class });
testng.addListener(tla);
testng.run();
This example creates a TestNG object and runs the test class Run2. 此示例创建一个TestNG对象并运行测试类Run2。
For more you can refer here 有关更多信息,请参阅此处
Similarly, you can invoke TestNG on a testng.xml file or you can create a virtual testng.xml file yourself 同样,您可以在testng.xml文件上调用TestNG,也可以自己创建虚拟testng.xml文件
For example, suppose you want to create the following virtual file: 例如,假设您要创建以下虚拟文件:
<suite name="TmpSuite" >
<test name="TmpTest" >
<classes>
<class name="test.failures.Child" />
<classes>
</test>
</suite>
You would use the following code: 您将使用以下代码:
XmlSuite suite = new XmlSuite();
suite.setName("TmpSuite");
XmlTest test = new XmlTest(suite);
test.setName("TmpTest");
List<XmlClass> classes = new ArrayList<XmlClass>();
classes.add(new XmlClass("test.failures.Child"));
test.setXmlClasses(classes) ;
And then you can pass this XmlSuite to TestNG: 然后你可以将这个XmlSuite传递给TestNG:
List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.run();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.