Java 如何创建TestNg类
我需要关于创建testng``scipt..的帮助 我创建了一个只包含@beforesuite的类,其中包含打开应用程序的命令Java 如何创建TestNg类,java,testng,appium,Java,Testng,Appium,我需要关于创建testng``scipt..的帮助 我创建了一个只包含@beforesuite的类,其中包含打开应用程序的命令 @beforesuite 第二类包含3个方法 @test{method1} @test{method2} @test{method3} 第三个类包含@AfterSuite,它关闭应用程序 @AfterSuite 如何编写xml文件以逐个运行这些类 有没有更好的方法来编写脚本 任何建议都会有帮助 提前谢谢 Sudhanva只需将这些类放在测试套件文件中,tes
@beforesuite
第二类包含3个方法
@test{method1}
@test{method2}
@test{method3}
第三个类包含@AfterSuite,它关闭应用程序
@AfterSuite
如何编写xml文件以逐个运行这些类
有没有更好的方法来编写脚本
任何建议都会有帮助
提前谢谢
Sudhanva只需将这些类放在测试套件文件中,testNG将负责首先运行带有@BeforeSuite的类,然后运行带有@test next的类,最后运行带有@aftersuite标记的类
<suite>
<test name ="myTest">
<classes>
<class name ="Class1"/> <!-- Class with @beforeSuite-->
<class name ="Class2"/> <!-- Class with @test-->
<class name ="Class3"/> <!-- Class with @afterSuite-->
</classes>
</test>
</suite>
顺便问一下,为什么要为@AfterSuite和@BeforeSuite方法创建不同的类。如果所有人都在同一个类中,情况会更简单。但这只是我的想法。我建议如下: 请仔细阅读这篇文章,这是一篇非常详细的TestNG文档。您可以为测试注释设置“优先级”属性
//this decides the order in which your tests are executed
@test{priority=1} //executed first
@test{priority=2} //executed second
@test{priority=3} //executed third
由于这看起来像是一个关键字驱动的框架,我建议您从excel工作表中传递类名,而不是实现XML解析器
实现excel表格的读/写,是一个很好的库。它支持xls和xlsx文件。这样修改执行顺序也很容易。有关关键字驱动框架的更多信息,请参见本文
就报告结构而言,TestNG可以生成自己的报告,但具有良好的视觉吸引力
以下是如何在XML文件中提到您的测试:
<?xml version="1.0" encoding="UTF-8"?>
<suite name="SuiteName" verbose="1" data-provider-thread-count="10"
thread-count="10">
<test name="TestName" thread-count="10">
<classes>
<class name="packageName.ClassName"/>
<class name="packageName.ClassName" />
</classes>
</test>
</suite>