/ Webdriverio

Override user location in WebdriverIO/Selenium

Need to test specific visitor locations for your website?

Just add the following code to your wdio.conf.js config:

function overrideGeolocation(coords) {
  navigator.geolocation.getCurrentPosition = function(success, failure) {
    success({coords, timestamp: Date.now() });
  }
}

exports.config = {
  ...
  before: function before() {
    browser.execute(overrideGeolocation, {
      latitude: 29.97, longitude: 31.13
    });
  } 
  ...
};

Change the lat/long to be what you need it to be.

This could easily be turned in to a WebdriverIO Service... now that's an idea.

Helpful links: