【问题标题】:Grails - Selenium-RC plugin - Starting Selenium serverGrails - Selenium-RC 插件 - 启动 Selenium 服务器
【发布时间】:2011-12-06 17:01:13
【问题描述】:

我正在尝试通过 Selenium-RC 插件在我的 Grails 项目中设置 Selenium。 然后我运行了grails install-plugin selenium-rc 命令。

然后,我运行了grails create-selenium-test firstTest 命令,并在其中添加了以下内容:

import grails.plugins.selenium.*
import org.junit.*
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*

@Mixin(SeleniumAware)
class FirstTestTests {
    @Before void setUp() {
    }

    @After void tearDown() {
        super.tearDown()
    }

    @Test void something() {
        selenium.open "/"
        assertTrue selenium.isTextPresent("Bem vindos")
    }
}

当我在 Ubuntu 11.04 上运行测试时,Grails 会启动默认的 firefox 浏览器(8.0 版),但在将其打印到控制台输出后会在此处冻结:

    Server running. Browse to http://localhost:8080/
  [groovyc] Compiling 1 source file to /home/alessandro/Documents/[...]/target/test-classes/selenium
Starting Selenium server on port 4444 ...
Starting Selenium session for http://www.mywebsite.com/ ...

当我通过 Ctrl + C 中断测试时,它会抛出以下错误消息:

    Error running selenium tests: java.lang.RuntimeException: Could not contact Selenium Server; have you started it on 'localhost:4444' ?
Read more at http://seleniumhq.org/projects/remote-control/not-started.html
Connection refused
java.lang.RuntimeException: Could not contact Selenium Server; have you started it on 'localhost:4444' ?
Read more at http://seleniumhq.org/projects/remote-control/not-started.html
Connection refused
    at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:86)
        at com.thoughtworks.selenium.Selenium$start$0.call(Unknown Source)
    at grails.plugins.selenium.SeleniumWrapper.start(SeleniumWrapper.groovy:90)
    at com.thoughtworks.selenium.Selenium$start.call(Unknown Source)
    at grails.plugins.selenium.SeleniumRunner.startSelenium(SeleniumRunner.groovy:35)
    at grails.plugins.selenium.SeleniumRunner$startSelenium.call(Unknown Source)
    at _Selenium_groovy$_run_closure2.doCall(_Selenium_groovy:50)
    at _Events$_run_closure3.doCall(_Events.groovy:32)
    at _GrailsEvents_groovy$_run_closure5.doCall(_GrailsEvents_groovy:58)
    at _GrailsEvents_groovy$_run_closure5.call(_GrailsEvents_groovy)
    at _GrailsTest_groovy$_run_closure4.doCall(_GrailsTest_groovy:265)
    at _GrailsTest_groovy$_run_closure4.call(_GrailsTest_groovy)
    at _GrailsTest_groovy$_run_closure2.doCall(_GrailsTest_groovy:228)
    at _GrailsTest_groovy$_run_closure1_closure21.doCall(_GrailsTest_groovy:187)
    at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:174)
    at TestApp$_run_closure1.doCall(TestApp.groovy:82)
    at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
    at gant.Gant.withBuildListeners(Gant.groovy:427)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at gant.Gant.dispatch(Gant.groovy:415)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at gant.Gant.invokeMethod(Gant.groovy)
    at gant.Gant.executeTargets(Gant.groovy:590)
    at gant.Gant.executeTargets(Gant.groovy:589)

我已经阅读了插件文档,它说服务器是由插件启动的,在测试冻结之前由控制台输出支持。我真的不知道从那里去哪里。 我已经浏览了网页,但我发现的唯一建议是将 selenium-server.jar 添加到 java 路径,这似乎已经被插件覆盖。

非常感谢任何帮助。

【问题讨论】:

    标签: grails selenium selenium-rc selenium-webdriver functional-testing


    【解决方案1】:

    我遇到了同样的问题 - 您可以查看我的 question。我猜是firefox的问题——我把它改成了Chrome,它开箱即用。 你只需要更换

      browser = "*firefox"
    

      browser = "*googlechrome" 
    

    在 SeleniumConfig 中

    【讨论】:

      【解决方案2】:

      非常感谢。它像你说的那样工作。对于那些在 Ubuntu 下也使用 Chromium 的人,这是我为配置 SeleniumConfig 文件添加的内容:

      browser = "*googlechrome /usr/lib/chromium-browser/chromium-browser"
      

      现在我明白了:

          Stopping Selenium server ...
      java.lang.RuntimeException: Can't start SslRelay: server is not started (perhaps it was just shut down?)
          at org.openqa.selenium.server.ProxyHandler.getSslRelayOrCreateNew(ProxyHandler.java:656)
          at org.openqa.selenium.server.ProxyHandler.handleConnect(ProxyHandler.java:589)
          at org.openqa.selenium.server.ProxyHandler.handle(ProxyHandler.java:274)
          at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
          at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
          at org.openqa.jetty.http.HttpServer.service(HttpServer.java:909)
          at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
          at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
          at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
          at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:245)
          at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
          at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
      

      测试通过后。 我会对此进行调查。 谢谢 mkk

      【讨论】:

        猜你喜欢
        • 2011-12-07
        • 1970-01-01
        • 2011-01-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-12
        • 2010-09-12
        • 1970-01-01
        相关资源
        最近更新 更多