有人和cucumber-jvm有一个sharedDriver示例吗? SharedDriver已经实现了Ashlak的描述,但是我如何实例化驱动程序并在页面对象之间共享?
共享驱动程序类:
public class SharedDriver extends EventFiringWebDriver {
private static final WebDriver REAL_DRIVER = WebDriverFactory.create();
private static final Thread CLOSE_THREAD = new Thread() {
@Override
public void run() {
REAL_DRIVER.quit();
}
};
static {
Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
}
public SharedDriver() {
super(REAL_DRIVER);
}
@Override
public void quit() {
if (Thread.currentThread() != CLOSE_THREAD) {
throw new UnsupportedOperationException("You shouldn't quit this WebDriver. It's shared and will quit when the JVM exits.");
}
super.quit();
}
@Before
public void deleteAllCookies() {
manage().deleteAllCookies();
}
@After
public void embedScreenshot(Scenario scenario) {
try {
byte[] screenshot = getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
} catch (WebDriverException somePlatformsDontSupportScreenshots) {
System.err.println(somePlatformsDontSupportScreenshots.getMessage());
}
}
}
如果我有一个登录页面,带有步骤类的注册页面,我该如何使用这个共享驱动器?
谢谢!
让我回答我的问题。
SharedDriver类(见上文)很好,唯一的配置是黄瓜picocontainer,使用SharedDriver而不是WebDriver驱动程序,并用这个驱动程序实例化页面对象。工作将由picocontainer处理。