I'm trying to do functional testing using Selenium Webdriver.

I'm using ruby code to test on multiple windows at the same time using multi-threading

The problem is when the thread creates the new window, the other window will lose focus and the send keys process from that window fill stop and the test fails.

How can I handle this window focus issue?


Note: every browser window has its own driver instance

Update :

here How I create the thread

    while testIndex < testCases.length #  End when every testcase has been tested
        if(Thread.list.count<threadLimit+1) # if thread slot available 
            th[testIndex] = Thread.new(testIndex){ |i| # Create Thread
                # get testCase input
                # initiate driver and run test
                # I have wraper for this, and there is no thread inside it, just single thread code

            t.join # Wait unfinished thread
rescue Exception => e
    puts "MESSAGE: #{e}"

Update II

Trying to investigate the issue again based on @Leon comment. and it's work, but just in Chrome it's failing in IE, FF, dan Phantom

The errors such as :

  • CSRF token error (IE) - already using cleanSession and private, work on single thread test so it's not the web code error, this make selenium fail to find element which caused the script stoped,
  • Unable to bind to locking port 7054 (Firefox),
  • Unable to bind to locking port 8909 (Phantom)

Update III

Updated my selenium to 3.4 , the errors is gone. But the weird things is only phantomjs don't execute it concurrently.

  • Updates title to be about multiple windows. It said browsers which made me think of firefox, chrome, Safari, etc. – Michael Durrant Jul 21 '17 at 10:58
  • Are you using capybara ? – Michael Durrant Jul 21 '17 at 11:16
  • nice icon also btw – Michael Durrant Jul 21 '17 at 11:17
  • @Michael I'm using plain selenium webdriver – Sunu Pinasthika Fajar Jul 21 '17 at 13:51
  • 1
    What you used exactly to initiate multi-threading,what your relevant code looks like? I use java for my tests and by making tasks that include the testing code I want (on their own driver instance) and feeding them to a multiple thread executor work just fine. If every browser window has its own driver instance, what you described shouldnt happen, being on focus isnt a requirement to run selenium be it single-threaded or multi-threaded. You should be able to have the windows in background and they should work just fine. – Leon Jul 21 '17 at 14:07


Please review this, I have used multithreading based programming to run several web drivers

| improve this answer | |
  • Hi thanks for the example. but are you already test it using phantomjs? because the problem is when executed on phantomjs driver. This is an old problem, I already abandon it, it's better using framework after all I guess :). but thanks for your answer – Sunu Pinasthika Fajar Jul 14 at 11:51
  • I use selenium for the scraping purpose only and this code works good with chrome. I have not tested it for phantomjs. – Lakshyaveer Chaudhary Sep 8 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.