您可能无法实现
继承
但是你可以用
施工人员
要传递的步骤定义类
驱动程序对象引用
从一个班到另一个班。
-
创建一个基础/基础类,初始化驱动程序对象/页面对象类。使用@before注释定义安装程序,使用@after定义拆卸方法。
public class Step_Def_Base {
public static webDriverCreator test;
@Before
public void printScenario(Scenario scenario) {
test = new webDriverCreator(this.getClass().getSimpleName());
String className = this.getClass().getCanonicalName();
System.out.println("********************************************************");
System.out.println("Scenario: " + scenario.getName());
System.out.println("********************************************************");
}
@After
public void screenShotAndConsoleLog(Scenario result) {
test.takescreenshot.takeScreenShotOnException(result);
if (!(result.getStatus().contains("pass"))) {
throw new RuntimeException(result.getName() + " got failed");
}
test.closeBrowserSession();
}
}
-
在步骤定义类中,创建一个构造函数并用上下文实例化BaseFoundation对象。在这里,pico容器扮演着将步骤定义类的驱动程序对象与另一个类链接起来的神奇角色。
public class StepDefs_AltoroMutualLoginPage {
private Step_Def_Base contextStep;
private webDriverCreator test;
public StepDefs_AltoroMutualLoginPage(Step_Def_Base contextStep) {
// TODO Auto-generated constructor stub
this.contextStep = contextStep; // <-- This is where pico-containers starts working
test = contextStep.test; // <-- Linking your driver object reference from the point where it is instantiated , i.e the base foundation class
}
@Given("^I am on test fire login page \"([^\"]*)\"$")
public void alotoroMutualLoginPage(String url) {
test.launchApplication(url);
test.altoroMutual.launchLoginLink();
test.altoroMutual.verifyUserIsOnLoginPage();
}
现在您可以获得创造性,并相应地组织页面对象。我在返回Web驱动程序对象的包装类中聚合并实例化了所有的页面对象类。你可以在代码中看到,我正在访问
altoroMutual
PageObject类来自
test
对象。
确保您正在使用
马文
管理所有开发依赖项。以下依赖项将在您的项目中添加pico容器。
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>2.14.3</version>
</dependency>