我正在尝试通过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路径中,这似乎已被插件所涵盖。
任何帮助非常感谢。
答案 0 :(得分:1)
我遇到了同样的问题 - 你可以看到我的question。我猜的问题是firefox - 我把它改成了Chrome,开箱即用。 你只需要替换
browser = "*firefox"
带
browser = "*googlechrome"
在SeleniumConfig中
答案 1 :(得分:0)
非常感谢你。它像你说的那样奏效。对于那些在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