PiratProxies

Automation and testing

Sending Cypress traffic through a proxy

Cypress runs end-to-end tests in a browser. It reads its proxy from environment variables, set before Cypress starts.

What a proxy does for Cypress

Running your tests through a proxy shows how your site behaves for a visitor in another country: prices, language, consent banners and blocked content.

The right proxy type for Cypress

Any plan with the country you want to test from. Use a sticky session so one run is one visitor.

The values to enter in Cypress

Every PiratProxies plan comes down to four values: host, port, username and password. Here they are for Residential; your own username and password are on your plan page.

Hostresi.piratproxies.com
HTTP port8080
SOCKS5 port1080
UsernameUSERNAME
Passwordshown on your plan page

Written as a single address:

http://USERNAME:PASSWORD@resi.piratproxies.com:8080

There is no separate country or session field: both are part of the username. Your plan page has a generator that writes it, and Targeting and sessions describes each piece.

Setting it up in Cypress

  1. Set HTTP_PROXY and HTTPS_PROXY to the proxy address in the shell.
  2. Start Cypress from that same shell.

Code: Cypress through a proxy

macOS and Linux

export HTTP_PROXY=http://USERNAME:PASSWORD@resi.piratproxies.com:8080
export HTTPS_PROXY=http://USERNAME:PASSWORD@resi.piratproxies.com:8080
npx cypress run

Windows PowerShell

$env:HTTP_PROXY = "http://USERNAME:PASSWORD@resi.piratproxies.com:8080"
$env:HTTPS_PROXY = "http://USERNAME:PASSWORD@resi.piratproxies.com:8080"
npx cypress run

Put your own login from the plan page in place of USERNAME and PASSWORD. The example calls an IP-check service, so what it prints is the address your request came from.

Should Cypress rotate IPs or keep one?

When Cypress plays one visitor across several steps, a sticky session keeps the IP address unchanged from start to finish. When every run stands alone, drop the session and each run begins from a new address.

Here is what a sticky username looks like:

USERNAME-country-us-time-600-session-a1b2c3d4

When Cypress will not connect

  • Set NO_PROXY=localhost,127.0.0.1 as well if your tests also talk to a server on your own machine.
  • Use a sticky username, so every request of one test run comes from the same visitor.
  • Error 407 means the login was refused. Copy the username and password from your plan page once more, and make sure no space crept in and the username was not cut short.
  • An IP in the wrong country nearly always comes from the username, since the country code lives there. Other fixes.

Cypress and proxies: questions

Which PiratProxies plan suits Cypress best?

Any plan with the country you want to test from. Use a sticky session so one run is one visitor.

Words used in this guide: headless browser, rotating proxy, sticky session, proxy authentication.

Cypress belongs to its own developers, and PiratProxies has no connection with them; we name it only to say what this guide covers. Follow the rules of the sites you visit and our acceptable use policy.