您好我正在使用geb运行我的功能测试。 我能够正确地在本地计算机上运行测试。但是当我将我的应用程序部署到服务器时功能测试的构建失败。
这是我的控制台输出
|Running 10 spock tests... 1 of 10
Failure: |
sign in with voucher
|
geb.driver.DriverCreationException: failed to create driver from callback 'script14007213321291157436758$_run_closure1@77068fce'
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:346)
at geb.Configuration.getDriver(Configuration.groovy:335)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.go(Browser.groovy:377)
at geb.Page.to(Page.groovy:171)
at geb.Browser.via(Browser.groovy:454)
at geb.Browser.to(Browser.groovy:413)
at geb.Browser.to(Browser.groovy:391)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:51)
at VoucherSpec.sign in with voucher(VoucherSpec.groovy:14)
Caused by: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/local/bin/firefox) on port 7056; process output follows:
Error: no display specified
Error: no display specified
任何人都可以指导我解决这个问题。
答案 0 :(得分:3)
您正在运行测试的服务器是“无头”,因此没有显示器来启动Firefox以运行测试。你有几个选择:
如果您需要直接在Firefox上进行测试,那么HTMLUnit不适合您。
使用SauceLabs或BrowserStack等远程浏览器服务有一些优点,例如他们录制了会话视频并截取屏幕截图,但我们发现了传递命令的开销。通过网络的流量使测试速度慢得令人无法接受。如果您需要测试各种各样的浏览器,那么开销就会减少,因为您可以并行运行...
使用虚拟显示器的选项2是大多数服务器上最简单的配置。如果您正在使用Linux,X虚拟帧缓冲区(XVFB)将帮助您快速启动并运行。值得一读的是正在发生的事情,但简短的回答是:
sudo apt-get install xvfb
)sudo apt-get install firefox
)sudo Xvfb :10 -ac -screen 0 1024x768x8 &
)。您可能希望添加一个init脚本,以便每次服务器启动时都会发生这种情况export DISPLAY=:10
作为步骤 XVFB在:10
上创建虚拟显示,然后将其设置为默认显示。当你启动Firefox时,它完全没有意识到它是在虚拟显示器上,所以让Geb获取失败测试的屏幕截图之类的东西将正常工作。
有关步骤的详细信息,请参阅:
如果你需要一个init脚本来启动/停止它,那么有很多可供选择,例如this one。