[英]TestNG Dataprovider closing driver after each iteration
I am trying to run a dataprovider based test using ANT.我正在尝试使用 ANT 运行基于数据提供程序的测试。 My main class points to testNG file
我的主类指向 testNG 文件
XmlSuite suite=new XmlSuite();
suite.setName("Test Results");
suite.setPreserveOrder(true);
List<XmlSuite> suits=new ArrayList<XmlSuite>();
suits.add(suite);
List<XmlPackage> xpackage=new ArrayList<XmlPackage>();
xpackage.add(new XmlPackage(TestProperties.TESTNG_PACKAGE.toString()));
XmlTest test=new XmlTest(suite);
test.setPackages(xpackage);
String groups=TestProperties.TESTNG_GROUP.toString();
System.out.println("groups are:"+groups);
String groupArray[]=groups.split(",");
List<String> includedGroups=new ArrayList<String>();
includedGroups.addAll(Arrays.asList(groupArray));
test.setIncludedGroups(includedGroups);
TestNG tng=new TestNG();
tng.setOutputDirectory("test-output");
tng.setXmlSuites(suits);
tng.run();
System.exit(0);
Now, in my Testcase file, I have现在,在我的测试用例文件中,我有
@BeforeClass(alwaysRun = true)
public void pretest() throws IOException, GeneralSecurityException {
Pretest
}
@Test(groups= {"indicatorGroup","",""},description = "Validate indicator uploaded", dataProvider = "getIndicatorData")
public void indicatorUpload(String txt){
test
}
@DataProvider
public Object[] getIndicatorData() throws IOException, GeneralSecurityException
{
bla bla
for(int i=0; i<contents.length; i++) {
System.out.println(contents[i]);
if(!contents[i].contains("README")) {
blah blah
System.out.println(path);
names.add(path);
}
}
String[] myArray = new String[names.size()];
names.toArray(myArray);
return myArray;
}
@AfterClass(alwaysRun = true)
public void afterMethod() throws IOException {
System.out.println("Deleting all files after operation.....");
}
The problem is, they run without any issues, if i run from Testng.问题是,如果我从 Testng 运行,它们运行时没有任何问题。 ie if i right click on the file, click on run, click on Run as Testng Test.
即,如果我右键单击该文件,单击运行,单击作为 Testng 测试运行。 But if I run from my build file, after the first iteration, the driver I bring up in before class, closes and the rest of the tests fail.
但是如果我从我的构建文件运行,在第一次迭代之后,我在上课前引入的驱动程序关闭,其余的测试失败。 This causes my tests to fail in jenkins.
这导致我的测试在 jenkins 中失败。 Can someone please help me out?
有人可以帮我吗?
After many trials, I found out that the testng xml created By my trigger file had经过多次试验,我发现我的触发器文件创建的 testng xml 有
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="IndicatorSuite" data-provider-thread-count="1">
<test name="Test Basics 1">
<groups>
<run>
<include name="indicatorUpload" />
</run>
</groups>
<classes>
<class name="Uploads.IndicatorFileUpload">
<class name="Uploads.IndicatorFileUpload1">
<class name="Uploads.IndicatorFileUpload2">
</methods>
</class>
</classes>
</test>
</suite>
Even though my test group was correct, I had given test package, because of which all my testcase files had been added as classes.即使我的测试组是正确的,我也给出了测试包,因此我所有的测试用例文件都被添加为类。 All of these had a listener which would close the driver after testrun.
所有这些都有一个监听器,可以在测试运行后关闭驱动程序。 I dont know much about testng, but I think it mixed up the listeners.
我不太了解 testng,但我认为它混淆了听众。 In my Trigger file, when I added just
在我的触发器文件中,当我添加
TestNG tng=new TestNG();
tng.setOutputDirectory("test-output");
//tng.setXmlSuites(suits);
tng.setTestClasses(new Class[] { IndicatorFileUpload.class });
tng.run();
it worked!有效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.