Test on Internal Networks

BrowserStack enables you to run your Behave 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.

Note: Code samples in this guide can be found in the behave-browserstack sample repo on GitHub

Configuring your Behave tests for Local Testing takes just three steps:

Step 1: Install local bindings:

pip install browserstack-local

Step 2: Next, you need to update your Behave config file, behave-browserstack/config/local.json (in sample repo), and set the browserstack.local capability to true:

{
  "user": "YOUR_USERNAME",
  "key": "YOUR_ACCESS_KEY",

  "capabilities": {
    "build": "behave-browserstack",
    "name": "local_test",
    "browserstack.debug": true,
    "browserstack.local": true
  },

  "environments": [{
    "browser": "chrome"
  }]
}

Step 3: You can use the following sample test case, which is in our GitHub repo. This test case navigates to the local server which you can use to verify if your Local test connection has been setup correctly:

behave-browserstack/features/local.feature
# Local Feature
Feature: BrowserStack Local Testing
    Scenario: can check tunnel working
        When visit url "http://bs-local.com:45691/check"
        Then page contains "Up and running"

The following part of the script shows the steps required for a Local test:

behave-browserstack/features/steps/steps.py
# Local Steps
@when('visit url "{url}"')
def step(context, url):
    context.browser.get(url)

@then(u'page contains "{body}"')
def step(context, body):
    assert body in context.browser.page_source

Step 4: You need the following code for starting and stopping Local testing connection:

behave-browserstack/features/environment.py
from browserstack.local import Local

def start_local():
    """Code to start browserstack local before start of test."""
    global bs_local
    bs_local = Local()
    bs_local_args = { "key": "YOUR_ACCESS_KEY", "forcelocal": "true" }
    bs_local.start(**bs_local_args)

def stop_local():
    """Code to stop browserstack local after end of test."""
    global bs_local
    if bs_local is not None:
        bs_local.stop()

Step 5: You can now run your Behave test using BrowserStack Local with the following command (ensure that you are inside the behave-browserstack directory after cloning our sample GitHub repo):

paver run local

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