Cypress: Support proxies and improve proxy performance

Created on 16 Mar 2018  路  22Comments  路  Source: cypress-io/cypress

Problem

There are several users with corporate proxy issues that are faced at several layers of interacting with Cypress including during:

(a checkmark indicates that a fix is in #3531)

  • cy.visit()

    • [x] #1459

    • [x] #1608

    • [x] #1312 - described behavior is correct

    • [x] #1039 - this timeout will be fixed once we respect proxies, but the error should still be passed through - #1013

    • [x] #939

    • [x] #672

  • npm install

    • [x] #733

  • cypress verify (maybe?)

    • [x] #787 - not a proxy issue, but the issues described in comments are, and will be fixed

  • accessing the 'Runs' tab within the Test Runner

    • [x] #1470

  • verifying that the server set at baseUrl is running

    • [x] #1541

Things that won't be fixed as part of this issue

  • PAC support - workarounds exist, see https://on.cypress.io/proxy-configuration
  • #584 - SOCKS proxy - more in-depth changes would be required to add SOCKS support - workarounds exist, see https://on.cypress.io/proxy-configuration
  • #1352 - SSL verification issue
  • #1401 - SSL verification issue - NODE_EXTRA_CA_CERTS not being used in cy download
  • #1438 - cy proxy hiding the actual issue
  • #1013 - network errors mishandled - related: #1036
  • #1253 (dupe: #3124, #1468) - system policy - could potentially either bypass (hard) or warn the user (easy) or only allow electron - workarounds exist

Current workarounds:

Setting environment variables

Note: these are NOT cypress environment variables, but system/shell environment variables

  • If using Linux, you can read about setting and reading env variables here
  • If using Windows, you can read about setting and reading env variables here

Set HTTP_PROXY and/or HTTPS_PROXY to your corporate proxy

HTTP_PROXY=http://my-proxy-address cypress run

Set NO_PROXY for localhost to prevent it from hitting corporate proxy

NO_PROXY=localhost cypress run

Other workarounds

For cy.visit()

For Download

For accessing 'Runs' tab in Test Runner

  • If you need to set up a project, you have to do it in this tab. Fortunately, you should only need to do this once. Try to do this once outside of the corporate proxy then you should be good to go.
Epic 5锔忊儯 bug

Most helpful comment

I've read everything I can find on this issue and tried every suggested workaround but Cypress still cannot connect to websites through our corporate proxy.

When will this feature be implemented? It is a massive blocker for any possibility of adoption within our team.

All 22 comments

setting the environment variables was very helpful for the npm install on Mac. thx for workaround

Tried setting env using cross-env HTTPS_PROXY=<my corp proxy> as well as HTTP_PROXY, but request to external resource gets http 407. I am using cntlm and set proxy to go through cntlm, but still unable to get CDN resources, e.g. google fonts

Tried do this:

PROXY_HTTP="http://proxy.adress" PROXY_HTTPS="https://proxy.adress" npx cypress run --spec cypress/integration/ah-ui.js -b chrome

With electron too, added rules in extension, add extension with VPN, added proxy settings in chrome...
but it doesn't work for me - best result - I can open url in new tab.
In Cypress test I receive -

CypressError: cy.visit() failed trying to load:

https://mytestsite

The content-type of the response we received from your web server was:

  > null

This was considered a failure because responses must have content-type: 'text/html'

I've read everything I can find on this issue and tried every suggested workaround but Cypress still cannot connect to websites through our corporate proxy.

When will this feature be implemented? It is a massive blocker for any possibility of adoption within our team.

@Rende11 See this comment regarding null content-type responses https://github.com/cypress-io/cypress/issues/1727#issuecomment-389891098

Did you try to set the corporate proxy into npm config? Like so: https://stackoverflow.com/a/33892578

Hi,

I am facing the same issue 403 Forbidden issue with an local application i.e. application running in localhost,

Error:

TEST
1
VISIT
http://localhost:4200/login
CypressError: cy.visit() failed trying to load:

http://localhost:4200/login

The response we received from your web server was:

  > 403: Forbidden

This was considered a failure because the status code was not '2xx'.

If you do not want status codes to cause failures pass the option: 'failOnStatusCode: false'

I have tried by providing proxy configurations in the cypress.json file, but no luck,

{
  "env": {
    "HTTP_PROXY": "http://my-proxy-address:port",        
    "HTTPS_PROXY": "http://my-proxy-address:port",
    "NO_PROXY": "localhost"
  }, 
  "defaultCommandTimeout": 10000  
}

Please let me know exact solution for this.

Thanks in advance.

@suryamangena Is the error coming from your application? What happens when you visit http://localhost:4200/login in your web browser?

FYI, you cannot set the *_PROXY environment variables from cypress.json. You'll need to define them in your shell.

On Mac or Linux, it's enough to do HTTP_PROXY=http://my-proxy-address:port NO_PROXY=localhost cypress open

If setting your environment variables does not fix it, there is currently not a released solution. I'm actively working on it though! :)

@flotwig, error is not coming from application. In my normal web browser, I am able to access the application without any issues in my company network. Problem is with cypress opened browser with same proxy settings.

I tried setting with environment variables in Windows machine, but no luck. Still i am seeing the same issue.

Eagerly waiting on new release with solution! :)

Thanks for the quick response.

@flotwig Same here. exactly the same behaviour. same problem. my application is working properly in my everyday browser, but when it comes to cypress, it can't access it. same for both chrome and headless browser.

Temp. Solution

I mapped localhost and 127.0.0.1 to localhost.com in my /etc/hosts file and added localhost.com as the base URL to Cypress.json file. With this way, Cypress can access to my app without any problem.

Maybe this workaround gives you some insight into the problem.

Thanks,

@suryamangrna @alioguzhan do your companies us a PAC file? https://en.wikipedia.org/wiki/Proxy_auto-config I believe that was the blocker to why I can't use Cypress at my company. I can set the HTTP_PROXY vars fine but our Network has a PAC file to determine how to connect to various domains. If Cypress could use a PAC file like our browsers I think we could finally get it working in my corporate network.

Thanks @alioguzhan. I will give out a try on provided solution.

@NickStees, I hope so my company may using PAC configuration.
I have to confirm with IT team.

The code for this is done in cypress-io/cypress#3531, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

Great to hear this is now pending release! I've recently started piloting Cypress at work with the goal of wider adoption and the speed issues we've been facing as a result of corporate proxy issues are the only thing currently holding us back.

Any idea when this might be released?

@rjd40 Soon. We have been working on the release - had to pause to fix some potential regressions in the pre-release. 馃

@jennifer-shehane Thanks for all the hard work on this, I have a quick question will this proxy improvement also include authentication for proxy? We have that use case since our corporate proxies require authentication with username and password.

@RicardoVaranda Yes, basic proxy authentication will be supported, just pass the proxy like so: http://username:[email protected]

Released in 3.3.0.

Cannot believe that setting a proxy can be this difficult :( - I have a corporate PAC file for a proxy and I tried setting the HTTP and HTTPS proxies through command prompt, nothing seems to work.

Agreed, I am not a developer, but the complexity might turn away many testers from setting up Cypress.

@sriram04144 Have you checked the proxy configuration docs? It explains how to work if all you have is a PAC file. You just need to set HTTP_PROXY to the proxy you need for outbound Internet access.

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

This issue will be closed to further comment as the exact issue here was resolved and tested.

If you're experiencing a bug similar to this in Cypress or want enhanced functionality for Proxy support, please open a new issue with a fully reproducible example that we can run or explaining the feature you would like.

Was this page helpful?
0 / 5 - 0 ratings