How do I enable geolocation support in chromedriver? How do I enable geolocation support in chromedriver? selenium selenium

How do I enable geolocation support in chromedriver?


In the known issues section of the chromedriver wiki they said that you Cannot specify a custom profile

This is why it seems to me that @Sotomajor answer about using profile with Chrome as you would do with firefox will not work.

In one of my integration tests I faced the same issue. But because I was not bothering about the real geolocation values, all I had to do is to mock window.navigator.gelocation

In you java test code put this workaround to avoid Chrome geoloc permission info bar.

chromeDriver.executeScript("window.navigator.geolocation.getCurrentPosition =     function(success){         var position = {"coords" : {                                       "latitude": "555",                                        "longitude": "999"                                     }                         };          success(position);}");

latitude (555) and longitude (999) values here are just test value


Approach which worked for me in Firefox was to visit that site manually first, give those permissions and afterwards copy firefox profile somewhere outside and create selenium firefox instance with that profile.

So:

  1. cp -r ~/Library/Application\ Support/Firefox/Profiles/tp3khne7.default /tmp/ff.profile

  2. Creating FF instance:

    FirefoxProfile firefoxProfile = new FirefoxProfile(new File("/tmp/ff.profile"));FirefoxDriver driver = new FirefoxDriver(firefoxProfile);

I'm pretty sure that something similar should be applicable to Chrome. Although api of profile loading is a bit different. You can check it here: http://code.google.com/p/selenium/wiki/ChromeDriver


Here is how I did it with capybara for cucumber tests

Capybara.register_driver :selenium2 do |app|        profile = Selenium::WebDriver::Chrome::Profile.new  profile['geolocation.default_content_setting'] = 1  config = { :browser => :chrome, :profile => profile }      Capybara::Selenium::Driver.new(app, config)end

And there is link to other usefull profile settings: pref_names.cc

Take a look at "Tweaking profile preferences" in RubyBindings