问题描述
我正在尝试在 Rspec 中运行此 watir 代码,并且我正在尝试并行运行测试用例.但它一个接一个地运行.无论如何我可以实现并行运行吗?
I am trying to run this watir code in Rspec and also I am trying to run the testcases in parallel. But it runs one after another. Is there anyway I can achieve the parallel run?
require 'rspec'
require 'watir'
a=[]
2.times do
a<<Thread.new do
describe 'My behaviour' do
it 'should do something' do
b = Watir::Browser.new
b.goto 'www.google.com'
b.text_field(name: 'q').set 'Rajagopalan'
b.close
end
end
end
end
a.each(&:join)
但是如果我在没有 Rspec 的情况下运行相同的代码,它会并行运行.例如,考虑下面的代码
But if I run the same code without Rspec, it runs in parrellel. For an example, consider the below code
require 'rspec'
require 'watir'
a = []
2.times do
a << Thread.new do
b = Watir::Browser.new
b.goto 'www.google.com'
b.text_field(name: 'q').set 'Rajagopalan'
b.close
end
end
a.each(&:join)
推荐答案
在此代码中,您没有并行运行规范.您正在并行声明上下文.
In this code you're not running specs in paraller. You're declaring contexts in parallel.
换句话说,调用 it
或 specify
不会执行测试代码.该块正在被保存,然后由 rspec runner (我相信在这里的某个地方).这就是为什么 RSpec(例如)可以以随机顺序运行所有示例.
In other words, calling it
or specify
does not execute the test code. The block is being saved, and then executed by rspec runner (somewhere here I believe).That's why RSpec (for example) can run all the examples in a random order.
因此,要进行并行执行 - 您需要做的不仅仅是示例代码.请参阅另一个答案中完全做到这一点的项目示例.
So, to have parallel execution - you need to do much more than your example code. See examples of projects that do exactly that in the other answer.
这篇关于如何在 Windows 机器上使用 RSpec 和 Watir 运行并行测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!