Cypress: Cypress cannot load pages behind a corporate proxy

Created on 20 Sep 2017  路  65Comments  路  Source: cypress-io/cypress

  • Operating System: Mac OS 10.12.6
  • Cypress Version: 0.20.1
  • Browser Version: Chrome v61

Is this a Feature or Bug?

Feature

Current behavior:

When running on a machine that requires a corporate proxy, cypress does not use the proxy settings and therefore cannot access and run tests on pages behind the proxy.

Desired behavior:

Cypress should respect the internal proxy settings of the network. From Brian Mann in Gitter:

"right i think its something we'll have to take into account and upgrade
cypress does not respect the internal proxy settings of the network
it would just work if we took that into account though"

Additional Info (images, stack traces, etc)

Resolving this would allow teams behind corporate proxies to adopt the software.

5锔忊儯 pkhttps-proxy pkserver 馃槼 whoops there is no test to run question

Most helpful comment

we tried to add this to cypress.json, to no effect yet:

{
  "env": {
    "http_proxy": "http://my.corporate.proxy:8080",
    "https_proxy": "http://my.corporate.proxy:8080"
  }
}

In our case we get a 404 for a local URL which runs fine outside cypress.

Right now this is a blocker to use cypress on our teams. Are there any workarounds?

All 65 comments

Thank you for the great product!

Any news or workarounds on using Cypress behind a corporate proxy?

Cypress is an extension on chrome. I was running into the same issue and getting 503. I fixed it by enabling permissions on the extension. Upper right hand where the three dots for settings
screen shot 2017-10-19 at 9 37 55 pm
go to extensions and allow permissions
screen shot 2017-10-19 at 9 37 35 pm

screen shot 2017-10-19 at 9 39 47 pm

Thank you for the great product.

I am able to access all the general applications like facebook, gmail so on. Issue is with accessing my application which can be accessible only in my office network. I see runner is trying to invoke the URL but at the end gives an error 'Whoops there is no test to run'.

Other sample tests are running fine without any issues. I had a discussion with my IT team and they are not able to help me on this.

Any update on this issue??

@getluke have you seen @vjefri03 suggestion?

Same problem here.
image

@vjefri03 suggestion does not work for me.

Oddly, this works perfectly fine for me on a mac. I am VPN'd into my corporate network, which then forces me to use a proxy to go out to the internet.

My app loads just fine in Cypress, as do the resources coming off CDNs. I wonder why it would work for some of us and not others?

Similar setup here: mac with corporate VPN and proxy configured.

My app loads ok but CDN content times out.

Oops. I just created a new ticket describing the same issue as jivimberg, but I'm using Windows. Would be great to have this sorted out, as this testing framework seems to have many advantages over the others.

I just tried troubleshooting to see why my setup works when others' do not. I removed my proxy settings from the VPN network settings and experienced the same behaviour as the others (no external sites would load). Once I added them back, still no external sites would load.

The only way I've gotten things to work is by running the tests once while not connected to the VPN, then they seem to work correctly afterwards when connected to the VPN (this is obviously not a solution for people trying to use Cypress from work). So I am concluding that this never properly worked for me over the VPN, I just thought it did.

I would very much like to see this issue get fixed so my team can try using Cypress on a few projects :)

Let me know what I can do to help.

Since Cypress acts as a reverse proxy to the browser (which also ends up terminating traffic amongst other things), when it makes the external requests to 3rd party servers, it needs to respect the system proxy settings. That's why this is failing.

If Cypress proxied itself to the upstream proxy of the system, then all would work. This is likely a change that only needs to be made in a few places. The trick here is that we need a reproducible repo or the minimum steps to reproduce so we can write tests to ensure this is working.

Until someone does that, there are other things that will take priority over this feature.

Well isn't the requirement here for reproduction a VPN where a proxy is required to get out to the internet? It doesn't actually have anything to do with the repo itself, or am I missing something?

That is true. However, you could likely put together a repo involving a transparent or reverse proxy that the traffic must tunnel through before hitting a regular http server.

The thing here is that I'm not sure if Cypress is supposed to read off the "corporate proxy" settings from the operating system itself - or if we need to expose configuration via cypress.json or environment variables that enables you to specify what the proxy is.

In other words - help us implement the exact steps needed to reproduce the failing environment so we can implement a solution to it. Even referencing other tools that do work would be helpful so we can look at how they solve this.

I can't see why Cypress wouldn't automatically use the system's proxy settings when it can. That would be my vote. Its also what most apps have done in my experience sitting behind our pointless corporate proxy.

As an aside, I have also tried adding environment variables (http_proxy, https_proxy) to the env key of the cypress.json file but still they were not honoured.

Right - so we can definitely respect the http_proxy and https_proxy env variables - i just wasn't sure what Cypress would need to do to read off the system proxy settings (if these aren't set as env vars).

Can you do an experiment - open node (any version) and check process.env to see if http_proxy is set without you explicitly setting it.

Or you could also just do print_env. What I'm trying to determine is whether these environment variables are automatically added by the system proxy. If they are not, then we'll need to come up with a way to read them all. I haven't looked but there's probably already modules that do this...

No, I cannot see either http_ or https_proxy in process.env.

They are not added to node via the Mac OS X System Settings. They must be explicitly added to the environment in the shell, e.g., .zshenv. I'm not aware of node support for reading the system network preferences and exposing them as process variables, yet.

Update
I didn't have this gist handy鈥攂eing on the Enterprise GitHub we run鈥攖o show how the standard team, using zsh, sets their proxy for using node

How to manage the proxy in ZSH...or one way to do so at the very least.

I would be happy with this working from the cypress.json config. Is that a possibility?

Yes it looks like we can simply expose a new set of configuration in cypress.json for the proxy settings and also read them from process.env if they happen to be defined.

@brian-mann
please also enable setting strict-ssl, proxy and https-proxy in cypress.json as not all proxy have valid certificates

We already turn off strict SSL handling in Cypress since Cypress itself is a proxy that issues invalid on the fly certificates.

Can anyone reference me another application that exposes the kinds of proxy configuration settings that is required here? I am still at a loss as to how many fields would need to be added to cypress.json

How about npm ?

https://docs.npmjs.com/misc/config#https-proxy
https://docs.npmjs.com/misc/config#proxy

It turns out that setting HTTPS_PROXY env in windows also works.

@brian-mann see above ZSH proxy setter. At a minimum HTTP_PROXY, http_proxy, HTTPS_PROXY, and https_proxy.

In my corporate environment, all SSL connections are terminated at the proxy, so HTTPS and HTTP setting are identical. The UPPER and lower case versions are to cover a couple of edge cases where some programs don't recognize the conventions, e.g., npm apparently likes uses https-proxy (but looks for the underscore versions, as noted by @g00fy-).

After some experimentation, it appears cypress respects most of the environment proxy variables once they are set. If I set http_proxy before launching cypress, cypress respects the setting and sends traffic to the proxy first. The little gotcha here was that I also had to set the no_proxy variable to ensure that for localhost it did not attempt to use the proxy.

For some reason, resources over https were not sent through the proxy, even though I had also set the https_proxy variable. Perhaps I should be using some other variable? (I also tried HTTPS_PROXY)

@jivimberg Did you (or could you) try running cypress after setting both http_proxy and no_proxy and see if your setup can work as expected?

In summary, I think cypress should support at a minimum the following environment variables:
http_proxy
https_proxy
no_proxy

I tried with the 3 variables set and it's working!
Only thing that didn't work for me is with https requests, but maybe that's just my proxy settings?

Looks like i am experiencing the same behaviour on a centos container where i can curl towards an https url but if i set this as my baseUrl it does not work. HTTPS_PROXY and https_proxy both are set.

how do we fix this issue?

we tried to add this to cypress.json, to no effect yet:

{
  "env": {
    "http_proxy": "http://my.corporate.proxy:8080",
    "https_proxy": "http://my.corporate.proxy:8080"
  }
}

In our case we get a 404 for a local URL which runs fine outside cypress.

Right now this is a blocker to use cypress on our teams. Are there any workarounds?

@klentB setting no_proxy to localhost in npmrc and system env variables fixed our issue

Apparently Cypress cannot make Chrome connect to its reverse proxy if the proxy settings are blocked by your administration.

If you have administrative rights, check HKLM\Software\Policies\Google\Chrome:ProxyMode. In my case it was present and had the value system.

I deleted the entry to make the proxy settings available in Chrome, and Cypress started working.

In addition, you also may have to set a no_proxy=localhost setting in npmrc and a corresponding environment variable in the local machine settings.

If administration overrules even that and you cannot convince them not to forbid access to the Chrome proxy settings, then there is not much hope for Chrome on your machine. Options are to use a VM where Chrome is not under control of the admins or hope for #1096. I've made this a separate issue, maybe the developers have ways to solve this: #1253

A possible workaround is to switch to Electron using the Browser dropdown on the right hand side of the Cypress application window (which says Chrome XX while using Chrome).

Any updates on this. Im trying to test HTTPS resources and I can get any of the proxy settings to work for me.

how do we finally fix this issue?

@brian-mann
I have a different issue with proxy

I have to test an application that's outside my dev machines network and we turned the proxy on to go out to that network and test that (of-course I have set my env vars http_proxy https_proxy PROXY_ALL to the proxy server )

But when I run tests in headless mode with cypress run the proxy settings are probably not picked by net.connect check in Cypress/resourses/app/packages/server/lib/utils/connect.js

It works when I run my tests on chrome /electron using cypress open

My workaround for that is setting the baseUrl as my proxy server (or something that cypress can obviously succeed to verify the baseUrl using net.connect) in the cypress.json and then rewrite that in beforeEach hook.

Thats really awkward and sad .

Anyone got a better fix or can point me in a right direction

With proxy enabled, running cypress over a corporate proxy in ci mode, I get the following:

Cypress could not verify that the server set as your 'baseUrl' is running:

  > https://example.com

Your tests likely make requests to this 'baseUrl' and these tests will fail if you don't boot your server.

Any direction on how to debug this? How do we find out what made the verification fail?


I've managed to get into the code, and have noticed that when I hard-code a bypass of the baseUrl check, the tests will actually run.

I'm wondering if the ensureUrl check is failing to respect proxy settings somehow.
Or, is it not liking our baseUrl's 403 response (as we don't want people directly visiting the base url).

@jedateach Hi, could you open a separate issue for this? This may certainly be proxy related, but the first I've seen for ensureUrl checks sending false checks.

@jennifer-shehane Sure, added a new issue here: https://github.com/cypress-io/cypress/issues/1541

@jedateach @vs yes, the reason that ensureUrl is failing is because those checks utilize a lower level net.connect as opposed to a real http request to see if there is an open TCP connection on the other side.

There is no nodejs support for proxying those, so we may have to switch to a regular http request to ensure the check.

Can ya'll try to set HTTP_PROXY and/or HTTPS_PROXY to your corporate proxy as system/shell environment variables? I detailed some of this fix here: https://github.com/cypress-io/cypress/issues/1469#issue-305961859

Try the no_proxy setting too. That was the key for some of our devs

@jedateach +1 same exact issue here. Upon removing from cypress.json baseUrl tests could finally talk out over the env var proxy settings.

This worked for me when I set HTTP_PROXY as an env var in my docker container and removed baseUrl

e2e remote server testing behind corporate firewall is still an issue, this is very nice test framework but without proxy support it is difficult for this to go big ie. remote server serving static lib like google api from CDN

i'm experiencing the same problem both using electron and chrome (running on osx), but only when accessing https website,

What weird is when running in docker container, the request to https successfully forwarded using proxy

setting HTTP_PROXY and/without HTTPS_PROXY yield the same result

Is this issue resolved? I am planning to use cypress as the testing tools in my project, but our application is seating in a corporate network.

@gtycherry This issue is still open, so has not been resolved. You may want to track the larger Corporate Proxy issue here: https://github.com/cypress-io/cypress/issues/1469

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.

Released in 3.3.0.

Resolved: Had a similar issue.

### *Windows only*
Environment variable gets set automatically with default proxy ( Company Proxy)
Delete the Variable and restart the PC (Optional)
Delete : http_proxy

I m facing similar issue, however in Windows 10 running following command tells me that there is no proxy server: netsh winhttp show proxy returns
"Current WinHTTP proxy settings: Direct access (no proxy server)"

However, yarn add cypress -D fails with the message to setup HTTP_PROXY variable.

URL: https://download.cypress.io/desktop/3.4.1?platform=win32&arch=x64
Error: connect ETIMEDOUT 104.25.214.23:443

@RupenAnjaria Please make sure to follow the directions on proxy setup from our docs: https://on.cypress.io/proxy-configuration#Windows

So I manually downloaded Cypress and opened it along with my project. Upon settings -> Proxy Settings displays message: There is no active proxy configuration.

@RupenAnjaria Does your environment require a proxy to access the Internet?

The message that the CLI gives is generic, if you do not usually need a proxy you do not need to set one up.

Unfortunately the settings are done by my company's tech support team.
See below, it is configured to check proxy via some script file. I have to be in VPN.
image

If I can not add it via yarn add cypress -D then is it okay if I download the CLI and open the project from it?

@RupenAnjaria You can download that .pac file under "Automatic configuration script" and extract the proxy server you need, then use HTTP_PROXY=... to supply that to Cypress. You can also try downloading the executable from cypress.io, but that's not a great long-term solution.

Download .pac from where?

The URL that you've blacked out in the image you shared.

it's a dat file and has some javascript within it. As I mentioned earlier running netsh winhttp show proxy command says I do not have any proxy, so in that case what should be the value of HTTP_PROXY?

Yeah, the proxy IP and PORT are in that Javascript. Figure out what IP and host are used for external traffic and set that to your HTTP_PROXY (ex, HTTP_PROXY=http://my-company.net:12345). Or, ask your IT support what the correct proxy to use for external traffic is.

I tried but they did not understand :( , can I install it without npm? any link/reference which can help to use cypress (without npm proxy setup?)

the standard https://docs.npmjs.com/misc/config#strict-ssl didn't work, but setting the environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0 from https://github.com/cypress-io/cypress/issues/1401#issuecomment-372344080 worked

the standard https://docs.npmjs.com/misc/config#strict-ssl didn't work, but setting the environment variable NODE_TLS_REJECT_UNAUTHORIZED to 0 from #1401 (comment) worked

not for me :(

I am running into this issue upon trying to deploy to Netlify. The deployment is failing because Cypress could not be downloaded.

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

If you're experiencing a bug similar or that seems related to this in Cypress, please fully read and following the instructions in our Proxy Configuration doc: https://on.cypress.io/proxy-configuration

If you're still experiencing an issue, open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

Was this page helpful?
0 / 5 - 0 ratings