Grails + selenium-rc插件-不能运行样例测试



我不知道我做错了什么。我想使用selenium-RC插件为Grails做一些功能测试。我使用内置脚本(我猜add-selenium-test)创建了示例测试,它生成(我稍微修改了一下):

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 "/activate"
    assertTrue selenium.isTextPresent("activate")
  }
}

我配置了SeleniumConfig

硒{

  slow = false                                  // true to run tests in slow resources mode
  singleWindow = true                               // true for single window mode, false for multi-window mode
  browser = "*firefox"                          // can include full path to executable, default value is *firefox or *iexplore on Windows
  url = "http://localhost:8080"                                     // the base URL for tests, defaults to Grails server url
  defaultTimeout = 3000                         // the timeout after which selenium commands will fail
  windowMaximize = true                     // true to maximize browser on startup
  screenshot {
    dir = "./target/test-reports/screenshots"   // directory where screenshots are placed relative to project root
    onFail = true                           // true to capture screenshots on test failures
  }
  server {
    host = "localhost"                          // the host the selenium server will run on
    port = 4444                                 // the port the selenium server will run on
  }
  userExtensions = ""                               // path to user extensions javascript file
}

然后我输入

  grails test-app :selenium

,似乎一切都做对了:

INFO 19:30:08,304 RemoteWebDriver instances should connect to: http://127.0.0.1:
4444/wd/hub org.openqa.selenium.server.SeleniumServer
Starting Selenium server on port 4444 ...
INFO 19:30:08,312 Version Jetty/5.1.x org.openqa.jetty.http.HttpServer
INFO 19:30:08,315 Started HttpContext[/selenium-server/driver,/selenium-server/d
river] org.openqa.jetty.util.Container
INFO 19:30:08,318 Started HttpContext[/selenium-server,/selenium-server] org.ope
nqa.jetty.util.Container
INFO 19:30:08,321 Started HttpContext[/,/] org.openqa.jetty.util.Container
INFO 19:30:08,326 Started org.openqa.jetty.jetty.servlet.ServletHandler@55881a8f
 org.openqa.jetty.util.Container
INFO 19:30:08,328 Started HttpContext[/wd,/wd] org.openqa.jetty.util.Container
INFO 19:30:08,338 Started SocketListener on 0.0.0.0:4444 org.openqa.jetty.http.S
ocketListener
INFO 19:30:08,340 Started org.openqa.jetty.jetty.Server@42aefb01 org.openqa.jett
y.util.Container
Starting Selenium session for http://localhost:8080 ...
INFO 19:30:08,502 Checking Resource aliases org.openqa.jetty.util.Credential
INFO 19:30:08,510 Command request: getNewBrowserSession[*firefox, http://localho
st:8080, ] on session null org.openqa.selenium.server.SeleniumDriverResourceHand
ler
INFO 19:30:08,512 creating new remote session org.openqa.selenium.server.Browser
SessionFactory
INFO 19:30:08,586 Allocated session 9250557308cc4886a25100eb6c5f3d7e for http://
localhost:8080, launching... org.openqa.selenium.server.BrowserSessionFactory
INFO 19:30:08,717 Preparing Firefox profile... org.openqa.selenium.server.browse
rlaunchers.FirefoxChromeLauncher
INFO 19:30:11,726 Launching Firefox... org.openqa.selenium.server.browserlaunche
rs.FirefoxChromeLauncher

firefox窗口打开了,但是没有加载任何东西,似乎也没有任何进展。我错过什么了吗?

听起来像是Selenium RC插件和当前版本的web浏览器之间的不兼容。如果你使用的是较新版本的浏览器,你可能需要深入研究插件的依赖关系,并将所有内容更新到最新版本。

当尝试运行与驱动程序版本不兼容的webdriver版本时,我们会在Geb (http://www.gebish.org)中看到这种情况。

只是补充一下,如果你使用Chrome,你的操作系统是Ubuntu,那么确保你把Chrome的完整路径,并确保可执行路径引用 Chrome -browser而不是 google-chrome。

所以你的SeleniumConfig应该看起来像这样,相关行用双星号表示:

selenium {
   slow = false
   singleWindow = true
   **browser = "*googlechrome /usr/bin/chromium-browser"**
   url = null
       defaultTimeout = 60000
   windowMaximize = false
   screenshot {
       dir = "./target/test-reports/screenshots"
       onFail = false
   }
   server {
       host = "localhost"
       port = 4444
   }
   userExtensions = ""
}

最新更新