I have this simple example:
require 'watir-webdriver' arr = [] sites = [ "www.google.com", "www.bbc.com", "www.cnn.com", "www.gmail.com" ] sites.each do |site| arr << Thread.new { b = Watir::Browser.new :chrome b.goto site puts b.url b.close } end arr.each {|t| t.join}
Every time I run this script, I get
ruby/2.1.0/net/http.rb:879:in `initialize': Connection refused - connect(2) for "127.0.0.1" port 9517 (Errno::ECONNREFUSED)
Or one of the browsers unexpectedly closes with at least one of the threads.
on the other hand, if I set sleep 2 at the end of each cycle of the cycle, everything runs smoothly! Any idea why?
There must be something to do with understanding how threads work ...
source share