[英]How to create TestNg classes
我需要在創建Testng Scipt方面的幫助..
我創建了一個僅包含@beforesuite的類,該類包含打開應用程序的命令
@beforesuite
第二類包含3種方法
@test{method1}
@test{method2}
@test{method3}
第三類包含@AfterSuite,它將關閉應用程序...
@AfterSuite
如何編寫一個xml文件來依次運行這些類。
有沒有更好的方法來編寫腳本?
任何建議都會有所幫助。
提前致謝。
Sudhanva
只需將這些類放在測試套件文件中,testNG將負責運行首先具有@BeforeSuite的類,其次具有@test的類,然后是具有@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工作表的讀寫, Apache POI是一個很好的庫。 它同時支持xls和xlsx文件。 這種修改執行順序的方法也很容易。 有關關鍵字驅動框架的更多信息,請參見此鏈接 。
就報告結構而言,TestNG可以生成自己的報告,但是ATU Graphical Reporter具有很好的視覺吸引力。
這是在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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.