1 回答
TA贡献1788条经验 获得超4个赞
它不起作用,因为您使用批注对构造函数进行了批注,然后使用了继承。@Factory
要保留继承等,您应该用SampleTest@Factory
喜欢这个:
public class SampleTest extends InitializeWebDriver {
private String userName, password;
@Factory(dataProvider="authentication", dataProviderClass=DataProviderList.class)
public SampleTest(String userName, String password) {
super(userName, password)
}
}
public class InitializeDriver extends BrowserFactory {
private String userName, password;
public InitializeDriver(String userName, String uPassword)
{
this.userName = userName;
this.password = password;
}
}
这将导致将参数从 DataProvider 传递到您的类,并将其另存为实例变量。@FactoryInitializeDriver
然后,您可以使用这些变量,就像在您的方法中一样:@BeforeTest
@BeforeMethod
public void Gexlogin() {
LoginPF objLogin=PageFactory.initElements(BrowserFactory.driver, LoginPF.class);
System.out.println("Logging into GEx");
objLogin.loginToDGEx(userName, password); //changed to instance variables
System.out.println("Successfully Logged into GEx");
}
编辑:该方法只会执行一次,因为TestNG将测试视为单个测试用例!如果要在每次测试之前登录,则需要使用@BeforeTest@Factory@BeforeMethod
添加回答
举报