testcafe: testcafe failing to connect when using --proxy option

What is your Test Scenario?

I’m trying to run testcafe in our pipeline (Semaphore) using a docker image based on the official one, where the only additions are copying our tests inside it and install some other additional npm packages used by them. Those tests run against a test environment, that for security reasons can only be accessed either via VPN or a proxy. I’m using the --proxy flag but the test run fails.

From that same container, if I run curl https://mytestserver.dev --proxy $HTTP_PROXY it connects without problems, so does a Cypress container running in the same pipeline.

What is the Current behavior?

Tests fail to run, with the message

ERROR Unable to establish one or more of the specified browser connections.
1 of 1 browser connections have not been established:
- chromium:headless

Hints:
- Use the "browserInitTimeout" option to allow more time for the browser to start. The timeout is set to 2 minutes for local browsers and 6 minutes for remote browsers.
- The error can also be caused by network issues or remote device failure. Make sure that the connection is stable and the remote device can be reached.

As per suggestion here I set

DEBUG=hammerhead:*,testcafe:*

And the log is:

021-07-07T15:23:44.572Z testcafe:utils:temp-directory Found temp directories: []
2021-07-07T15:23:44.574Z testcafe:utils:temp-directory Temp directory path:  /tmp/testcafe/chrome-profile-128Nvnnsbk1AEpG
2021-07-07T15:23:44.587Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:46.423Z testcafe:compiler:typescript version: 3.9.10
2021-07-07T15:23:46.425Z testcafe:compiler:typescript options: [Object: null prototype] {
  experimentalDecorators: true,
  emitDecoratorMetadata: true,
  allowJs: true,
  pretty: true,
  inlineSourceMap: true,
  noImplicitAny: false,
  module: 1,
  moduleResolution: 2,
  target: 3,
  jsx: 2,
  suppressOutputPathCheck: true,
  skipLibCheck: true
}
2021-07-07T15:23:48.119Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.120Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.121Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.122Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.124Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.221Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.222Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.223Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.224Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.225Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.226Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.227Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.228Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.230Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.232Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.232Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.234Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.235Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.236Z testcafe:compiler:typescript path: "typescript"
2021-07-07T15:23:48.245Z testcafe:bootstrapper tests compilation took 3.67 s
2021-07-07T15:25:44.563Z testcafe:browser:connection:469Ca~Y status changed to 'closing'
2021-07-07T15:25:44.585Z testcafe:browser:connection:469Ca~Y TypeError: Cannot read property 'config' of undefined
    at BrowserProviderPluginHost.isHeadlessBrowser (/app/node_modules/testcafe/src/browser/provider/built-in/dedicated/base.js:65:51)
    at BrowserProvider.canUseDefaultWindowActions (/app/node_modules/testcafe/src/browser/provider/index.ts:260:53)
    at BrowserProvider.closeBrowser (/app/node_modules/testcafe/src/browser/provider/index.ts:323:44)
    at BrowserConnection._closeBrowser (/app/node_modules/testcafe/src/browser/connection/index.ts:208:13)
    at BrowserConnection.close (/app/node_modules/testcafe/src/browser/connection/index.ts:410:9)
    at Function._closeConnection (/app/node_modules/testcafe/src/runner/browser-set.ts:55:9)
    at async Promise.all (index 0)
    at BrowserSet.dispose (/app/node_modules/testcafe/src/runner/browser-set.ts:163:9)
    at Function.from (/app/node_modules/testcafe/src/runner/browser-set.ts:108:13)
    at async Promise.all (index 0)
2021-07-07T15:25:44.586Z testcafe:browser:connection:469Ca~Y status changed to 'closed'

I had the chance to get the logs in our proxy server, and found out this entry coming from the ip in semaphore where the container is running:

TCP_DENIED/403 4464 GET http://172.17.0.2:1337/browser/connect/sYNp3vU - HIER_NONE/- text/html

Denying access to that request is logical as it points to a local network address.

Incidentally I tried using firefox:headless just in case but found out that the --proxy option is completely ignored.

What is the Expected behavior?

I would expect the hammerhead proxy to issue requests to our proxy with the urls that our tests are visiting, not a local ip address.

Your Environment details:

  • testcafe version: 1.14.2
  • node.js version: 14.16.1
  • command-line arguments: docker run --rm -v ~/results:/app/results --env HTTP_PROXY=$HTTP_PROXY $ECR_REPO:$TESTCAFE_IMAGE chromium:headless --proxy $HTTP_PROXY
  • platform and version: Linux Ubuntu 18.04.1 VM in Semaphore
  • other:

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 51

Most upvoted comments

+1 same issue that @cyanbutton @mhanci92 are experiencing. After 1.14.0 I’m unable to connect to https sites via proxy.

@aleks-pro Just tried "disableHttp2": true workaround and am able to connect to https sites via proxy using 1.16.0. 😮 🥳 Not sure how I missed this in @VasilyStrelyaev comment 😓 THANK YOU BOTH!

Hi @miherlosev I’ve been looking for an open proxy that would work with TestCafe, had no luck, but using version 1.14.0 and running testcafe chrome test.js --proxy 147.135.225.62:8139 would return Failed to connect to the proxy. error. When using 1.15.3 the test would just run, but ignore the proxy, the IP address does not change. Have attached an example that checks the IP to see if it’s the same as the proxy. You’ll need to run npm install, it will install 1.15.3. Hope this helps.

I’m experiencing the same issue that @cyanbutton described with testcafe version 1.15.3. Testcafe seems to just ignore the proxy settings. I use the CLI, not the testcafe runner. When downgrading to testcafe version 1.14.0, the issue is not reproducable anymore. The issues seems to start occuring with version 1.14.1. Hence, I deduce from there that the changes that came with 1.14.1 cause the wrong behavior that we observe. To make sure that version 1.14.0 does not ignore the proxy, I tried the following case successfully: nonexisting-proxy-fails-as-expected When running the same exact setup with Testcafe Version 1.14.1 or above, the expected error when establishing a connection to the proxy server does not occur anymore.

Hi @miherlosev I’ve been looking for an open proxy that would work with TestCafe, had no luck, but using version 1.14.0 and running testcafe chrome test.js --proxy 147.135.225.62:8139 would return Failed to connect to the proxy. error. When using 1.15.3 the test would just run, but ignore the proxy, the IP address does not change. Have attached an example that checks the IP to see if it’s the same as the proxy. You’ll need to run npm install, it will install 1.15.3. Hope this helps.

Hi @Aleksey28 , thanks for the quick reply. No errors, the proxy setting is just being ignored. We have a firewall to protect our QA server, and use a proxy to bypass it. With 1.14.0 bypasses fine, with 1.15.2 the tests hit the firewall. Using the same testcaferc file and the same command line args.

Hey everyone, Been following along, added the --hostname localhost using 1.15.2 but still having the same issue described above, the proxy setting in the testcaferc file or the command line is being ignored. Proxy setting works well on 1.14.0 using Firefox. Did anyone find a solution? Thanks in advance.

My question is where I can find the parser of variables, because it looks weird that just changing my package.json file replacing testcafe version from 1.14.0 to 1.14.1 (until version 1.15.0) I got different behaviour.

The command-line argument parser is located in the ‘node_modules/testcafe/lib/cli/argument-parser.ts’ file. You can debug the parsing process using the console.log statement. Judging by your description, there is some issue with argument parsing. You can create a docker image with which it’s possible to reproduce the issue, share it with us, and specify your environment details (operation system, version, terminal name, node version). We will investigate this.

I think I found the problem, and it’s related not during a variables parsing, but during variable merge on file ‘node_modules/testcafe/lib/runner/index.js’ on function -->> useProxy() <–

Version 1.14.0 (lines 374,377) useProxy(proxy, proxyBypass) { this.configuration.mergeOptions({ proxy, proxyBypass }); return this; }

Version 1.15.0 (lines 436,440) useProxy(proxy, proxyBypass) { this._options.proxy = proxy; this._options.proxyBypass = proxyBypass; return this; }

It looks like that there is no merge on configuration options on last version (1.15.0), and result is that final configuration is without proxy/proxyBypass options.

I don’t have lot of time to analyse what’s the meaning about " this._options.proxy = proxy;", and “this._options.proxyBypass = proxyBypass;”, so as a test I have simply modified version 1.15.0 function on this way:

useProxy(proxy, proxyBypass) { this._options.proxy = proxy; this._options.proxyBypass = proxyBypass; this.configuration.mergeOptions({ proxy, proxyBypass }); return this; }

And everything is back to work well, using proxy on .testcafe.json file, and even using proxy definition by cli.

I hope it will be useful for you.

Cheers 😃

@sly4you, that’s the interesting bit. I can’t see the options there; however, I’m running this (from within the docker container):

$ testcafe chromium:headless --proxy $HTTP_PROXY --proxy-bypass 172.17.0.2

That’s the reason because of your issues.

It’s so clear that from version 1.14.1 options about proxy are not working, unfortunately I don’t have enough knowledge to look around the code and discover this bug.

Here @miherlosev has written that issue is solved, but output of configuration is still saying differently.

😦

I can confirm since version 1.14.1 (O.S independent):

Cli options: –proxy and --proxy-bypass are ignored

Config file options (.testcaferc.json): proxy proxyBypass

in both cases proxy setup variables are ignored.