3

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?

Thanks

Note: every browser window has its own driver instance

Update :

here How I create the thread

begin
    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
            }
        end
    end

    th.each{|t| 
        if(!t.nil?)
            t.join # Wait unfinished thread
        end
    }
rescue Exception => e
    puts "MESSAGE: #{e}"
end

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.

10
  • Updates title to be about multiple windows. It said browsers which made me think of firefox, chrome, Safari, etc. Jul 21, 2017 at 10:58
  • Are you using capybara ? Jul 21, 2017 at 11:16
  • nice icon also btw Jul 21, 2017 at 11:17
  • @Michael I'm using plain selenium webdriver Jul 21, 2017 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, 2017 at 14:07

1 Answer 1

1

https://github.com/choudharylakshyaveer/SeleniumThreadedAutomation.git

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

2
  • 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 Jul 14, 2020 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. Sep 8, 2020 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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