您好,我正在使用 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
谁能指导我解决这个问题。
最佳答案
您正在运行测试的服务器是“ headless ”的,因此没有显示来启动 Firefox 来运行测试。您有几个选择:
如果您需要直接在 Firefox 上进行测试,那么 HTMLUnit 不适合您。
使用 SauceLabs 或 BrowserStack 等远程浏览器服务有几个优点,例如它们可以录制 session 视频并截取屏幕截图,但我们发现通过网络传递命令和流量的开销使测试速度慢得令人无法接受.如果您需要测试多种浏览器,那么开销就会减少,因为您可以并行运行...
选项 2 使用虚拟显示器,在大多数服务器上配置起来最简单。如果您使用的是 Linux,X 虚拟帧缓冲区 (XVFB) 将使您快速启动并运行。值得一读正在发生的事情,但简短的回答是:
- 安装 XVFB(
sudo apt-get install xvfb
) - 安装 Firefox(
sudo apt-get install firefox
) - 启动 XVFB(
sudo Xvfb :10 -ac -screen 0 1024x768x8 &
)。您可能想添加一个初始化脚本,这样每次服务器启动时都会发生这种情况 - 在您的 CI 服务器中添加
export DISPLAY=:10
作为测试运行前的步骤 - 运行测试
XVFB 在 :10
上创建一个虚拟显示器,然后您将其设置为默认显示器。当您启动 Firefox 时,它完全不知道它在虚拟显示器上,因此让 Geb 截取失败测试的屏幕截图之类的事情将照常进行。
有关步骤的更多信息,请参阅:
- http://www.installationpage.com/selenium/how-to-run-selenium-headless-firefox-in-ubuntu/
- https://github.com/tomaslin/grails-test-recipes
- http://www.semicomplete.com/blog/geekery/xvfb-firefox.html
- http://www.labelmedia.co.uk/blog/setting-up-selenium-server-on-a-headless-jenkins-ci-build-machine.html
- http://manpages.ubuntu.com/manpages/lucid/man1/xvfb-run.1.html
如果您需要一个初始化脚本来启动/停止它,那么有很多可供选择,例如this one。 .
关于grails - 无法在服务器上运行功能测试。 [geb 斯波克],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23798250/