Mock the geolocation of the browser. Call without any arguments to reset the geolocation back to original.

setGeolocation() is only available when using Chrome or Edge drivers.

Usage

.setGeolocation({latitude, longitude, accuracy}, [callback])

Parameters

Name Type description
coordinates
Optional
object

Latitude, longitude, and accuracy.

callback
Optional
function

Callback function to be called when the command finishes.

Example

 describe('mock geolocation', function() {
   it('sets the geolocation to Tokyo, Japan and then resets it', () => {
     browser
       .setGeolocation({
         latitude: 35.689487,
         longitude: 139.691706,
         accuracy: 100
       })  // sets the geolocation to Tokyo, Japan
       .navigateTo('https://www.gps-coordinates.net/my-location')
       .pause(3000)
       .setGeolocation()  // resets the geolocation
       .navigateTo('https://www.gps-coordinates.net/my-location')
       .pause(3000);
   });
 });

Recommended content