Selenium Java - 使用 Getters 和 Setters 的 TestNG 数据提供者

Selenium Java - TestNG Data Providers using Getters and Setters

我在测试用例中使用 Getters 和 Setters this,我正在解析一个数组给它。然后我稍后尝试从数据集控制器 class 中的另一个测试用例引用它,我将在其中提取数组的值。当执行到该部分代码时,返回值始终为 Null。我已经尝试了很多事情,包括将字段设为静态等。我似乎找不到正确的解决方案。下面是我的 Getters 和 Setters 代码。我留下了注释代码。共有三个数据提供者。这是在第一个测试用例中设置的。然后我在第二个测试用例中尝试 getSubscriber_Type 。但它仍然显示 Null 值。但是它显示了第三个测试用例中的值。有人可以帮助我吗?

public class SubscriberType {
    static String[] Subscriber_Type;

/*public SubscriberType(String[] sScenarioType)
{
        this.Subscriber_Type = sScenarioType;
}*/

/* public SubscriberType()
{
Subscriber_Type = null;
}*/

public static void setSubscriber_Type(String[] sSubscriber_Type) {
    Subscriber_Type = sSubscriber_Type;
}

public String[] getSubscriber_Type() {
    return Subscriber_Type;
}

}

下面用于设置包含简单字符串值数组的工作表对象的代码:

getSubscriberBaseTest.setSubscriber_Type(workSheet);

下面是获取工作表值的代码:

SubscriberType = getSubscriberBaseTest.getSubscriber_Type();

声明:

public static SubscriberType getSubscriberBaseTest;
public static final String[] workSheet = new String[3];

这是如何解决的:dependsOnMethods = { "DatasetFromExcel" },我使用了 dependsOnMethod 属性,因为稍后需要使用一些信息。

这是google对该属性的解释:

dependsOnMethods : dependsOnMethods attribute on a test method [test1 e.g.] specifies all the test methods [test2, test3,..] this test method depends on. It means test1 will start execution only after all the tests it depends on executed successfully.