【问题标题】:windows 7 command prompt run grails functional testing with geb and spockwindows 7 命令提示符使用 geb 和 spock 运行 grails 功能测试
【发布时间】:2013-10-23 05:44:13
【问题描述】:

我似乎无法从命令提示符运行功能测试。有趣的是,它适用于 Intellij...

我正在使用 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"

这是错误:

 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 已启动(在正在运行的进程中可见),但显然它无法启动 chrome。

这是在 GebConfig.groovy 中创建 chromedriver 的方式:

  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)

请注意,chromedriver 和 chrome 的路径分别通过系统属性和选项给出 以下是 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"

我尝试了很多版本组合都是徒劳的,我也没有从 chromedriver 获得任何日志,即使通过在 ChromeOptions 中传递日志路径也是如此。

更新:

我将 grails 更新到 2.2.3,将 geb 更新到 0.9.2,现在命令提示符中的完整堆栈跟踪如下(在 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)

【问题讨论】:

    标签: grails functional-testing spock geb windows64


    【解决方案1】:

    试试这个解决方案link 我通过使用 ChromeDriver 解决了这个问题。在link上下载你的版本,解压并使用如下:

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

    并更新 geb/spock version

    【讨论】:

    • 谢谢,我将 geb/spock 更新为 0.9.2,并且我已经给出了 chromedriver 的路径(请参阅我的 GebConfig 的第一行)。正如我所提到的,它启动但无法启动 chrome。问题仍然存在,仅在从命令行尝试时才会发生。
    • 所以,如果您在 Intellij 中运行...并且一切正常,您可能遇到了 windows 环境问题吗?你可以运行grails --version 吗?或 java 的问题:java -version?
    • grails 版本:2.2.0,java 版本“1.7.0_40”Java(TM) SE 运行时环境(构建 1.7.0_40-b43)Java HotSpot(TM) 64 位服务器 VM(构建 24.0 -b56,混合模式)
    • @Calahad 我不知道如何帮助你,但我认为环境有问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 2012-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多