Simulate GPS location
GPS Geolocation testing enables you to simulate the location of the device to specific GPS coordinates in order to test location-based scenarios for your app.
Use the GPS location capability as shown in the following code sinppets to specify the GPS coordinates. You will be required to pass the latitude and longitude of the desired location.
GPS location feature for app testing is only available with a BrowserStack Paid plan. View details .
If you are using BrowserStack SDK, you can set the following capability within the browserstack.yml
file:
Capability
Description
Value
gpsLocation
Simulate the location of the device to a specific GPS location.
Latitude followed by longitude Acceptable range for latitude is -90 to +90 and for longitude is -180 to +180. Example: “40.730610,-73.935242”
```yml
gpsLocation: -73.935242,40.730610
```
Copy icon
Copy
gpsLocation : -73.935242 , 40.730610
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page .
Use the following code snippet to set the GPS location
Capability
Description
Value
gpsLocation
Simulate the location of the device to a specific GPS location.
Latitude followed by longitude Acceptable range for latitude is -90 to +90 and for longitude is -180 to +180. Example: “40.730610,-73.935242”
Example:
DesiredCapabilities capabilities = new DesiredCapabilities ( ) ;
HashMap < String , Object > browserstackOptions = new HashMap < String , Object > ( ) ;
browserstackOptions. put ( "gpsLocation" , "-73.935242,40.730610" ) ;
Copy icon
Copy
var capabilities = {
'bstack:options' : {
"gpsLocation" : "-73.935242,40.730610" ,
} ,
}
Copy icon
Copy
AppiumOptions capabilities = new AppiumOptions ( ) ;
Dictionary< string , object > browserstackOptions = new Dictionary< string , object > ( ) ;
browserstackOptions. Add ( "gpsLocation" , "-73.935242,40.730610" ) ;
Copy icon
Copy
$caps = array (
'bstack:options' => array (
"gpsLocation" => "-73.935242,40.730610" ,
) ,
)
Copy icon
Copy
desired_cap = {
'bstack:options' : {
"gpsLocation" : "-73.935242,40.730610" ,
} ,
}
Copy icon
Copy
capabilities = {
'bstack:options' = > {
"gpsLocation" = > "-73.935242,40.730610" ,
} ,
}
Copy icon
Copy
Capability
Description
Value
browserstack.gpsLocation
Simulate the location of the device to a specific GPS location.
Latitude followed by longitude Acceptable range for latitude is -90 to +90 and for longitude is -180 to +180. Example: “40.730610,-73.935242”
Example:
DesiredCapabilities desiredCapabilities = new DesiredCapabilities ( ) ;
capabilities. setCapability ( "browserstack.gpsLocation" , "-73.935242,40.730610" ) ;
Copy icon
Copy
var capabilities = {
"browserstack.gpsLocation" : "-73.935242,40.730610" ,
}
Copy icon
Copy
AppiumOptions capabilities = new AppiumOptions ( ) ;
capabilities. AddAdditionalCapability ( "browserstack.gpsLocation" , "-73.935242,40.730610" ) ;
Copy icon
Copy
$caps = array (
"browserstack.gpsLocation" => "-73.935242,40.730610"
)
Copy icon
Copy
desired_cap = {
"browserstack.gpsLocation" : "-73.935242,40.730610"
}
Copy icon
Copy
caps = Selenium : : WebDriver : : Remote : : Capabilities . new
caps[ "browserstack.gpsLocation" ] = "-73.935242,40.730610"
Copy icon
Copy
To change the GPS location during a test, use Appium’s geolocation commands as part of your test script. For details, refer Appium’s documentation .
Is this page helping you?
Thank you for your valuable feedback!