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
添加回答
舉報