Set Geolocation for Tests in Chrome & Firefox


For setting the location of the Test Environment where the Tests are run, we just need to add a pair of Desired Capabilities in the Test Environment.

You should already know how to add Desired Capabilities to your Tests. Refer to the documentation on configuring desired capabilities


Setting Desired Capabilities in different Browsers

Google Chrome

Here are the Desired Capabilities you need to add in Test Environment to set the location for Chrome Browser:

Name Data Type Value
goog:chromeOptions String {"profile.default_content_setting_values.geolocation":1}
geolocation String 51.50735, -0.12776, 100

You need to keep the first-row item as it is. In the second row item, the three values correspond to the parameters latitude, longitude and altitude, respectively.

The given value i.e 51.50735, -0.12776, 100 is for 'Trafalgar Square, London'.

Similarly, the value for 'Central Park, NYC, USA' is 40.783840, -73.965550, 33

Firefox

Here are the Desired Capabilities you need to add in Test Environment to set the location for Firefox Browser:

Name Data Type Value
firefoxprofile String {
"geo.prompt.testing": true,
"geo.prompt.testing.allow": true,
"geo.enabled": true,
"geo.wifi.uri": "data:application/json, {
 \"location\": {
  \"lat\": 34.052235, \"lng\": -118.243683
  }, \"accuracy\": 100.0
 }"
}

The value in the location under geo.wifi.uri corresponds to the parameters latitude, longitude, and accuracy.

The given value i.e {"location": {"lat": 34.052235, "lng": -118.243683}, "accuracy": 100.0} is for the location 'Downtown, Los Angeles, California 90012, United States'.

Similarly, the value for the location 'Central Park, NYC, USA' will be {"location": {"lat": 40.783840, "lng": -73.965550}, "accuracy": 100.0}

NOTE:

Setting the Geolocation is not yet supported in IE and Safari


Example websites to test current location

You can use https://www.mapcoordinates.net/en for the latitude and longitude information for your desired location, and https://mycurrentlocation.net/ to check current location.