Skip to main content

Simulate Geolocation

Learn how to simulate the location of browsers using the IP Geolocation feature for your Cypress tests.

IP Geolocation is an Enterprise-only feature. You can contact sales to get an Enterprise plan for your account.

BrowserStack’s IP geolocation feature allows you to simulate website behavior from different locations using IP addresses hosted in 45+ countries around the world. By incorporating IP geolocation into your tests, you can verify scenarios such as localized pricing, languages, product listings, and so on.

With IP geolocation enabled, traffic from your web app will originate from an IP address hosted in the country you have selected.

In this guide, you will learn about:

IP Geolocation feature is available in browserstack-cypress-cli v 1.12.0 or above. Run npm i -g browserstack-cypress-cli to ensure that the latest version is used.

Your application under test will see all traffic originating from the country that you have specified, for all the specs in the build.

Set the geolocation capability using browserstack.json

Add the geoLocation key and the country code within the run_settings object in the browserstack.json file as shown in the following code snippet:

//browserstack.json
...
"run_settings": {
  ...
    "geolocation": "<country_code>"
  ...
}
...

Check out the list of countries and country codes supported by BrowserStack for IP Geolocation.

Set the geolocation capability using the CLI

To use the CLI to simulate a specific geolocation from the available list of countries for your Cypress tests, the sample command is as follows:

Command Line
browserstack-cypress run --geolocation <country_code>

If you want to test multiple spec files originating from different locations, it cannot be achieved in the same build. However, you can split your test build into multiple spec files, and run each spec individually with the your desired location, as displayed in the following sample command:

Command Line
# Run a single spec from USA
browserstack-cypress run --geolocation US --spec spec A

# Run a single spec from France
browserstack-cypress run --geolocation FR --spec spec B

# Run a single spec from United Kingdom
browserstack-cypress run --geolocation UK --spec spec C

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Download Copy