我有一个带有Chrome和Firefox的Selenium服务器4。Chrome运行良好,但当我尝试运行Firefox时,它给我带来了一个错误:
org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。所需的能力=能力{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:u002fu002flocalhost: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:connect:权限被拒绝
不知道我还应该设置什么来运行。
这在使用snap安装的firefox中很常见您可以卸载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