Using BrowserStack Local Testing to Run Cross‑Browser Tests on a Staged Server Behind a Firewall
Learn how to expose a local staging environment to BrowserStack’s cloud grid with the Local Testing binary, run tests from CI, and verify tunnel health. Includes a concrete Cypress example and recovery tips.
31 May 2026, 02:33 UTC

Goal
Expose a localhost or staging server that sits behind a firewall or NAT to BrowserStack’s remote browsers so that your automated tests can run against the real environment rather than a public URL.
Prerequisites
- BrowserStack account with Automate access (any tier). Free tier allows one concurrent tunnel.
- Local server running on an IP/port accessible from the machine that will launch the tunnel.
- Node.js (or any language) and
npmif you plan to run a test framework such as Cypress or WebDriverIO. - Environment variables set for
BROWSERSTACK_USERNAMEandBROWSERSTACK_ACCESS_KEYor a~/.browserstackrcfile. - Download the BrowserStack Local binary for your OS from BrowserStack Local.
Setup Steps
- Verify binary version
browserstack-local --versionCheck that the output matches the version shown in the BrowserStack Automate dashboard under Local Testing.
- Start the local tunnel
browserstack-local --key $BROWSERSTACK_ACCESS_KEY --verboseRun this command on the machine that hosts your local server. The
--verboseflag prints connection state and helps debug failures. - Configure your test framework
Below is a Cypress example. Add the following to
cypress.json:{ "baseUrl": "http://localhost:3000", "browserstack": { "local": true, "browser": "chrome", "browser_version": "latest", "os": "Windows", "os_version": "10" } }The
local: trueflag tells BrowserStack to route traffic through the tunnel. - Run tests from CI
Example Jenkins pipeline step:
stage('Run Tests') { sh 'browserstack-local --key $BROWSERSTACK_ACCESS_KEY && npm run test:ci' }Ensure the tunnel is started before the test command and stopped afterward.
Verifying Connectivity
- On the BrowserStack dashboard, open the Local tab. The tunnel should show as Active and list the hostname you provided.
- In the test logs, look for entries similar to:
Using tunnel: https://.browserstack.com - Navigate to the test URL in a remote browser (e.g.,
https://.browserstack.com/your-app) and confirm the page loads.
Common Pitfalls & Recovery
- Binary‑Dashboard mismatch
If the tunnel refuses to connect, run
browserstack-local --versionand compare to the dashboard. Download the latest binary if they differ. - Firewall blocks outbound ports
BrowserStack Local uses port 443 for HTTPS. Ensure outbound traffic to
*.browserstack.comon port 443 is allowed. - Free tier timeouts
Sessions may drop after ~30 min of inactivity. Add a keep‑alive ping or run tests in batches to avoid this.
- Tunnel restart
When a tunnel disconnects, simply stop the binary and restart it. In CI, wrap the start/stop in a
try/finallyblock to guarantee cleanup.
Limits & Considerations
- Free tier: one concurrent tunnel, 30 min idle timeout. Paid plans increase concurrent tunnels and remove idle limits.
- Only HTTP/HTTPS/TCP are supported. WebSocket traffic requires a separate configuration flag (
--ws). - The tunnel URL is unique per session; do not hard‑code it in test scripts. Use environment variables or the
browserstack.localcapability instead. - Security: the tunnel exposes your local server to BrowserStack’s infrastructure. Restrict access to trusted IP ranges if possible.
By following this guide you can reliably run cross‑browser tests against a protected staging environment, ensuring that your CI pipeline reflects real‑world user interactions.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.