Test on Internal Networks
Run tests on internal networks and use tunnel connection for other advanced use-cases
TestCafe operates in a way that irrespective of the fact that you are testing a locally hosted website or a publicly available one, all traffic goes through your local machine which runs the TestCafe instance. Hence, BrowserStackLocal setup is mandatory as we have already seen in the section for setting up BrowserStack Local connection section.
You do not need to make any separate arrangements to run any locally hosted website. You can simply specify the localhost
URL and your test should work fine. The next section addresses the concerns if you are behind a proxy.
Run tests from behind a proxy
If you are behind a proxy and want to run your tests on BrowserStack, you have to ensure that the BrowserStackLocal tunnel connection is established between your machine and the BrowserStack cloud. The following sections will help you achieve that.
User managed tunnel connection
You should have downloaded the appropriate BrowserStackLocal binary. If not, you can download from one of the links below:
You now have to start the binary with the proxy arguments as shown below:
./BrowserStackLocal --key YOUR_ACCESS_KEY --proxy-host HOST --proxy-port PORT --local-identifier TestCafe --daemon start --parallel-runs <number-of-parallels>
HOST
and PORT
should be replaced with the proxy hostname and respective port.
If your proxy requires basic authentication, use the invocation as shown below:
./BrowserStackLocal --key YOUR_ACCESS_KEY --proxy-host HOST --proxy-port PORT --proxy-user USERNAME --proxy-pass PASSWORD --local-identifier TestCafe --daemon start --parallel-runs <number-of-parallels>
You can also set the proxy details using a PAC file as shown below:
./BrowserStackLocal --key YOUR_ACCESS_KEY --pac-file PAC FILE PATH --local-identifier TestCafe --daemon start --parallel-runs <number-of-parallels>
See the complete list of supported local arguments which you can use in the local binary invocation
TestCafe managed tunnel connection
- The stability of tests run on BrowserStack is much better if the BrowserStackLocal binary is managed by the user and not TestCafe.
- Follow the steps in this section to start and stop the binary and set the
BROWSERSTACK_LOCAL_IDENTIFIER
variable with the identifier for your tunnel so that TestCafe does not create another tunnel connection.
If you let TestCafe manage the BrowserStack tunnel connection then you have to set values for these environment variables if you are behind a proxy:
Environment Variable | Description |
---|---|
BROWSERSTACK_PROXY |
A string that specifies a proxy for the BrowserStack local binary. It should have the following structure: user:pass@proxyHostName:port
|
BROWSERSTACK_LOCAL_PROXY |
A string that specifies a proxy for the local web server. It should have the following structure: user:pass@proxyHostName:port
|
BROWSERSTACK_FORCE_PROXY |
If it’s not empty, forces all traffic of BrowserStack local binary to go through the proxy. |
Example:
export BROWSERSTACK_PROXY="user:p@ssw0rd@proxy.com:8080"
export BROWSERSTACK_LOCAL_PROXY="admin:12345678@192.168.0.2:8080"
export BROWSERSTACK_FORCE_PROXY="1"
export BROWSERSTACK_FORCE_LOCAL="1"
testcafe browserstack:chrome test.js
Other options for TestCafe managed local
Setting these additional environment variables will let you avail more features of BrowserStackLocal binary as shown below:
Environment Variable | Description |
---|---|
BROWSERSTACK_BINARY_PATH |
The filepath where you have downloaded the binary. If this is not set, TestCafe will download the binary every time |
BROWSERSTACK_LOGFILE |
The full filepath where you want to save the local binary logs |
BROWSERSTACK_VERBOSE |
This would set the logging level. 1 for setup logs, 2 for network logs and 3 for all logs |
BROWSERSTACK_FORCE_LOCAL |
If it’s not empty, forces all traffic of BrowserStack local binary to go through the local machine |
BROWSERSTACK_LOCAL_IDENTIFIER |
A string identifier of an open BrowserStack local tunnel. If it’s not empty, a new local tunnel is not created. Instead, the browser provider uses an existing local tunnel with the specified identifier |
Example:
export BROWSERSTACK_BINARY_PATH="~/BrowserStack/BrowserStackLocal"
export BROWSERSTACK_LOGFILE="~/BrowserStack/logs.txt"
export BROWSERSTACK_VERBOSE="1"
testcafe browserstack:chrome test.js
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!