Search code examples
rubyrspecwatir

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


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)

Solution

  • 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.