admin管理员组

文章数量:1221466

Is it possible to setup cypress.io to access pages through a proxy?

I have a proxy that I need to go through, in order to test my application. Is there anyway to configure cypress.io to honour the standard HTTP_PROXY environment variables.. or is there some other setup that is required?

Is it possible to setup cypress.io to access pages through a proxy?

I have a proxy that I need to go through, in order to test my application. Is there anyway to configure cypress.io to honour the standard HTTP_PROXY environment variables.. or is there some other setup that is required?

Share Improve this question edited Nov 21, 2017 at 8:18 Dylan Watson asked Nov 20, 2017 at 8:38 Dylan WatsonDylan Watson 2,3232 gold badges20 silver badges38 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 2

HTTP_PROXY was added and Cypress.io should be able to work with your proxy with that set. I however still can't get our HTTPS to work, so its not totally working

I use "cypress": "3.3.1", there is a proxy setting

I got the same issue. My issue: My cypress tests are running for one application and due to the corporate firewall, it was not able to access the public internet URL.
Ex. xyz.com

Solution:
I used the NO_PROXY=localhost HTTPS_PROXY=mycompanyproxy.com:443 while running the cypress tests as env variable.

Ex:

HTTPS_PROXY=mycompanyproxy.com:443 NO_PROXY=localhost npm run test -- @profile=profile

Use these to variable while running the cypress tests.

Note: If we use the env variable to the box that will not work.

Update:

This is now well documented at: https://docs.cypress.io/guides/references/proxy-configuration.html

Unix

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

Windows

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

There is a Cypress issue open to track this: https://github.com/cypress-io/cypress/issues/1469

This covers many of the common issues with getting through a corporate proxy and ways of working around them.

The following is an excerpt from the issue:

Setting Environment Variables

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()

  • Enable permissions in the Cypress chrome extension
  • Check the Chrome ProxyMode if you have administration rights
  • Try using Electron

For Download

  • Try the direct download if you're having issues during install.
  • Workaround for install using CYPRESS_BINARY_VERSION.

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.

Also what you can do is set the environmental variables in your cypress.config.ts file below:

import { defineConfig } from "cypress";

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
  },
  env: {
    http_proxy: "http://localhost:8008"
  }
});

本文标签: javascriptSetup Cypressio to access a page through a proxyStack Overflow