为防火墙后面的网站运行BrowserStackLocal的问题

时间:2018-03-20 22:31:45

标签: mocha ui-automation browserstack mocha-phantomjs

我正在尝试在防火墙后面运行browserstack。

我试图在终端上运行此命令:

RK$ ./BrowserStackLocal --key <key> --force-local


BrowserStackLocal v7.0

You can now access your local server(s) in our remote browser.

Press Ctrl-C to exit

我打开了另一个终端并运行了命令

npm run test:functional:cr:mobile

我收到以下错误:

  1) Run sample test flow page:
     Uncaught WebDriverError: [browserstack.local] is set to true but local testing through BrowserStack is not connected.

这是我的config.js

'use strict'
import webdriver from 'selenium-webdriver'
let driver
module.exports = {
    getDriverConfiguration: function (testTitle, browserName) {
            var capabilities = {
                'browserName': process.env.BROWSER || 'Chrome',
                'realMobile': 'true',
                'os': 'android',
                'deviceName': process.env.DEVICE || 'Samsung Galaxy S8',
                'browserstack.user': 'USER',
                'browserstack.key': 'KEY',
                'browserstack.debug': 'true',
                'build': 'Build for mobile testing',
                'browserstack.local' : 'true',
                'browserstack.localIdentifier' : 'Test123'
            }
            driver = new webdriver.Builder().withCapabilities(capabilities).usingServer('http://hub-cloud.browserstack.com/wd/hub').build()
            driver.manage().deleteAllCookies()
            return driver
    }
}

我启用browserstack.local为true,但我仍然遇到此错误。

不知道我哪里出错了。

请帮助。

1 个答案:

答案 0 :(得分:0)

错误 [browserstack.local]设置为true,但未通过BrowserStack进行本地测试。如果您的BrowserStackLocal连接(使用./BrowserStackLocal建立的连接 - 键 - ,则返回 force-local)已断开连接。

我建议您使用以下方法,以避免额外的步骤并轻松管理您的本地测试连接:

npm install browserstack-local

安装了browserstack-local模块后,请使用以下代码片段作为参考来修改代码并从代码本身启动browserstack-local(在line driver = new webdriver.Builder()之前.withCapabilities (capabilities).usingServer('http://hub-cloud.browserstack.com/wd/hub')。build()),而不是从单独的终端窗口启动它:

var browserstack = require('browserstack-local');

//creates an instance of Local
var bs_local = new browserstack.Local();

// replace <browserstack-accesskey> with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
var bs_local_args = { 'key': '<browserstack-accesskey>', 'forceLocal': 'true' };

// starts the Local instance with the required arguments
bs_local.start(bs_local_args, function() {
  console.log("Started BrowserStackLocal");
});

// check if BrowserStack local instance is running
console.log(bs_local.isRunning());

// stop the Local instance
bs_local.stop(function() {
  console.log("Stopped BrowserStackLocal");
});