Skip to main content

Test on Internal Networks

BrowserStack allows you to test your apps hosted on local/internal development API servers through its Local Testing feature. This feature creates a secure connection between your device and the BrowserStack cloud, enabling all types of URLs, including HTTPS URLs and those blocked by a firewall or proxy, to function seamlessly.

Prerequisites

Before configuring your WebdriverIO tests for Local Testing, go through Integrate your test suites with BrowserStack.

Configure local testing

The @wdio/browserstack-service plugin provides support to manage the Browserstack Tunnel out of the box. You just need to set browserstackLocal: true to activate this feature.

Step 1: Set browserstackLocal: true in your configuration file as shown below. If you’re using our sample repo for testing, test.conf.js file located in the /examples/run-sample-test folder of your preferred project(android/ios) has to be altered.

  //test.conf.js

  export.config = {
    user: process.env.BROWSERSTACK_USERNAME || 'YOUR_USERNAME',
    key: process.env.BROWSERSTACK_ACCESS_KEY || 'YOUR_ACCESS_KEY',
    services: [
        ['browserstack', {
            browserstackLocal: true
        }]
    ],
    ...
  };

Step 2: Trigger your existing build command to run your WebdriverIO tests with BrowserStack Local.

Verify local connection

You can use the following sample test case to verify whether your Local test connection has been setup correctly:

If you are using your own app, modify the following code as per your test case:

var path = require('path');
var assert = require('assert');

describe('BrowserStack Local Testing', () => {
  it('can check tunnel working', async () => {
    var searchSelector = 
    await $('android=new UiSelector().resourceId(
      "com.example.android.basicnetworking:id/test_action")');
    await searchSelector.waitForDisplayed({ timeout: 30000 });
    await searchSelector.click();

    var insertTextSelector = await $(`android.widget.TextView`);
    await insertTextSelector.waitForDisplayed({ timeout: 30000 });

    var testElement = null;

    try {
      var textElement =
      await $('android=new UiSelector().textContains("active connection is")');
      await textElement.waitForDisplayed({ timeout: 30000 });
      testElement = textElement;
    }
    catch {
      var screenshotPath = path.resolve(__dirname, 'screenshot.png');
      await browser.saveScreenshot(screenshotPath);
      console.log('Screenshot stored at ' + screenshotPath);
      throw new Error('Cannot find the needed TextView element from app');
    }

    var matchedString = await testElement.getText();
    console.log(matchedString);
    assert(matchedString.indexOf('The active connection is wifi') !== -1);
    assert(matchedString.indexOf('Up and running') !== -1);
  });

If you are using your own app, modify the following code as per your test case:

var path = require('path');
var assert = require('assert');

describe('BrowserStack Local Testing', () => {
  it('can check tunnel working', async () => {
    var searchSelector = await $(`~Test BrowserStackLocal connection`);
    await searchSelector.waitForDisplayed({ timeout: 30000 });
    await searchSelector.click();

    var textElements = await $(`~ResultBrowserStackLocal`);
    await textElements.waitForDisplayed({ timeout: 30000 });

    var testElement = null;

    var textContent = await textElements.getText();
    if (textContent.indexOf('Up and running') !== -1) {
      testElement = textElements;
    }

    if (testElement === null) {
      var screenshotPath = path.resolve(__dirname, 'screenshot.png');
      await browser.saveScreenshot(screenshotPath);
      console.log('Screenshot stored at ' + screenshotPath);
      throw new Error('Cannot find the Up and running response');
    }

    var matchedString = await testElement.getText();
    assert(matchedString == 'Response is: Up and running');
  });
});

Note: If you want to refer a sample local testing configuration, check the webdriverio-browserstack repo on GitHub

After you run your test, visit the App Automate dashboard to view your test results

Next steps

Once you have successfully executed local testing with BrowserStack, you might want to check the following:

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
Download Copy