How to run parrellel tests with RSpec and Watir on a Windows machine?

徘徊边缘 提交于 2019-12-11 15:05:05

问题


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)

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)

回答1:


In this code you're not running specs in paraller. You're declaring contexts in parallel.

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.




回答2:


Use the Parallel Test gem or Parallel Split Test gemfrom a Rake Task. You can see an example in this sample code.



来源:https://stackoverflow.com/questions/56083800/how-to-run-parrellel-tests-with-rspec-and-watir-on-a-windows-machine

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!