Test on Internal Networks
Run CodeceptJS + WebdriverIO tests on your privately hosted websites using BrowserStack Automate.
Introduction
BrowserStack enables you to run your CodeceptJS automated tests on your internal development environments, on localhost, and from behind a corporate firewall. This feature is called “Local Testing”.
Local Testing establishes a secure connection between your machine and the BrowserStack cloud. Once you set up Local Testing, all URLs work out of the box, including HTTPS URLs and those behind a proxy or firewall.
In this guide, you will learn about:
Prerequisites
If you have already run your first test, you can skip the prerequisites.
- BrowserStack Username and Access key, which you can find in your account settings. If you have not created an account yet, you can sign up for a Free Trial or purchase a plan.
- Node.js version 12 or higher is installed on your machine.
- Git installed on your machine.
- NPM installed on your machine.
Run your first local test
Configuring your CodeceptJS + WebdriverIO tests for Local Testing using the following steps:
- Clone the codecept-js-browserstack sample repo on GitHub using:
command promptgit clone https://github.com/browserstack/codecept-js-browserstack cd codecept-js-browserstack
- Open the cloned project in the IDE of your choice and install the required dependencies by running the following command in your command line:
npm install
- Update your CodeceptJS config file,
codecept.conf.js
, in thesrc/test/local
directory to set thebrowserstack.local
capability totrue
. The config file also includes the logic to start and stop the local instance :
local/codecept.conf.jsconst browserstack = require("browserstack-local"); require('dotenv').config() const BROWSERSTACK_USERNAME = process.env.BROWSERSTACK_USERNAME const BROWSERSTACK_ACCESS_KEY = process.env.BROWSERSTACK_ACCESS_KEY exports.config = { tests: './*_test.js', output: './output', helpers: { WebDriver: { url: 'https://bstackdemo.com', user: BROWSERSTACK_USERNAME, key: BROWSERSTACK_ACCESS_KEY, browser: 'chrome', capabilities: { "os": "Windows", "os_version": "10", "browser_version": "latest", "browserstack.local": "true", "project": "Codecept + WebdriverIO", "build": "Local_Execution", "name": "Local Test", } } }, bootstrap: function () { console.log("Connecting Local"); exports.bs_local = new browserstack.Local(); exports.bs_local.start({ 'key': BROWSERSTACK_ACCESS_KEY }, function (error) { if (error) return error; console.log('Connected. Now testing...'); }); }, teardown: function () { exports.bs_local.stop(() => { console.log("Disconnected Local"); }); }, include: { I: './steps_file.js' }, mocha: {}, name: 'CodeceptJS-BrowserStack', plugins: { pauseOnFail: {}, retryFailedStep: { enabled: true }, tryTo: { enabled: true }, screenshotOnFail: { enabled: true } } }
You can use the following sample test case
local_test.js
in thesrc/test/local
directory to verify if your Local test connection has been set up correctly:local/local_test.jsFeature('BrowserStack Local Testing'); Scenario('Local Test', async ({ I }) => { I.amOnPage("http://bs-local.com:45691/check") let text = await I.grabTextFrom('/html/body') console.log(text) if(text === "Up and running"){ I.executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Local Instance is runnning"}}') } else{ I.executeScript('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Local Instance is not runnning!"}}') } });
- Run your CodeceptJS test using BrowserStack Local with the following command:
command prompt
npm run local
- View your tests on BrowserStack on the BrowserStack Automate Dashboard.
Next steps
After you have successfully run your first test using BrowserStack Local, you can explore the following sections:
- Run multiple tests in parallel to speed up the build execution
- Testing your local site that might be behind a proxy
- Local flags to customize your local testing setup
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!