Selenium 中的测试运行器如何确定测试类的执行优先级?
seleniumautomation testingtesting tools
我们可以在 TestNG 中设置测试执行的优先级。需要注意的是,只有带有 @Test 注解的测试方法才能设置优先级。测试方法的优先级设置值越低,其执行时的优先级就越高。
只能将整数值(正数、零或负数)设置为优先级。也可以将十进制数设置为优先级,但需要通过类型转换将其转换为整数值。
一个测试方法不能有多个优先级。此外,无法从 TestNG XML 文件中设置测试方法的优先级。
语法
public class TestNG {
@Test (priority = 2)
public void tC1() {
System.out.println("Test Case 1");
}
示例
import org.testng.annotations.Test;
public class TestNGP {
@Test (priority = 2)
public void testCase1() {
System.out.println("This is the A Normal Test Case 1");
}
@Test (priority = 1)
public void testCase2() {
System.out.println("This is the A Normal Test Case 2");
}
@Test (priority = 3)
public void testCase3() {
System.out.println("This is the A Normal Test Case 3");
}
}
输出

相关文章
打印
下一节:如何在 Selenium 中通过多个类名查找 div 元素? ❯❮ 上一节:如何解决 Selenium WebDriver 中的 ElementNotInteractableException?

