Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always Allow Geolocation in Firefox using Selenium

I am creating some end-to-end tests for a web app using Selenium.

I am working in Python and using the Firefox driver

driver = webdriver.Firefox()

The problem is that my web app using HTML5 geolocation, and it seems that everytime I run my tests, I have to click the 'Allow Location' popup in Firefox, making my tests less than automated.

Is there a way to force the Selenium Firefox driver to always allow geolocation without prompting?

like image 351
Michael Robinson Avatar asked Apr 30 '13 05:04

Michael Robinson


1 Answers

You can force browser to return some predefined location without permission requests.

Just execute the following JavaScript code:

"navigator.geolocation.getCurrentPosition = function(success) { success({coords: {latitude: 50.455755, longitude: 30.511565}}); }"

Tested in Firefox and Chrome.

like image 157
deadmoto Avatar answered Sep 29 '22 21:09

deadmoto