org.openqa.selenium.WebDriverException:与Selenium Geb GeckoDriver和Firefox的连接被拒绝

时间:2019-01-31 14:52:21

标签: selenium firefox selenium-webdriver geckodriver geb

在安装了Mozilla Firefox 60.4.0的Linux计算机上运行测试时,随机出现此错误“ org.openqa.selenium.WebDriverException:连接被拒绝”。

我尝试过的不同组合是:

1)硒3.12.0    geb-spock:2.1    GeckoDriver 0.18.0

2)硒3.12.0    geb-spock:2.1    GeckoDriver 0.23.0

3)硒3.14.0    geb-spock:2.1    GeckoDriver 0.23.0

我什至尝试将xvfb显示设置为偏移量5。 另外,请检查是否有任何防弹的geckodriver和firefox。没有这样的无效进程。

是否有办法尝试捕获此“ org.openqa.selenium.WebDriverException:连接被拒绝”,然后尝试再次创建驱动程序?有人知道为什么会发生此错误以及如何解决此问题吗?

堆栈跟踪:

geb.driver.DriverCreationException: failed to create driver from callback 'script1548780037482534636672$_run_closure1$_closure4$_closure7@288e23a'
    at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
    at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:85)
    at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
    at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:32)
    at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:84)
    at geb.Configuration.createDriver(Configuration.groovy:382)
    at geb.Configuration.getDriver(Configuration.groovy:371)
    at geb.Browser.getDriver(Browser.groovy:111)
    at geb.navigator.factory.BrowserBackedNavigatorFactory.<init>(BrowserBackedNavigatorFactory.groovy:35)
    at geb.Configuration.createNavigatorFactory(Configuration.groovy:417)
    at geb.Browser.createNavigatorFactory(Browser.groovy:133)
    at geb.Browser.getNavigatorFactory(Browser.groovy:121)
    at geb.Page.init(Page.groovy:144)
    at geb.Browser.createPage(Browser.groovy:859)
    at geb.Browser.to(Browser.groovy:550)
    at geb.Browser.to(Browser.groovy:539)
    at geb.spock.GebSpec.methodMissing(GebSpec.groovy:56)
    at tests.UserTest.Step 1: user can login(UserTest.groovy:40)
Caused by: org.openqa.selenium.WebDriverException: connection refused
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'va1c143', ip: '10.20.10.77', os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.32-754.9.1.el6.x86_64', java.version: '1.8.0_191'
Driver info: driver.version: FirefoxDriver
remote stacktrace: stack backtrace:
   0:           0x5787ed - backtrace::backtrace::trace::h59229d13f6a8837d
   1:           0x578942 - backtrace::capture::Backtrace::new::h23089c033eded8f0
   2:           0x4463cc - webdriver::error::WebDriverError::new::hd11f864b1fdf4510
   3:           0x450591 - geckodriver::marionette::MarionetteHandler::create_connection::h6f7058fccafe4367
   4:           0x425c32 - <webdriver::server::Dispatcher<T, U>>::run::h8f5348b8f5f7c053
   5:           0x40b22c - std::panicking::try::do_call::hb67c6fb6bcd96195
   6:           0x5dc20a - panic_unwind::__rust_maybe_catch_panic
                        at /checkout/src/libpanic_unwind/lib.rs:98
   7:           0x41b943 - <F as alloc::boxed::FnBox<A>>::call_box::h4100941edc372034
   8:           0x5d48a4 - alloc::boxed::{{impl}}::call_once<(),()>
                        at /checkout/src/liballoc/boxed.rs:650
                         - std::sys_common::thread::start_thread
                        at /checkout/src/libstd/sys_common/thread.rs:21
                         - std::sys::imp::thread::{{impl}}::new::thread_start
                        at /checkout/src/libstd/sys/unix/thread.rs:84
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    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.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
    at script1548780037482534636672$_run_closure1.closure4$_closure7(script1548780037482534636672.groovy:17)
    at script1548780037482534636672$_run_closure1.closure4$_closure7(script1548780037482534636672.groovy)
    at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)

1 个答案:

答案 0 :(得分:0)

此错误消息...

geb.driver.DriverCreationException: failed to create driver from callback 'script1548780037482534636672$_run_closure1$_closure4$_closure7@288e23a'

...表示 geb 无法启动/产生新的 GeckoDriver 进程。

此问题可能有多种原因,如下所示:

  • 按照geb.driver.DriverCreationException: failed to create driver from callback

    • 您需要在 GebConfig 中提供 GeckoDriver 绝对路径,如下所示:

      driver = {
         System.setProperty('webdriver.gecko.driver', '/path/to/geckodriver')
         new FirefoxDriver()
      }
      
    • 确保已安装 Firefox 浏览器。

    • 根据以下矩阵,确保 GeckoDriver 版本与 Selenium Firefox 版本兼容:

Geckodriver Releases_till_24