【问题标题】:Running headless Firefox with Selenium on OpenShift - Connection refused在 OpenShift 上使用 Selenium 运行无头 Firefox - 连接被拒绝
【发布时间】:2019-08-13 12:41:02
【问题描述】:

所以我设置了一些 Selenium 测试,以便在无头 Chrome + Firefox 上的 OpenShift 上运行。它们在我的 Windows 机器上在带有 GUI 的浏览器上运行良好,Chrome 无头也可以正常工作。 对于 Firefox,我收到错误消息“连接被拒绝”,并且 geckodriver 似乎无法连接到 Firefox。 我找到了十几个关于这个问题的帖子,但到目前为止还没有解决方案。 有人对此有任何建议吗? 非常感谢!

所需的能力

 public static DesiredCapabilities getFirefoxCapabilities () {
    DesiredCapabilities caps = DesiredCapabilities.firefox();
    caps.setPlatform(org.openqa.selenium.Platform.ANY);

    FirefoxOptions options = new FirefoxOptions();
    options.setBinary("/usr/lib64/firefox/firefox-bin"); 
    options.setHeadless(true);
    options.addArguments("--disable-gpu");
    options.addArguments("--allow-insecure-localhost");
    options.addArguments("--remote-debugging-port=9222");
    options.setAcceptInsecureCerts(true);

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("sanity-test.running", true);

    options.setProfile(profile);

    caps.merge(options);

    return caps;
  }

Webdriver 实现的设置

System.setProperty("webdriver.gecko.driver",  openshift_browserDriverPath_Firefox);
try {
    driver.set(new FirefoxDriver(headlessDriverCapabilityFactory.getCapabilities(getBrowserName())));
}
catch(Exception e) {
    System.out.println("setup headless ff: " + e.getMessage() + "failed at " + e.getStackTrace());
}

詹金斯日志摘录

1565697695283   mozrunner::runner   INFO    Running command: 
"/usr/lib64/firefox/firefox-bin" "-marionette" "-headless" "--disable- 
gpu" "--allow-insecure-localhost" "--remote-debugging-port=9222" "- 
foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.LMzPtqcIh6wS"
*** You are running in headless mode.
 1565697700885  addons.xpi  WARN    Can't get modified time of 
 /usr/lib64/firefox/browser/features/aushelper@mozilla.org.xpi
1565697701079   addons.xpi-utils    WARN    addMetadata: Add-on 
aushelper@mozilla.org is invalid: [Exception... "Component returned 
failure code: 0x80520006 (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) 
[nsIFile.isFile]"  nsresult: "0x80520006 
(NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)"  location: "JS frame :: 
resource://gre/modules/addons/XPIInstall.jsm :: loadManifestFromFile :: 
line 925"  data: no] Stack trace: 
loadManifestFromFile()@resource://gre/modules/addons/XPIInstall.jsm:925 syncLoadManifestFromFile()@resource://gre/modules/addons/XPIProvider.jsm:940
addMetadata()@resource://gre/modules/addons/XPIProvider.jsm -> 
resource://gre/modules/addons/XPIProviderUtils.js:1173
processFileChanges()@resource://gre/modules/addons/XPIProvider.jsm -> 
resource://gre/modules/addons/XPIProviderUtils.js:1529
checkForChanges()@resource://gre/modules/addons/XPIProvider.jsm:3304
startup()@resource://gre/modules/addons/XPIProvider.jsm:2196
callProvider()@resource://gre/modules/AddonManager.jsm:253
_startProvider()@resource://gre/modules/AddonManager.jsm:728
startup()@resource://gre/modules/AddonManager.jsm:892
startup()@resource://gre/modules/AddonManager.jsm:298 observe()@jar:file:///usr/lib64/firefox/omni.ja!/components/addonManager.js 
:63
1565697701094   addons.xpi-utils    WARN    Could not uninstall invalid 
item from locked install location
Aug 13, 2019 12:01:44 PM org.openqa.selenium.remote.ProtocolHandshake 
createSession
INFO: Detected dialect: W3C
@Test - internal test: Chrome browser headless
Aug 13, 2019 12:01:46 PM cucumber.runtime.java.ObjectFactoryLoader 
loadSingleObjectFactory
  WARNING: Use deprecated reflections to load ObjectFactory.
setup headless ff: connection refused
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11- 
14T08:17:03'
System info: host: 'ifx-java-slave-browsers.latest-6llvz', ip: 
'10.125.24.3', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0- 
862.el7.x86_64', java.version: '1.8.0_222'
Driver info: driver.version: FirefoxDriver

【问题讨论】:

    标签: selenium firefox openshift mozilla geckodriver


    【解决方案1】:

    @Daniel Davison 关于OpenShift Templates for Selenium 的文章可以为您提供在Docker 容器中利用 和Selenium 为Selenium 创建可扩展框架所需的所有步骤。

    这里是所需的链接:

    【讨论】:

    • 我已经设置好了,但是没有使用 Selenium Hub。我刚刚在我的 docker 映像中安装了 firefox 和 chrome 并将它们置于无头模式 - 因为 Chrome 工作得很好。所以我不确定本教程是否对我有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 2020-11-18
    • 1970-01-01
    • 1970-01-01
    • 2019-11-20
    • 1970-01-01
    相关资源
    最近更新 更多