1

I am writing a web application that depends heavily on geolocation. I am using chimpjs (combination of cucumber, webdriverio, chai) to do my BDD. I would like to launch google chrome with geolocation allowed. I think I must do this because I can find no way to click the Allow button in chrome to allow geolocation.

I have a chimp.js config file in my cucumber directory. Here are its contents:

module.exports = {
  webdriverio: {
    desiredCapabilities: {
      chromeOptions: {
        deviceName: 'Google Nexus 5'
      }
    }
  },
  browser: 'chrome',
  watch: false,
  path: './features',
  chai: true,
  screenshotsPath: '.screenshots'
};

I know that:

  • chrome uses profile information that may be provided around runtime
  • there is an option 'geolocation' which must be set to 1
  • some other relevant nesting are 'prefs' and 'default_content_setting_values', which I learned about from digging through my chrome preferences

What I cannot figure out is which among these need to be passed to chromeOptions, and what needs to be nested where.

I am sure I cannot be the only person who ever needed to launch chrome with webdriver and have geolocation enabled.

RedMage
  • 1,056
  • 1
  • 8
  • 20

2 Answers2

1

You can simply configure this in chromeOptions with profile.default_content_setting_values.geolocation.

chromeOptions: {
  deviceName: 'Google Nexus 5'
  prefs: {
    "profile.default_content_setting_values.geolocation": 1,
  }
},
Abhijith Sasikumar
  • 4,490
  • 4
  • 24
  • 37
  • 1
    This one fixed it for me. Although I used it like this: chromeOptions: { prefs: { 'credentials_enable_service': false, 'profile': { 'password_manager_enabled': false, 'default_content_setting_values': { 'geolocation': 1 } } } } – Thomas Theunen Apr 25 '18 at 09:18
0

This question is a duplicate of this one: How do I enable geolocation support in chromedriver for Selenium?

I've translated the answer to WebdriverIO syntax:

browser.execute(function() {
  window.navigator.geolocation.getCurrentPosition = function(success) {
    var position = { coords : { latitude: "40.748440", longitude: "-73.984559" } }; 
    success(position);
  }
});
Community
  • 1
  • 1
Xolv.io
  • 2,373
  • 1
  • 12
  • 17