Can I force Cypress to use a specific IP address?

Viewed 2066

I'm trying to force my automation to use specific ip address in Cypress. I made changes to cypress.json but doesn't seem to be working. Any ideas?

3 Answers

Can you explain more detailed what you wanted with that ip ?

In many cases baseURL is localhost or 127.0.0.1 - this will work anytime because is "your computer" (loopback).

You can use ip that is assign to your network, but be careful because it can change.

Also I wanted to force cypress to "see" me as different ip, from different region, but this is possible only if using VPN (on linux you have windscribe; in windows you have Hotspot Shield)

If you are looking for proxy configuration then the Cypress docs talk about that at length. This is essentially achieved by setting environment variables in the machine which runs the test, eg:

export HTTP_PROXY=http://my-company-proxy.com

See the docs: https://docs.cypress.io/guides/references/proxy-configuration

If (like me) you were looking for a way to make Cypress believe that the site was being visited from a different country (for example, if you want to test that tracking consent works as expected from region to region) then you will have to find a way to do this in the environment that Cypress runs in (using a vpn or actually hosting the test to run elsewhere). https://github.com/cypress-io/cypress/discussions/16171

There is a baseUrl variable in the cypress.json file, where you should be able to set the Url, for example:

{
"baseUrl": "https://127.0.0.1",
"video": false,
"chromeWebSecurity": false,
"testFiles": "**/*.spec.js"
}

Check also environment variables, keep in mind that variables in cypress.env.json will overwrite values in the cypress.json file.

Related