我使用cucumber-jvm picocontainer在类之间共享selenium驱动程序。我有ShareDriver和WebDriverFactory类。
我的问题如下: 1.如果我运行2个测试用例,则在第一个测试用例之后关闭驱动程序/浏览器实例,创建新的浏览器实例并运行第二个测试用例。我想只使用一个浏览器实例并运行测试,然后关闭它。
谢谢!
我的SharedDriver类:
public class SharedDriver extends EventFiringWebDriver implements Startable {
public SharedDriver() {
super(WebDriverFactory.localInternetExplorerWebDriver());
}
@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());
}
}
@Override
public void start() {
}
@Override
public void stop() {
quit();
}
}
我的WebDriverFactory类:
class WebDriverFactory {
static {
System.setProperty("webdriver.ie.driver", "src/test/resources/webDrivers/IEDriverServer.exe");
}
static WebDriver localInternetExplorerWebDriver() {
DesiredCapabilities returnCapabilities = DesiredCapabilities.internetExplorer();
System.setProperty("webdriver.ie.driver", "src/test/resources/webDrivers/IEDriverServer.exe");
//returnCapabilities.setCapability("nativeEvents", false);
returnCapabilities.setCapability("requireWindowFocus", true);
returnCapabilities.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
returnCapabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
returnCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
returnCapabilities.setCapability("ignoreZoomSetting", true);
return new InternetExplorerDriver(returnCapabilities);
}
}