2011-12-03 37 views
2

我不知道我做錯了什麼。我想用Grails的selenium-RC插件做一些功能測試。grails + selenium-rc插件 - 無法運行樣本測試

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 [email protected] 
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 [email protected] 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窗口打開,但沒有加載,似乎沒有任何進展。我想念什麼?

回答

1

聽起來像Selenium RC插件和當前版本的Web瀏覽器之間的不兼容。如果您使用更新版本的瀏覽器,您可能需要深入瞭解插件的依賴關係,並將所有內容更新爲最新版本。

當試圖運行與驅動程序版本不兼容的網絡驅動程序版本時,我們在Geb(http://www.gebish.org)中看到了這一點。

+0

謝謝托馬斯一個想法 - 我會盡量 – mkk

+0

你是男人改變瀏覽器!謝謝,我改變了鉻,它的工作'開箱':) – mkk

0

我想補充,如果你使用Chrome瀏覽器與操作系統是Ubuntu的,然後確保你把完整路徑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 = "" 
} 
+0

更新:這取決於你的Linux發行版的鉻。如果你有谷歌瀏覽器,那麼它被稱爲谷歌瀏覽器,否則你有Ubuntu打包鉻,在這種情況下,它是鉻瀏覽器。詳情請參閱http://code.google.com/p/chromium/wiki/ChromiumBrowserVsGoogleChrome – Tone