【问题标题】:How to integrate scalatest with selenium如何将 scalatest 与 selenium 集成
【发布时间】:2012-11-28 23:43:49
【问题描述】:

通过阅读 http://www.scalatest.org/user_guide/using_selenium 我正在尝试整合 selenium 和 scalatest selenium DSL。

这是我正在使用的代码:

class BlogSpec extends FlatSpec with ShouldMatchers with Chrome {


    System.setProperty("webdriver.chrome.driver", "C:\\selenium-drivers\\chromedriver.exe"); 
    val host = "http://www.google.com"

    go to (host)
    title should be ("Awesome Blog")

}

但我收到此错误:

* RUN ABORTED * java.lang.IllegalStateException: 驱动程序可执行文件的路径必须由 webdriver.chrome.driver 系统设置 财产;有关详细信息,请参阅 http://code.google.com/p/selenium/wiki/ChromeDriver。最新的 版本可以从 http://code.google.com/p/chromedriver/downloads/list 在 com.google.common.base.Preconditions.checkState(Preconditions.java:176) 在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:118) 在 org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:61) 在 org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:107) 在 org.scalatest.selenium.Chrome$class.$init$(WebBrowser.scala:3756)
在 BlogSpec.(BlogSpec.scala:12) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 在 java.lang.reflect.Constructor.newInstance(Constructor.java:513)
...

驱动程序确实存在于C:\\selenium-drivers\\chromedriver.exe 我是否正确设置了驱动程序或者上面的代码中是否存在单独的问题? Chrome 也没有启动

【问题讨论】:

    标签: scala selenium scalatest


    【解决方案1】:

    我认为上面代码中的System.setProperty 只有在 Chrome 被实例化后才会被调用,这意味着在引发上述错误之后。也许您应该尝试使用-D 设置系统属性。

    【讨论】:

    • 如何使用 -D 设置系统属性?我找不到任何对它的 java 引用?
    【解决方案2】:

    我使用 Maven 自动运行 ScalaTest Selenium 集成测试。我没有使用 ChromeDriver,而是使用了 HtmlUnit 驱动程序。使用 Maven,您还可以通过命令行使用“-Dxxx”设置自定义属性。

    查看:https://bitbucket.org/olimination/hello-scalajava/overview 获取使用 Scala/Java 的示例 Maven webapp 项目。

    【讨论】:

      【解决方案3】:

      或者你可以尝试这个而不是从 Chrome 扩展

      private val chromeDriverPath = "~/Downloads/chromedriver"
      System.setProperty("webdriver.chrome.driver", chromeDriverPath)
      import Chrome._
      `
      

      【讨论】:

        猜你喜欢
        • 2011-09-11
        • 2014-03-28
        • 2015-02-25
        • 1970-01-01
        • 1970-01-01
        • 2015-10-02
        • 2011-12-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多