由于没有创建会话,GeckoDriver无法连接到便携式Firefox

时间:2018-05-31 16:36:39

标签: selenium selenium-webdriver selenium-firefoxdriver geckodriver

使用以下内容:

  • Mozilla Firefox版本--60.0.1(64位)
  • Selenium v​​ersion - 3.12.0
  • Gecko驱动程序版本 - 0.20.1

我的目标是使用Selenium和Gecko Driver进行一些浏览器测试。

当运行以下测试时,浏览器窗口打开正常并且看起来geckodriver正在启动并且听得很好但是没有与浏览器进行交互(例如导航到所需的URL)。通过调试,当 ProtocolHandshake 尝试创建会话(createSession(HttpClient客户端,InputStream newSessionBlob,长度))时,会出现问题,其中基本URL为 http://localhost:22192 (对于下面的示例,每次运行时端口都会更改)并且HttpRequest具有URI" / session"。

我尝试过不同的Firefox,Selenium和Gecko Driver组合,只是为了检查它是否是由于我使用的特定软件版本,但观察到同样的问题。

@Test
public void testWebDriver() {

  System.setProperty("webdriver.firefox.bin", "C://Firefox//firefoxesr-60.0.1//FirefoxPortableESR//FirefoxPortable.exe");

  FirefoxOptions firefoxOptions = new FirefoxOptions();
  firefoxOptions.setProfile(getFirefoxProfile());
  firefoxOptions.setLogLevel(FirefoxDriverLogLevel.TRACE);
  firefoxOptions.setCapability("marionette", true);
  firefoxOptions.setCapability("acceptInsecureCerts", true);

  WebDriver webDriver = new FirefoxDriver(firefoxOptions);
  webDriver.navigate().to("https://www.google.co.uk/");
}

private FirefoxProfile getFirefoxProfile() {
  final FirefoxProfile profile = new FirefoxProfile();
  System.setProperty("webdriver.gecko.driver", "C://Users//dio//Downloads//geckodriver//geckodriver.exe");
  return profile;
}

日志如下:

May 31, 2018 5:11:01 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
1527783063107   geckodriver INFO    Listening on 127.0.0.1:22192
1527783063801   mozprofile::profile INFO    Using profile path C:\Users\User\AppData\Local\Temp\rust_mozprofile.oPYEdpyJJG4D
1527783063858   geckodriver::marionette INFO    Starting browser C://Firefox//firefoxesr-60.0.1//FirefoxPortableESR//FirefoxPortable.exe
1527783063878   geckodriver::marionette INFO    Connecting to Marionette on localhost:59995
1527783065942   geckodriver::marionette DEBUG     connection attempt 0/600
1527783068153   geckodriver::marionette DEBUG     connection attempt 1/600
1527783070258   geckodriver::marionette DEBUG     connection attempt 2/600
1527783072361   geckodriver::marionette DEBUG     connection attempt 3/600
1527783074462   geckodriver::marionette DEBUG     connection attempt 4/600
1527783076561   geckodriver::marionette DEBUG     connection attempt 5/600
1527783078680   geckodriver::marionette DEBUG     connection attempt 6/600
1527783080785   geckodriver::marionette DEBUG     connection attempt 7/600
1527783082886   geckodriver::marionette DEBUG     connection attempt 8/600
1527783084983   geckodriver::marionette DEBUG     connection attempt 9/600
1527783087085   geckodriver::marionette DEBUG     connection attempt 10/600
1527783089184   geckodriver::marionette DEBUG     connection attempt 11/600
....
1527784326728   geckodriver::marionette DEBUG     connection attempt 598/600
1527784328847   geckodriver::marionette DEBUG     connection attempt 599/600
1527784330951   geckodriver::marionette DEBUG     connection attempt 600/600
1527784333054   geckodriver::marionette DEBUG     connection attempt 601/600
1527784333055   webdriver::server   DEBUG   Returning status InternalServerError
1527784333055   webdriver::server   DEBUG   Returning body {"error":"unknown error","message":"connection refused","stacktrace":"stack backtrace:\n   0:           0x4744af - <no info>\n   1:           0x475289 - <no info>\n   2:           0x435984 - <no info>\n   3:           0x41d7dc - <no info>\n   4:           0x405ca7 - <no info>\n   5:           0x6bff09 - <no info>\n   6:           0x415457 - <no info>\n   7:           0x6b1e73 - <no info>\n   8:         0x76d559cd - BaseThreadInitThunk"}
1527784333056   hyper::header   TRACE   Headers.set( "Content-Type", ContentType(Mime(Application, Json, [(Charset, Utf8)])) )
1527784333056   hyper::header   TRACE   Headers.set( "Cache-Control", CacheControl([NoCache]) )
1527784333056   hyper::header   TRACE   Headers.set( "Content-Length", ContentLength(440) )
1527784333056   hyper::server::response DEBUG   writing head: Http11 InternalServerError
1527784333056   hyper::header   TRACE   Headers.set( "Date", Date(HttpDate(Tm { tm_sec: 13, tm_min: 32, tm_hour: 16, tm_mday: 31, tm_mon: 4, tm_year: 118, tm_wday: 4, tm_yday: 150, tm_isdst: 0, tm_utcoff: 0, tm_nsec: 56943500 })) )
1527784333056   hyper::server::response DEBUG   headers [
Headers { Connection: close
, Content-Type: application/json; charset=utf-8
, Cache-Control: no-cache
, Content-Length: 440
, Date: Thu, 31 May 2018 16:32:13 GMT
, }]
1527784333056   hyper::server::response DEBUG   write 440 bytes
1527784333057   hyper::server::response TRACE   ending
1527784333057   hyper::server   DEBUG   keep_alive = false for 127.0.0.1:59993
1527784333057   hyper::server   DEBUG   keep_alive loop ending for 127.0.0.1:59993

注意 如果我明确地引用便携式的可执行文件,那么它可以正常工作:

System.setProperty("webdriver.firefox.bin", "C://Firefox//firefoxesr-60.0.1//FirefoxPortableESR//App//Firefox64//firefox.exe");

0 个答案:

没有答案