Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Instances of Firefox during Selenium Webdriver Testing not handling focus correctly.

I have noticed that while running multiple selenium firefox tests in parallel on a grid that the focus event handling is not working correctly. I have confirmed that when each of my tests is run individually and given focus of the OS the tests pass 100% of the time. I have also run the tests in parallel on the grid with Chrome and not seen the issue present.

I have found the following thread on google groups which suggests launching each browser in a separate instance of xvfb may be a viable solution. https://groups.google.com/forum/?fromgroups#!topic/selenium-developers/1cAmsYCp2ho%5B1-25%5D

The portion of the test is failing is due to a jquery date picker which is used in the project. The date picker launches on a focus event and since there are multiple selenium tests executing at the same time the webdriver test executes the .click() command but focus does not remain long enough for the date picker widget to appear.

.focus(function(){ $input.trigger("focus"); });

  • jQuery timepicker addon
  • By: Trent Richardson [http://trentrichardson.com]

My question is if anyone has seen this before and solved it through some firefox profile settings. I have tried loading the following property which had no affect on the issue.

profile.setAlwaysLoadNoFocusLib(true);

The test fails in the same way as it did before with that property enabled and loaded in the Remote Driver Firefox Profile.

I need a way ensure the focus event is triggered 100% of the time or to solve the issue of multiple firefox browsers competing for focus. Considering Chrome displays none of these issues I wonder if it may also be considered a bug in firefox.

Thanks!

like image 204
jjhughes57 Avatar asked Aug 15 '12 17:08

jjhughes57


2 Answers

@djangofan: Wrong. You cannot lock the focus. After you requested focus in one window and before you trigger an action, another window requests focus, and your action (like sending keys to input field) just doesn't work. This happened in our tests several times daily. It was hard to reproduce, because with each test run it failed on different places. A solution is to execute each browser in a separate display. E.g. you can use Xvfb:

  Xvfb ... -screen 1 1200x800x24 -screen 2 1200x800x24 ...

Then when you start a browser, assign a separate screen to it:

  browser.setEnvironmentProperty("DISPLAY", ":N.1");
  browser.setEnvironmentProperty("DISPLAY", ":N.2");
  ...
like image 88
mentallurg Avatar answered Sep 18 '22 13:09

mentallurg


I've had the same issue in my continuous integration environment with Jenkins. After a long research i found an old bug in firefox that led to a new config flag to avoid those problems.

The solution is to enable this flag on the firefox profile that the tests use. The flag is focusmanager.testmode, set it to true.

enter image description here

The explanation is that the focus events are triggered only when firefox window is active. If you run multiple test you have multiple windows so only the active one triggers the focus events. With this param the events are trigered even for non active windows.

like image 28
Ricardo Vila Avatar answered Sep 19 '22 13:09

Ricardo Vila