【问题标题】:TestNG Dataprovider closing driver after each iteration每次迭代后 TestNG Dataprovider 关闭驱动程序
【发布时间】:2020-09-02 13:25:20
【问题描述】:

我正在尝试使用 ANT 运行基于数据提供程序的测试。我的主类指向 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);

现在,在我的测试用例文件中,我有

@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.....");
    

}

问题是,如果我从 Testng 运行,它们运行没有任何问题。即,如果我右键单击该文件,单击运行,单击运行为 Testng 测试。 但是,如果我从我的构建文件运行,在第一次迭代之后,我在课前提出的驱动程序会关闭,其余的测试会失败。这导致我的测试在詹金斯中失败。 有人可以帮帮我吗?

【问题讨论】:

    标签: java ant testng dataprovider


    【解决方案1】:

    经过多次尝试,我发现我的触发器文件创建的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>
    

    即使我的测试组是正确的,我也给出了测试包,因此我所有的测试用例文件都被添加为类。所有这些都有一个监听器,它会在测试运行后关闭驱动程序。我对testng了解不多,但我认为它混淆了听众。在我的触发器文件中,当我添加刚刚

    TestNG tng=new TestNG();
            tng.setOutputDirectory("test-output");
            //tng.setXmlSuites(suits);
            
            
            tng.setTestClasses(new Class[] { IndicatorFileUpload.class });
            tng.run();
    

    成功了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多