SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
345 stars 195 forks source link

Focus and blur events not fired when browser has no focus #7346

Open lukeis opened 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 7346

What steps will reproduce the problem?
1. Start test suite
2. Let the browser window be in background
3. Let selenium fill out some input fields

What is the expected output? What do you see instead?

While selenium fills out browser fields, no `focus` or `blur` event is triggered like
it would be for a real user.

Selenium version: selenium-webdriver (2.41.0), ruby
OS: OSX 10.9.3 beta
Browsers: Firefox 29

To reproduce this without selenium, simply see http://fiddle.jshell.net/WPpPy/34/ -
when the browser is not focused, the blur and focus event do not happen. Browser act
the same expect Safari.

I suspect this is because you cannot focus an input when the browser is not focused,
so later you cannot blur an input that is not focused.

I ran into this issue when testing my webpage with selenium - it starts up the browser
(firefox) and fills in the input fields (ruby bindings with capybara):

    visit '/some/web/page'
    fill_in "user_password", :with => 'password'
    fill_in "user_password_confirmation", :with => 'different_password'
    fill_in "user_name", :with => 'username'
    click_button "submit"

The `fill_in`s only trigger `focus` and `blur` events when the browser window is focused.
This means, the page behaves differently whether or not the browser is focused - so
for the test to simulate a real person, the browser window must be focused and the
tests cannot run in background.

Is there any workaround for this? Should selenium trigger `focus` and `blur` events
by itself? Or should the doc be updated to remind people to have the browser focused
during tests (or is there already such a hint I did not stumble upon?)?

Reported by markus.doits on 2014-05-14 08:12:40

lukeis commented 8 years ago
Yes, it is the way the browsers work. Selenium does not modify this behaviour. What
part of the documentation do you think is the most appropriate to mention this fact
in?

Reported by barancev on 2014-05-14 12:34:14

lukeis commented 8 years ago
I'm not sure where the correct place in the docs is, but it should be somewhere prominent.
Maybe on that page: http://docs.seleniumhq.org/docs/03_webdriver.jsp - but if there
is some FAQ section (I do not see atm), something like "my page behaves differently
when the browser is driven by selenium than with a real user - what to do? Answer:
It might be because the browser is not focused ...".

It actually means that you have to run tests in foreground. So you cannot start your
tests and let them run while you do something other on the pc. That is very important
to know, because else you get false results.

One could also argue that selenium fills out fields that have no focus - this is impossible
for a real user, so it is not doing things as a real user. But maybe that is not the
goal of selenium (to simulate a "real user"), then this would be fine and no problem
for selenium. But it should be mentioned that if selenium is used for automated browser
tests (where the browser obviously should behave like a "real user"), the browser window
must be in foreground.

Maybe the browser could implement a feature to behave like in foreground when selenium
is driving them. Afaik selenium now uses native browser hooks to drive it? Then there
might be a chance to implement such native hook to force the browser to behave like
if it where in foreground (which could be exposed for the selenium user as a method
to manually enable it).

Reported by markus.doits on 2014-05-15 11:11:29

lukeis commented 8 years ago

Reported by barancev on 2014-05-15 14:10:46

lukeis commented 8 years ago
I am facing the exact same issue with my Project, is there a workaround for this?

Reported by jasleenss on 2015-09-14 22:06:52

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 17:46:58