在对如何同时运行Cucumber测试用例进行了大量研究之后,我发现了以下关于这个主题的非常有用的文章:
https://www.opencredo.com/2013/07/02/running-cucumber-jvm-tests-in-parallel/
本文提供了一些很好的信息,可以帮助您开始使用多线程环境,包括可以从Github下载的一些代码.
https://github.com/tristanmccarthy/Cucumber-JVM-Parallel
如果我理解正确的文章,驱动程序应该可配置为使用Grid,使您能够跨多个设备运行多个测试用例.在使用chromedriver对代码进行一些测试后,它似乎按照文章中的描述工作.但是,一旦配置为使用Grid,测试用例就不再并行执行.相反,它们是按顺序执行的.
目前,我已将Grid配置为具有1个集线器和2个节点.每个节点在任何给定时间最多可以有2个会话.
注意:没有Cucumber,我能够在多个设备上成功部署多个测试用例,所以我认为这个问题与我的网格设置无关.
以下是与Web驱动程序相关的代码示例:
static {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setBrowserName("chrome");
capabilities.setPlatform(Platform.ANY);
try {
REAL_DRIVER = new RemoteWebDriver(new URL("http://xxx.xxx.xxx.xxx:4444/wd/hub"), capabilities);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
REAL_DRIVER.manage().timeouts().pageLoadTimeout(3000, TimeUnit.SECONDS);
REAL_DRIVER.manage().window().maximize();
Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
}
public SharedDriver() {
super(REAL_DRIVER);
}
@Override
public void close() {
if (Thread.currentThread() != CLOSE_THREAD) {
throw new UnsupportedOperationException(
"You shouldn't close this WebDriver. It's shared and will close when the JVM exits.");
}
super.close();
}
Run Code Online (Sandbox Code Playgroud)
我怀疑如果您使用多种浏览器类型,您应该能够在多个设备上运行测试用例(每个设备1个浏览器),但在我的情况下,我正在使用Chrome驱动程序.有谁知道什么可能阻止测试用例分布在多个设备上,或者更好地理解Grid如何与黄瓜一起工作?请分享与此问题相关的任何文章或信息.
+ =和= +无法正常工作.以下代码输出@@ num_things的正确值.
class Thing
@@num_things = 0 # class variable
def initialize()
@@num_things += 1 # increment @@num_things
end
def value
@@num_things
end
end
t1 =Thing.new()
puts t1.value
t2 =Thing.new()
puts t2.value
t3 =Thing.new()
puts t3.value
Run Code Online (Sandbox Code Playgroud)
输出是:
1
2
3
Run Code Online (Sandbox Code Playgroud)
但是,如果将表达式从+ =反转为= = +,则输出变为
1
1
1
Run Code Online (Sandbox Code Playgroud)
我错过了什么?一旦调用该值,我希望两种情况下的输出都相同.