FirefoxDriver and Geolocation Permissions

1,144 views
Skip to first unread message

Oliver Stewart

unread,
Mar 15, 2012, 7:01:17 PM3/15/12
to Selenium Users
Does anyone know if it's possible to add a permission setting in
Firefox via Selenium/WebDriver? Specifically, I'm trying to test
pages that use the geolocation API, so I both need to fake my location
to a predictable lat/long and to set the browser to allow the location
to be provided to the page. Absent the latter, it hangs on a
permission dialog when the geolocation JavaScript runs.

Right now I have code (in Scala, using the Java API) that fakes the
location:

val profile = new FirefoxProfile()
profile.setPreference("geo.wifi.uri", """data:application/json,
{'location':{'latitude':""" + TestLatitude + """,'longitude':""" +
TestLongitude + """,'accuracy':44}}""")
val driver = new FirefoxDriver(profile)

I haven't found a way to authorize sharing my location with this page,
however, and I'd like to avoid having to create a special profile
manually for each development/build environment in which I want to run
the tests.

Thanks,
Oliver

Krishnan Mahadevan

unread,
Mar 16, 2012, 2:19:48 AM3/16/12
to seleniu...@googlegroups.com
Oliver,
I havent worked on this, but would like to know how do you do it manually. If its a setting that is getting appended to prefs.js then you can create firefox profile and add preferences via your test code itself.


More inline comments below.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



Unlike Selenium1, Selenium2 treats a firefox profile as part of the test code and not part of the test environment, which means you can create a firefox profile, and use that firefox profile against grid runs as well.

 
Thanks,
Oliver

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Oliver Stewart

unread,
Mar 16, 2012, 11:51:22 AM3/16/12
to Selenium Users
By "manually", I mean create a new profile, open the browser UI and
visit the page, select "always allow" when it asks to send location
information to this site, then close the browser and use that saved
profile in my tests. From what I can tell, this has the effect of
adding a "permissions" entry in the Firefox profile, which seems to be
distinct from preference data. It doesn't seem like you can add
permission values by setting preferences, though if anyone knows
otherwise, I'd love to hear about it.

In my case, I'm not using a grid, just a headless build server (for
now). Still, I'd like the build to work out of the box, rather than
having a bunch of manual steps needed to successfully run tests, and
performing these steps on the headless build server is a bit
complicated.

Thanks,
Oliver

On Mar 16, 2:19 am, Krishnan Mahadevan
<krishnan.mahadevan1...@gmail.com> wrote:
> Oliver,
> I havent worked on this, but would like to know how do you do it manually.
> If its a setting that is getting appended to prefs.js then you can create
> firefox profile and add preferences via your test code itself.
>
> More inline comments below.
>
> Thanks & Regards
> Krishnan Mahadevan
>
> "All the desirable things in life are either illegal, expensive, fattening
> or in love with someone else!"
>

Oscar Rieken

unread,
Mar 16, 2012, 1:28:03 PM3/16/12
to seleniu...@googlegroups.com
I think this --experimental-location-features
is the switch to enable it so when you create the browser maybe passing that switch will enable it
http://peter.sh/experiments/chromium-command-line-switches/
Reply all
Reply to author
Forward
0 new messages