黄瓜picocontainer / SharedDriver无法正确处理浏览器实例 [英] Cucumber picocontainer/SharedDriver doesn't handle browser instance properly
问题描述
我正在使用Cucumber-jvm picocontainer在课程之间共享硒驱动程序。我有ShareDriver和WebDriverFactory类。
I'm using cucumber-jvm picocontainer to share selenium driver between classes. I have ShareDriver and WebDriverFactory class.
我的问题如下:
1.如果我运行2个测试用例,则驱动程序/浏览器实例在第一个测试用例(新的浏览器实例)之后关闭创建并运行第二个。我只想使用1个浏览器实例并运行测试,然后将其关闭。
My problem is the following: 1. If I run 2 test cases, the driver/browser instance is closed after the first test case, new browser instance is created and run the second one. I would like to use only 1 browser instance and run the tests, then close it.
- IEDriverServer.exe和一个测试后,java.exe卡在了任务管理器上,但是关闭了浏览器。我需要手动杀死他们。每次运行都会根据这些任务创建一个新的运行。我尝试了stackoverflow中的所有想法,但是没有一个可以解决这个问题。
谢谢!
我的SharedDriver类:
My SharedDriver class:
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类:
My WebDriverFactory class:
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);
}
}
推荐答案
SharedDriver的实现不正确。您需要在shareddriver类中有一个静态webdriver字段,创建一个关闭线程,然后将该线程添加到jvm shutdown挂钩中。使用此一个
The implementation of SharedDriver is not correct. You need a static webdriver field in the shareddriver class, create a shutdown thread, add this thread to the jvm shutdown hook. Use this one
如果您也想杀死它,请使用此。将其添加到关闭钩子。在调用REAL_DRIVER.quit()之后将其添加到线程的run方法中。
If you wanna kill that too use this. Add this to the shutdown hook.Add it inside the run method of the thread after call to REAL_DRIVER.quit().
这篇关于黄瓜picocontainer / SharedDriver无法正确处理浏览器实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!