java - 如何在页面对象模型中使用参数驱动程序返回通用类型的新对象
问题描述
我使用硒。我有这样的页面对象:
public class Portal extends Utils{
private WebDriver driver;
private final By getReason= By.xpath("//a[contains(text(),'Get Sol')]");
public Portal(WebDriver driver) {
super(driver);
this.driver = driver;
}
public VisitReason clickCurrentReason() {
clickIn(getReason);
return new VisitReason(driver);
}
}
我想要这个方法:clickCurrentReason() return new Object extend Utils class 并传递给它参数:driver。怎么做?我知道我必须使用泛型。我找到了部分解决方案:
public<T extends Utils> T clickCurrentReason(){
clickIn(getReason);
return (T)(driver);
}
但是如何通过返回:“return new Object(driver)”
@测试方法:
public void Test() {
TestingEnv testingEnv = new TestingEnv(driver);
Portal portal = testingEnv.openPage();
VisitReason visitReason = portal.clickCurrentReason();
//sometimes instead of the last line it will be: VisitInSpot visitInSpot = portal.clickCurrentReason();
//sometimes instead of the last line it will be: VisitBack visitBack = portal.clickCurrentReason();
}
解决方案
推荐阅读
- google-bigquery - 在 BigQuery 中,是否可以在 BigQuery 存储过程中使用类似于 @@ROWCOUNT 的内容?
- javascript - 对于 D3 堆叠条,我如何知道鼠标在哪个条中?
- aws-code-deploy - AWS CodePloy 管道示例存储库:“bash: zip: command not found”
- ios - ScrollView 未显示自定义 UIView
- xamarin.forms - Xamarin 表单:如何为 StackLayout 添加 SwipeGestureRecognizer?
- javascript - 获取 TD 的值以在模态 Javascript 中显示
- python - [Python]如何自动为数据框分配特殊索引?
- java - 如何将不同的片段分配给不同的颜色表?
- tensorflow.js - TypeError: JSON 内容必须是 `dict`,但发现
- react-native - 如何在本机基础 react-native 中自动调整选项卡渲染项的滚动高度