Node.js `使用本地功能时未找到newSession`

Node.js `使用本地功能时未找到newSession`,node.js,selenium-webdriver,browserstack,Node.js,Selenium Webdriver,Browserstack,在尝试使用BrowserStack本地功能时,我遇到了以下错误: (node:67602) UnhandledPromiseRejectionWarning: UnsupportedOperationError: newSession: Not Found at parseHttpResponse (/Users/ardo/Documents/workspace/test-browser-stack/node_modules/selenium-webdriver/lib/http.js:

在尝试使用BrowserStack本地功能时,我遇到了以下错误:

(node:67602) UnhandledPromiseRejectionWarning: UnsupportedOperationError: newSession: Not Found
    at parseHttpResponse (/Users/ardo/Documents/workspace/test-browser-stack/node_modules/selenium-webdriver/lib/http.js:578:11)
    at Executor.execute (/Users/ardo/Documents/workspace/test-browser-stack/node_modules/selenium-webdriver/lib/http.js:489:26)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:67602) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:67602) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:67602) UnhandledPromiseRejectionWarning: UnsupportedOperationError: newSession: Not Found
    at parseHttpResponse (/Users/ardo/Documents/workspace/test-browser-stack/node_modules/selenium-webdriver/lib/http.js:578:11)
    at Executor.execute (/Users/ardo/Documents/workspace/test-browser-stack/node_modules/selenium-webdriver/lib/http.js:489:26)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:67602) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
我的代码非常简单:

const webdriver = require('selenium-webdriver');
const browserstack = require('browserstack-local');

const runTestSuite = () => {
  const capabilities = {
    browserName: 'Chrome',
    browser_version: '80.0 beta',
    os: 'OS X',
    os_version: 'Catalina',
    resolution: '1024x768',
    'browserstack.user': '<user>',
    'browserstack.key': '<key>',
    'browserstack.local': true,
    'browserstack.localIdentifier': 'ardotest',
    // 'browserstack.use_w3c': true,
    acceptSslCerts: true,
    name: 'Bstack-[Node] Sample Test-OS X Catalina-Chrome 80',
  };

  // https://www.browserstack.com/question/663
  const driver = new webdriver.Builder()
    .usingServer('http://localhost:3000') // tried using the IP that I got from Network settings on my machine, it spat out the same error
    .withCapabilities(capabilities)
    .build();

  console.log('quit');
  driver.quit();
};

// creates an instance of Local
const bsLocal = new browserstack.Local();

// replace <browserstack-accesskey> with your key. You can also set an environment variable - "BROWSERSTACK_ACCESS_KEY".
const bsLocalArgs = { key: '<browserstack-accesskey>' };
// https://github.com/browserstack/browserstack-local-nodejs/blob/master/lib/Local.js

// starts the Local instance with the required arguments
bsLocal.start(bsLocalArgs, function(err) {
  if (err) {
    console.error(err);
    return;
  }

  if (!bsLocal.isRunning()) {
    return;
  }

  try {
    runTestSuite();
  } catch (e) {
    console.error(e);
  } finally {
    // stop the Local instance
    bsLocal.stop(function(err) {
      if (err) {
        console.error(err);
      }
      console.log('===== BrowserStack tunnel stopped =====');
    });
  }
});
我的本地环境:

    "node": "10.16.3",
    "npm": "6.8.0",

macOS 10.14.6


通过查看代码,很明显它正试图点击
/session
url来创建一个新的会话或其他内容。我不确定我是否应该手动支持
/session
,或者我只是错过了一些非常愚蠢的东西?

看起来BrowserStack为测试执行提供了自己的中心URL。您可以尝试将中心URL从localhost:3000更改为BrowserStacks中心URL

参考此代码->。使用服务器(“”)


本文档提供了更多详细信息:

您只需确保在
功能
bsLocalArgs
中具有相同的
localIdentifier
参数

也就是说,在
.withCapabilities()
newbrowserstack.Local().start(,…)

    "node": "10.16.3",
    "npm": "6.8.0",

macOS 10.14.6