无法建立一个或多个指定的浏览器连接/Ubuntu/Firefox Headless

Unable to establish one or more of the specified browser connections / Ubuntu / Firefox Headless

我的设置:

OS: Ubuntu 18

测试咖啡馆版本:1.8.8

浏览器:火狐

我有几台 Ubuntu 服务器,其中 Testcafe 正在运行。由于安全问题,我不得不完全重新安装服务器。不幸的是,在全新的重新安装中,Testcafe 表示无法建立一个或多个指定的浏览器连接。我已经安装了 firefox 并再次确认它已安装。

之前我是这样做的:

  1. 发出命令:sudo testcafe test.js
  2. 预期行为:片刻之后,我可以在日志中明显看到测试 运行ning 使用 Firefox headless。 生活很美好.

现在,当我在全新的重新安装中执行完全相同的操作时:

  1. 发出命令:sudo testcafe test.js
  2. 意外行为:片刻之后,我在控制台中得到了这个:

Using locally installed version of TestCafe. ERROR Unable to establish one or more of the specified browser connections. This can be caused by network issues or remote device failure.

糟透了!

这是我正在使用的.testcaferc.json:

{
    "browsers": ["firefox:headless"],
        "speed": 0.1,
        "skipJsErrors" : true,
        "pageLoadTimeout": 5000
}

当我 运行 testcafe --list-browsers 时,我得到: firefox

我的测试文件:

import { ClientFunction, Selector } from 'testcafe';

fixture `triage`
    .page('https://www.google.com/');

test(`test debugging`, async t => {

await t
    .wait(5000)
        console.log(`I did it!`)

})

以前没有问题!如果我不必重新安装 Ubuntu,就不会失败。我实际上有 5 台这样的服务器,确实需要修复。知道为什么会这样吗?

我什至安装了 chrome。同样的问题!也无法与 chrome 建立连接。

终于为我解决了这个问题。我的解决方案,以及我所做的不同之处。

之前的安装步骤:

  1. 安装Ubuntu
  2. 以 root 身份登录
  3. 创建新用户
  4. 登录新用户帐户
  5. 在新用户帐户中安装 Node.js 作为 sudo
  6. 在新用户帐户中以 sudo 身份安装 Firefox
  7. 在新用户帐户中以 sudo 身份安装 Testcafe
  8. 设置 git express 的克隆...

看了几天之后,我认为等待 Unable to establish one or more of the specified browser connections 可能只是意味着 Can't see the browser due to being installed as sudo in a user account thus unable to establish that browser connection...(好像由于某种原因看不到它)。 为了验证这个理论,我重新安排了安装步骤,突然间一切正常了! 以下是为我解决此问题的步骤:

  1. 安装Ubuntu
  2. 以 root 身份登录
  3. 安装 Node.js 为 ROOT
  4. 以 ROOT 身​​份安装 Firefox
  5. 以 ROOT 身​​份安装 Testcafe(这允许您执行 npm i -g testcafe 以及能够发出命令 testcafe "firefox:headless" mytest.js -e 而不是 sudo testcafe "firefox:headless" mytest.js -e,这不适用于 sudo )
  6. 创建新用户
  7. 登录新用户帐户
  8. 设置 git express 的克隆...

现在我的所有请求都像以前一样触发测试。