4

While trying to execute a Selenium test on BrowserStack with the capability 'browserstack.local' as 'true' I am getting the following exception-

org.openqa.selenium.WebDriverException: [browserstack.local] is set to true but local testing through BrowserStack is not connected.

If I remove the capability 'browserstack.local' then the test executes, however, it does not access the private network application. I tried to search other online resources around this exception, however, could not find any details.

URL URLObj = new URL("https://" + USERNAME + ":" + KEY + "@hub-cloud.browserstack.com/wd/hub");

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("device", "iPhone 8 Plus");
caps.setCapability("real_mobile", "true");
caps.setCapability("browserstack.local", "true");

AppiumDriver webDriver = new IOSDriver(URLObj, caps);

The excepted result is that the test should run and the private network application should be accessible. Also, the above exception should not be thrown.

Xtraterrestrial
  • 191
  • 1
  • 7

3 Answers3

8

BrowserStack provides the Local testing feature to test the internal websites which are not accessible publicly. Local testing feature is enabled by setting the capability 'browserstack.local' to the value 'true' and starting the BrowserStackLocal binary.

Have you started the BrowserStackLocal binary? You can start the binary by executing the following command in your command prompt-

BrowserStackLocal.exe --key ACCESS_KEY

The error - '[browserstack.local] is set to true but local testing through BrowserStack is not connected.' usually occurs when the BrowserStackLocal binary is not running.

I can think of the following causes for the error-

  1. When the test script and BrowserStackLocal binary connection do not use the same username and access key. You can verify the username and access key associated with your account here, https://www.browserstack.com/accounts/settings

  2. When the test script and BrowserStackLocal binary connection do not use the same local identifier

  3. When a new BrowserStackLocal binary is invoked with the same parameters and hence the old connection is closed thereby displaying the error
  4. Binary disconnected at your end due to some network connectivity issues

You can make sure that the test script and the BrowserStackLocal binary uses the same access key and the same local identifier, in case, if you are using a Local Identifier for the BrowserStackLocal binary connection. Also, make sure that all the old connections of BrowserStackLocal binary are terminated before starting a new one with the same parameters. Read more on Local testing here, https://www.browserstack.com/local-testing.

N3M
  • 266
  • 1
  • 3
3

I received this error because I had 2 instances of the BrowserstackLocal.exe running.

I was able to see them both in the task manager. I opted to end task on one, and they both quit. I used the CMD prompt to re-run the BrowserstackLocal.exe (with my key) and re-ran my test, and it worked.

Joshua
  • 41
  • 1
2

Apart from what you are doing, there is another step involved in Browserstack Local testing. You can check it here. Basically, there is a binary (executable) file which you need to run on your system(on which the tests will be executed) which will route the traffic via your network to Browserstack's network. This will resolve all your private URLs inside Browserstack's network.

Haxor
  • 2,266
  • 4
  • 14
  • 18