Disable hardware inputs on Selenium webdriver firefox - ruby

I have a ruby script to test a web page in Firefox. it sends mouse or keyboard events pragmatically to Browser but when hardware mouse is moved, it affects my test.
How can i configure Firefox to forget hardware mouse and keyboard events?

You could use Xvfb which will provide a virtual screen for Firefox to open in. Basically you start Xvfb with a screen number in and point Firefox at that screen by running export DISPLAY=:XX. You could use PhantomJS but I wouldn't recommend it because it's doubtful that any users will ever use it; better to test with a browser that people use.
Info on setting up Xvfb
http://www.installationpage.com/selenium/how-to-run-selenium-headless-firefox-in-ubuntu/
How do I run Selenium in Xvfb?

I recommend the headless browser PhantomJS. It works with webdriver and pretty much all Ruby testing tools. Being headless, you must send mouse and keyboard events programmatically. The user's mouse and keyboard will have no effect.
You will also notice that the tests are faster!

Related

Selenium test hangs on css transition when chrome window is sent to background on mac

I'm experiencing an annoying issue while running my behat selenium tests on my mac, El capitan.
I have a test that opens a modal that will hang if the chrome window is behind another window. As soon as I click on the chrome window to bring it to the front, the test continues and passes.
The modal uses a css transition to show. If I remove the transition, the test passes. If I keep a portion of the browser visible, the test passes.
I'm unsure if this is mac doing some kind of performance optimization or chrome. Anyone know of a way I can disable this? I'd rather not have to disable css transitions or run chrome headless.
Here I found a good article and it helped me to find some flags for Chromium:
--disable-renderer-backgrounding — Prevent renderer process backgrounding when set.
--disable-background-timer-throttling — Disable task throttling of timer tasks from background pages.
--disable-backgrounding-occluded-windows — Disable backgrounding renders for occluded windows. Done for tests to avoid nondeterministic behavior.
These flags really fixed the problem for me.
Some time ago I found mentioned and tried these flags --disable-gpu --disable-d3d11.
But they did not help.
More described flags can be found here.

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!
#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");
...
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.
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.
You can wrangle this and get it under your control with no problem. First write a method to identify the popup window by its window handle id. Then, use a JavaScriptExecutor to execute "window.focus()" in javascript to force the window to be focused just before you perform another action. Then, you can close the popup by its window handle name if necessary.

Is there any browser (Chrome, Firefox) plugin that allows to simulate geo location?

I need to test web application that extensively uses geo location api (getCurrentPosition, watchPosition). Is there any browser (Chrome, Firefox) plugin that allows to simulate geo location?
I am a bit late, but Microsoft Edge has this useful tab Emulation.
You can open this developer tool as usual hitting F12 button or by clicking on the browser's menu button, Developer Tools F12.
Geolocation:
Simulate a GPS receiver and enter GPS coordinates to test location-aware features in a webpage.
More info here at developer.microsoft.com
If I understood the question correctly and you're asking for a way to fake geolocation responses for your web app, you might be able to do this in Firefox by overriding the geo.wifi.uri in the prefs, like Firefox's unit tests do. See:
http://mxr.mozilla.org/mozilla-central/source/dom/tests/mochitest/geolocation/geolocation_common.js?force=1
http://mxr.mozilla.org/mozilla-central/source/dom/tests/mochitest/geolocation/network_geolocation.sjs?force=1 - the httpd.js script responding to requests of the geo.wifi.uri used in the tests.
Chromium 52 has it in-built:
Open developer console
Click the : button on the right, select More tools -> Sensors
In Tab "Sensors" you can modify the current location:

firefox kiosk mode : just 3 buttons needed

I've done the researched but I haven't found anything suitable.
I need firefox to start in so called kiosk mode that would result in :
fullscreen
no tabs
no right click
back home forward buttons
There are plugins like r-kiosk - can I configure them to display only 3 buttons that I need?
thanks
I've written a Firefox extension that does just this called Webconverger:
http://webconverger.org/kiosk/
http://en.wikipedia.org/wiki/Webconverger itself is a complete browser operating system with this "kiosk mode" extension loaded by default.
Use mKiosk firefox plugin. It's a Public Firefox Kiosk Mode with optional Tabs Guides for Access Point. Complete solution. Block downloads/addon, bookmarks, reset kiosk inactivity, retry on errors, restricted interface, show favorites as buttons and more...

How to close or minimize browser windows with Selenium RC?

Every time I launch a Firefox instance via Selenium RC I get 3 windows that I don't need appearing:
the add-ons windows notifying me that
"3 new add-ons have been installed"
(since I'm using a custom profile for
Selenium to which it evidently adds
the DocumentReadyState, KillFF, and
Selenium RC Runner add-ons)
the http://localhost:4444/selenium-server/core/Blank.html?start=true window
the dual window with two tabs starting with chrome://src/content/RemoteRunner.html?sessionId=... each
I don't need any of these to be visible, and each time I have to manually close the add-ons window, to minimize the two other windows, and to maximize the main browser windows which Selenium controls. After going through this too many times, I got annoyed enough to seek a solution:
Is there any way to automate closing the add-ons window and minimizing the two other windows?
By the way, I'm on OS X so I'd also appreciate some alternative solution which automates this via the OS instead of directly using Selenium.
There's a few preferences you can change in your custom profile to prevent the addons window and the additional tab on startup:
Set the extensions.lastAppVersion preference to the version of Firefox that you have installed.
Set the extensions.newAddons preference to false.
Set the extensions.update.notifyUser preference to false.
There might be some more, perhaps others can provide their suggestions in comments or their own answers.
As long as Selenium is running in multi window mode (the default mode) you'll get two browser windows. You could either maximize the main window using the following command:
selenium.windowMaximize();
Or use the multiWindow command line parameter to disable the use of multuple windows and just use a single window - note that this causes issues on some websites, especially if they attempt to break out of frames.

Resources