Skip to main content
Get Automate insights in Microsoft Teams with our new integration! Get Started!.

Test on Internal Networks

Run CodeceptJS + WebdriverIO tests on your privately hosted websites using BrowserStack Automate.

Note: Check out the codecept-js-browserstack sample repository on GitHub to access code samples used in this guide.

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:

  1. Prerequisites
  2. Running your first local test

Prerequisites

If you have already run your first test, you can skip the prerequisites.

Run your first local test

Configuring your CodeceptJS + WebdriverIO tests for Local Testing using the following steps:

  1. Clone the codecept-js-browserstack sample repo on GitHub using:

    command prompt
    git clone https://github.com/browserstack/codecept-js-browserstack
    cd codecept-js-browserstack
    
  2. 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
    
  3. Update your CodeceptJS config file, codecept.conf.js, in the src/test/local directory to set the browserstack.local capability to true. The config file also includes the logic to start and stop the local instance :

    local/codecept.conf.js
     const 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 the src/test/local directory to verify if your Local test connection has been set up correctly:

    local/local_test.js
     Feature('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!"}}')
         }
     });
    
  4. Run your CodeceptJS test using BrowserStack Local with the following command:
    command prompt
     npm run local
    
  5. 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:

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

Is this page helping you?

Yes
No

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!

Talk to an Expert
Talk to an Expert