Vig*_*esh 5 testng selenium selenium-webdriver
我的类中有很多方法,当我运行代码时,方法是随机调用的,但是在我的类中,每个方法都取决于其前驱方法,即第二个方法取决于第一个方法,第三个方法取决于第二个方法,依此类推.我想按顺序执行所有方法
我尝试了以下方法并测试了代码,但仍然随机调用这些方法
//using sequential
@Test(sequential = true)
public void Method1(){
}
@Test(sequential = true)
public void Method2(){
}
//using singleThreaded
@Test(singleThreaded=true)
public void Method1(){
}
@Test(singleThreaded=true)
public void Method2(){
}
Run Code Online (Sandbox Code Playgroud)
我也在 testng 中传递了以下参数
<test name="Test" preserve-order="true" annotations="JDK">
<classes>
<class name="com.test" >
<methods>
<include name="method1"/>
<include name="method2"/>
<include name="method3"/>...
</methods>
</class>
</classes>
</test>
</suite>
Run Code Online (Sandbox Code Playgroud)
当我用 测试它时@Test(dependsOnMethod=""),不是按顺序执行这些方法,而是跳过了这些方法。
如何在testng中顺序执行测试?
如果您想以某种特定方式运行所有测试方法,那么只需在@test注释中添加优先级即可。请参阅以下内容:-
@test(priority=0)
function1()
{}
@test(priority=1)
function2()
{}
@test(priority=5)
function3()
{}
@test(priority=3)
function4()
{}
@test(priority=2)
function5()
{}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,函数 1 先调用函数 2,然后函数 5 将调用而不是函数 3,因为优先级。
您可以使用 @Priority 和侦听器来控制执行。请参阅此链接 - http://beust.com/weblog/2008/03/29/test-method-priorities-in-testng/
| 归档时间: |
|
| 查看次数: |
19887 次 |
| 最近记录: |