gpt4 book ai didi

java - 使用数据提供者时使用 Test-ng 优先级

转载 作者:行者123 更新时间:2023-12-02 10:36:58 24 4
gpt4 key购买 nike

我正在使用带有 test-ng 的数据提供程序,并且我希望特定的测试对数据收集对象中的每个元素遵循一系列步骤。

测试:

For each element in the object, validate the form can input the values

因此该过程具有以下内容:

  1. 打开网页(来自数据)
  2. 检查页面上是否存在元素
  3. 输入值

我尝试使用下面的内容,但是,对于对象中的每个元素,它运行步骤 1,然后移动到步骤 2,而不是遵循该过程。因此,我想问是否可以使用 test-ng 进行“测试步骤”方法?

如果Data中有2个值,它将执行Open两次,然后继续执行CheckElementExists

@Test (priority = 1, dataProvider = "Data")
public void Open(Data data) throws InterruptedException
{
System.out.println("Step 1");
this.module.open(data);
}

@Test (priority = 2, dataProvider = "Data")
public void CheckElementExists(Data data)
{
System.out.println("TWO");
}

最佳答案

在这种情况下,您可以使用工厂类。

public class TestCase {
Data data;

@Factory(dataProvider = "Data")
public TestCase(Data data){
this.data=data;
}

@Test(priority = 1)
public void Open() throws InterruptedException {
System.out.println("Step 1");
this.module.open(data);
}

@Test(priority = 2)
public void CheckElementExists(Data data) {
System.out.println("TWO");
}
}

您需要在 testng 套件 xml 文件中提及 group-by-instance = true 并使用 xml 套件运行

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Suite New" group-by-instances="true" configfailurepolicy="continue" preserve-order="true">
<test name="Test Case">
<classes>

<class name="com.package.TestCase"></class>

</classes>
</test>
</suite>

关于java - 使用数据提供者时使用 Test-ng 优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53218119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com