Test on Internal Networks

Local Testing is a BrowserStack feature that allows you to run automated tests on internal development environments (localhost) or behind a corporate firewall.

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 how to :

  1. Add BrowserStack Local to the project
  2. Set up BrowserStack credentials
  3. Understand the code
  4. Run the Project

Prerequisites

  • BrowserStack Access key and Username. If you haven’t created an account yet, sign up for a free trial or purchase a paid plan. After signup, you can obtain your access credentials from account settings.
  • Node.js installed on your machine
Note: Before you begin, ensure that the sample Nightwatch.js repository is cloned and available to get started on local testing. You can use the repository to understand how test cases can be structured to integrate BrowserStack with your existing test suites.

Add BrowserStack Local to the project

To add BrowserStack Local to the project:

  1. Navigate to your Nightwatch.js project in your command-line.
  2. Install BrowserStack Local Testing bindings using the npm command.
    npm install browserstack-local
    
  3. In your IDE, navigate to the package.json file.
  4. Verify that nightwatch is added in dependencies.`
    "dependencies": {
         "browserstack-local": "^1.4.8",
         "nightwatch": "^1.7.3"
       },
    

Set up BrowserStack credentials

To set your BrowserStack access key and username in the project, run the following command in the root directory of the Nightwatch.js project:

export BROWSERSTACK_USER=<YOUR_USERNAME> && export BROWSERSTACK_KEY=<YOUR_ACCESS_KEY> 

Understand the code

Nightwatch.js project consists of the following folder structure:

  • tests/local directory: It contains the test script file for a locally-hosted website.
  • scripts directory: It contains the runner file required to set up and manage a local connection using methods, such as bs_local.start(), bs_local.stop(),and bs_local.isRunning(), which are provided by BrowserStack.

Run the Project

To run the project:

  1. In your terminal, navigate to the root of the project.
  2. Run the local test script using the following command:
    npm run local
Note: This npm command generates the nightwatch.conf.js file in the sample Nightwatch.js project folder. If you are editing your existing test scripts and already have a configuration file, ensure that the browserstack.local capability is added to the configuration file and set to true. For example:
desiredCapabilities: {
        'browserstack.local': true
      }

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