【发布时间】:2017-12-21 10:21:57
【问题描述】:
我正在使用 selenium 3.8.1 和 TestNG 6.9.2 版本,而在完成 @Test 方法之前的测试执行另一个 @Test 方法开始了,因为这个我在 selenium 脚本中遇到错误在完成测试用例后执行。
一类
public class LoginPage{
@Test(priority=0)
public void test1(){
System.out.println(first test);
}
@Test(priority=1)
public void test2(){
System.out.println(Second test);
}
}
二等
public class HomePage{
@Test(priority=0)
public void test3(){
System.out.println(first test);
}
@Test(priority=1)
public void test4(){
System.out.println(Second test);
}
}
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test" preserve-order="true">
<classes>
<class name="com.tests.day.modules.LoginPage"/>
<class name="com.tests.day.modules.HomePage"/>
</classes>
</test>
</suite>
在完成登录页面类的test2之前使用testng.xml文件执行上述操作后,test3正在启动主页,因为这个我得到了异常,无法找到元素。
【问题讨论】:
-
你怎么知道 test3 在 test2 完成之前开始了。当我们将保留顺序设置为 true 时,它将仅在 test2 之后启动 test3。可能是其他原因造成的异常。
-
在测试中我正在打印页面标题,当时测试 3 页面标题在打印测试 2 页面标题之后首先打印
标签: java selenium selenium-webdriver testng testng-annotation-test