3

I can't seem to run functional tests from the command prompt. Interestingly it works fine with Intellij...

I am using Grails 2.2.0, seleniumVersion = "2.27.0", spockVersion = "spock-grails-support:0.7-groovy-2.0", geb = "0.9.0-RC-1", httpClientVersion = "4.2.3"

This is the error :

 geb.driver.DriverCreationException: failed to create driver from callback 'script13825065657431376537371$_run_closure1@800
4899'
      [...] Caused by: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid
 address of the remote server or browser start-up failure.

ChromeDriver is started (seen in running processes), but obviously it cannot start chrome.

Here is how chromedriver is created in GebConfig.groovy:

  System.setProperty('webdriver.chrome.driver', chromeDriver.absolutePath)
  ChromeDriverService service = new ChromeDriverService.Builder()
      .usingDriverExecutable(new File(chromeDriver.absolutePath))
      .usingAnyFreePort()
      .build()

  ChromeOptions options = new ChromeOptions()
  options.addArguments("user-data-dir=test/drivers/chrome/.config/google-grey-chrome-profile",
      "--disable-webgl",
      "log-path=C:/test/chromedriver.log")
  File chromeBinary = new File("C:/test/Google/Chrome/Application/chrome.exe")
  options.setBinary(chromeBinary)

  new ChromeDriver(service, options)

Note that the path to chromedriver and chrome are given via system property and options respectively And here are the dependencies in BuildConfig.groovy:

dependencies {
[...]
provided("org.apache.httpcomponents:httpclient:$httpClientVersion")

test "org.spockframework:$spockVersion"
// runtime 'mysql:mysql-connector-java:5.1.16'
test("org.gebish:geb-spock:$gebGrailsVersion")
test("org.gebish:geb-junit4:$gebGrailsVersion")
test "org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion", { excludes "commons-io", "httpclient", 'nekohtml' }
test "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
test "org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion"
compile "org.apache.httpcomponents:httpclient:$httpClientVersion"

I have tried a lot of version combinations in vain, and I don't get any logs from chromedriver either, even by passing the log-path in the ChromeOptions.

Update:

I updated grails to 2.2.3, geb to 0.9.2, and now the full stack trace in the command prompt is the following (all still fine in Intellij):

|  geb.driver.DriverCreationException: failed to create driver from callback 'script13856991845071649825131$_run_closure1@91a
94b3'
        at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
        at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
        at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
        at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
        at geb.Configuration.createDriver(Configuration.groovy:354)
        at geb.Configuration.getDriver(Configuration.groovy:343)
        at geb.Browser.getDriver(Browser.groovy:105)
        at geb.Browser.go(Browser.groovy:394)
        at geb.Browser.go(Browser.groovy:386)
        at support.FunctionalSpec.setupSpec_closure1(FunctionalSpec.groovy:13)
        at geb.Browser.drive(Browser.groovy:860)
        at geb.Browser.drive(Browser.groovy:830)
        at support.FunctionalSpec.setupSpec(FunctionalSpec.groovy:12)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:218)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:161)
        at script13856991845071649825131.run_closure1(script13856991845071649825131.groovy:44)
        at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
4

1 回答 1

1

试试这个解决方案链接 这是我使用 ChromeDriver 修复的。在链接上下载您的版本,解压缩并按如下方式使用它:

System.setProperty("webdriver.chrome.driver", "<unzip location>/chromedriver");
driver = new ChromeDriver();

并更新 geb/spock版本

于 2013-10-23T08:56:40.360 回答