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.
-
Updates title to be about multiple windows. It said browsers which made me think of firefox, chrome, Safari, etc.Michael Durrant– Michael Durrant2017年07月21日 10:58:41 +00:00Commented Jul 21, 2017 at 10:58
-
Are you using capybara ?Michael Durrant– Michael Durrant2017年07月21日 11:16:24 +00:00Commented Jul 21, 2017 at 11:16
-
nice icon also btwMichael Durrant– Michael Durrant2017年07月21日 11:17:09 +00:00Commented Jul 21, 2017 at 11:17
-
@Michael I'm using plain selenium webdriverSunu Pinasthika Fajar– Sunu Pinasthika Fajar2017年07月21日 13:51:35 +00:00Commented Jul 21, 2017 at 13:51
-
1What 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– Leon2017年07月21日 14:07:33 +00:00Commented Jul 21, 2017 at 14:07
1 Answer 1
https://github.com/choudharylakshyaveer/SeleniumThreadedAutomation.git
Please review this, I have used multithreading based programming to run several web drivers
-
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 answerSunu Pinasthika Fajar– Sunu Pinasthika Fajar2020年07月14日 11:51:58 +00:00Commented 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.Lakshyaveer Chaudhary– Lakshyaveer Chaudhary2020年09月08日 20:18:52 +00:00Commented Sep 8, 2020 at 20:18