[英]Generics and constructor in the inherited class
guys. 家伙。 I am a QA tester and I keep learning automation with Selenium and Java.
我是质量检查测试人员,并且不断使用Selenium和Java学习自动化。 I can not understand why do I need to add generics and constructor in the class ProfilePage?
我不明白为什么我需要在类ProfilePage中添加泛型和构造函数? So lets create Page Object class:
因此,让我们创建Page Object类:
public class BasePageObject {
protected WebDriver driver;
protected void getPage(String url){
driver.get(url);
}
private WebElement find(By element) {
return driver.findElement(element);
}
protected void type(String text, By element){
find(element).sendKeys(text);
}
}
Now lets create class for profile page: 现在让我们为个人资料页面创建类:
public class ProfilePage extends BasePageObject<ProfilePage> {
private By editProfileButton = By.xpath("//button[@id='editProfile']");
private By advancededitProfileButton = By.xpath("//a[@class='dice-btn-link']");
private By profileContactNameText = By.xpath("//h1[@class='profile-contact-name']");
protected ProfilePage(WebDriver driver) {
super(driver);
}
public boolean isCorrectProfileLoaded(String correctProfileName){
if (getText(profileContactNameText).equals(correctProfileName)){
return true;
}else
return false;
}
}
So the question is: why should I use generics "ProfilePage" "after extends BasePageObject" and why do I have to create protected ProfilePage(WebDriver driver) { super(driver); }
所以问题是:为什么我应该使用通用的“ ProfilePage”“在扩展BasePageObject之后”,为什么我必须创建
protected ProfilePage(WebDriver driver) { super(driver); }
protected ProfilePage(WebDriver driver) { super(driver); }
Thanks! 谢谢!
I think your doubts are justified. 我认为您的怀疑是有道理的。 As far as seleniums
BasePageObject
is concerned, it has no type parameter and it has no constructor that would expect a WebDriver
parameter. 就硒
BasePageObject
而言,它没有类型参数,也没有构造函数需要WebDriver
参数。
Is it possible that there is another BasePageObject
in a package other than com.wikia.webdriver.pageobjectsfactory.pageobject
? 包中是否可能存在
com.wikia.webdriver.pageobjectsfactory.pageobject
以外的其他BasePageObject
?
If yes, then that's a reason. 如果是,那就是原因。 It's a bit confusing though.
不过这有点令人困惑。
Otherwise this ProfilePage
just won't compile. 否则,此
ProfilePage
将无法编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.