我想运行并行硒测试(使用 webriver 和 Spring JUnit 运行器)。Webdriver 是一个带有自定义线程作用域的 spring bean。但我收到以下警告SimpleThreadScope does not support descruction callbacks
所以浏览器没有关闭。知道如何关闭它们(更准确地说是调用 quit 方法)?
弹簧配置
<bean id="threadScope" class="org.springframework.context.support.SimpleThreadScope" />
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="thread" value-ref="threadScope" />
</map>
</property>
</bean>
<bean id="webDriver" class="org.openqa.selenium.remote.RemoteWebDriver" scope="thread" destroy-method="quit">
<constructor-arg name="remoteAddress" value="http://localhost:4444/wd/hub" />
<constructor-arg name="desiredCapabilities" ref="browserAgent" />
</bean>
行家配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<configuration>
<includes>
<include>**/*Test.class</include>
</includes>
<reportsDirectory>${basedir}/target/surefire-reports</reportsDirectory>
<parallel>classes</parallel>
<threadCount>2</threadCount>
<perCoreThreadCount>false</perCoreThreadCount>
</configuration>
</plugin>
这篇文章http://www.springbyexample.org/examples/custom-thread-scope-module-code-example.html建议自定义线程实现。但是使用任何 JUnit 运行器的 Runnable 扩展点类型在哪里?
public class ThreadScopeRunnable implements Runnable {
protected Runnable target = null;
/**
* Constructor
*/
public ThreadScopeRunnable(Runnable target) {
this.target = target;
}
/**
* Runs <code>Runnable</code> target and
* then afterword processes thread scope
* destruction callbacks.
*/
public final void run() {
try {
target.run();
} finally {
ThreadScopeContextHolder.currentThreadScopeAttributes().clear();
}
}
}