gpt4 book ai didi

java - Selenium Java - 使用 Getters 和 Setters 的 TestNG 数据提供程序

转载 作者:太空宇宙 更新时间:2023-11-04 09:03:40 24 4
gpt4 key购买 nike

我在测试用例中使用 Getters 和 Setters,并且我正在向它解析一个数组。然后,我稍后尝试从数据集 Controller 类中的另一个测试用例引用它,我将在其中提取数组的值。当执行到该部分代码时,返回的值始终为 Null。我尝试了很多事情,包括使字段静态等......我似乎找不到正确的解决方案。下面是我的 Getter 和 Setter 代码。我留下了注释的代码。共有三个数据提供者。这是在第一个测试用例中设置的。然后我尝试在第二个测试用例中 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属性,因为稍后需要使用一些信息。

这是谷歌对此属性的解释:

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.

关于java - Selenium Java - 使用 Getters 和 Setters 的 TestNG 数据提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60483851/

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