1 回答

TA贡献1880条经验 获得超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;
}
}
这将导致@Factory将参数从 DataProvider 传递给您的InitializeDriver类并将其保存为实例变量。
然后你可以在你的@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");
}
编辑:该@BeforeTest方法只会执行一次,因为 TestNG 将@Factory测试视为单个测试用例!如果要在每次测试前登录,则需要使用@BeforeMethod
添加回答
举报