Ruby threads with Watir

I have several written classes that define how I want to handle several websites, with similar methods in both (e.g. login, refresh). Each class opens its own instance of the WATIR browser.

class Site1 def initialize @ie = Watir::Browser.new end def login @ie.goto "www.blah.com" end end 

the code sample is basically without threads as follows

 require 'watir' require_relative 'site1' agents = [] agents << Site1.new agents.each{ |agent| agent.login } 

This works fine, but will not move to the next agent until the current one completes the login. I would like to enable multithreading to handle this, but it doesn't seem to work.

 require 'watir' require_relative 'site1' agents = []; threads = [] agents << Site1.new agents.each{ |agent| threads << Thread.new(agent){ agent.login } } threads.each { |t| t.join } 

this gives me an error: unknown property or method: navigate . HRESULT error code: 0x8001010e. An application is called an interface that has been configured for another thread.

Does anyone know how to fix this, or how to implement similar functionality?

+6
source share
1 answer

Not quite sure about this, but here's a swing using threads.

 require 'thread' threads = [] # Setting an array to store threaded commands c_thread = Thread.new do # Start a new thread login # Call our command in the thread end threads << c_thread 
0
source

All Articles