3

我有一个带有 Chrome 和 Firefox 的 Selenium 服务器 4。Chrome 工作正常,但是当我尝试运行 Firefox 时,它会抛出一个错误:

org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。所需功能 = Capabilities {acceptInsecureCerts: true, browserName: firefox, marionette: true}

驱动程序的Java代码在这里:

String browser = System.getProperty("browser");
browser = browser == null || browser.equals("") ? CHROME : browser.toLowerCase();

System.setProperty("webdriver.gecko.driver", "/home/tatrytec/custom-scripts/selenium-server/geckodriver");

Configuration.remote = HUB_URL;
Configuration.browser = browser;

FirefoxOptions options = new FirefoxOptions();
options.setCapability("marionette",true);
options.setHeadless(true);
WebDriver driver = new RemoteWebDriver(options);
WebDriverRunner.setWebDriver(driver);

这是 Jenkins 堆栈跟踪:

Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities {acceptInsecureCerts: true, browserName: firefox, marionette: true}
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'vmi503579.contaboserver.net', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-70-generic', java.version: '11.0.10'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:87)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
    at services.WebDriverService.setDriver(WebDriverService.java:51)
    at steps.BaseSteps.<clinit>(BaseSteps.java:43)

这是 Selenium 服务器堆栈跟踪:

12:34:10.493 INFO [Distributor.newSession] - Session request received by the distributor:
 {
  "desiredCapabilities": {
    "browserName": "firefox",
    "moz:firefoxOptions": {
      "args": [
        "-headless"
      ],
      "prefs": {
      }
    },
    "marionette": true,
    "acceptInsecureCerts": true
  },
  "capabilities": {
    "firstMatch": [
      {
        "acceptInsecureCerts": true,
        "browserName": "firefox",
        "moz:firefoxOptions": {
          "args": [
            "-headless"
          ],
          "prefs": {
          }
        }
      }
    ]
  }
}
1619433250551   geckodriver     INFO    Listening on 127.0.0.1:21294
1619433251262   mozrunner::runner       INFO    Running command: "/snap/bin/firefox" "--marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile8aLKtJ"
2021/04/26 12:34:13.167735 cmd_run.go:1003: WARNING: cannot start document portal: dial unix /run/user/0/bus: connect: permission denied
mkdir: cannot create directory '/run/user/1000': Permission denied
*** You are running in headless mode.
[GFX1-]: glxtest: libpci missing
[GFX1-]: glxtest: libEGL initialize failed
[GFX1-]: glxtest: Unable to open a connection to the X server
[GFX1-]: glxtest: libEGL initialize failed
[GFX1-]: No GPUs detected via PCI
12:35:11.436 WARN [SeleniumSpanExporter$1.lambda$export$0] - {"traceId": "276854ae3527ad1a0d5c4039f0580cec","spanId": "2c522f44eb54f30e","spanKind": "INTERNAL","eventTime": 1619433311373994495,"eventName": "exception","attributes": {
"driver.url": "http:\u002f\u002flocalhost:21294",
"exception.message": "Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: Connection refused (os error 111)\nBuild info: version: '4.0.0-beta-2', revision: 'Unknown'\nSystem info: host: 'vmi123456.contaboserver.net', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-70-generic', java.version: '11.0.10'\nDriver info: driver.version: unknown"

服务器上的权限似乎有问题。它说:

无法启动文档门户:拨打 unix /run/user/0/bus:连接:权限被拒绝

不知道我还应该设置什么来运行。

4

1 回答 1

0

这对于使用 snap 安装的 firefox 很常见,您可以卸载 snap 版本的 firefox 并使用 apt 安装它

snap remove firefox

然后

sudo apt-get install firefox
sudo apt-get install firefox-geckodriver

关于此https://github.com/mozilla/geckodriver/issues/1877的一些参考资料

https://askubuntu.com/questions/1334192/glxtest-libpci-missing-although-i-made-an-apt-install

于 2021-07-18T20:25:09.803 回答