2013-06-24 36 views
2

我是GEB + Spock的新手,試圖在我們的項目中使用它。我有以下安裝:獲取GEB + Spock + Groovy中的錯誤

GEB- geb-core-0.7.0.jar 
SPOCK- Spock core-0.7 - groovy 2.0 
GROOVY- Groovy1.8.9 

下面是我的代碼,其中包含的方法。

package projectGEB 

import javax.lang.model.element.VariableElement; 
import org.codehaus.groovy.ast.Variable; 
import geb.* 
import groovy.model.ValueHolder; 
import spock.lang.* 
import geb.spock.* 

class GoogleSearchModule extends Module { 
class Google extends Page { 
    static url = "http://www.google.co.in/" 
    static at = { title == "Google" } 
    static content = { 
     searchField { $("input[name=q]") } 
     searchButton{ $("input[value=Google Search]") } 
    } 

    } 

} 

下面是我越來越強調$符號調用的方法*/

package projectGEB 

import spock.lang.Specification 
import geb.* 
import grails.plugin.geb.* 
import org.openqa.selenium.firefox.FirefoxDriver 
import org.openqa.selenium.ie.InternetExplorerDriver 


class DemoClass extends Specification { 

def "HelloProgram"(){ 
    expect: 
    Browser.drive(new Browser(driver: new FirefoxDriver())) { 

     to Google 
     println "Hello" 
    }.quit() 
} 
} 

。這是一個錯誤嗎?我如何解決它?

在此先感謝。

+5

爲什麼你使用'SP ock-core:0.7-groovy-2.0'與groovy 1.8.9?這是適合groovy 2 –

+0

你能顯示你的錯誤信息嗎? – plsgogame

回答

0

難道你是在一個模塊中嵌套頁面?通常頁面可以包含模塊,但我認爲相反的設計是不可能的。

在這種情況下,您應該刪除封裝頁面的模塊,並按原樣使用該頁面。

模塊是方便當你有條內容在多個頁面重用,這裏是一個如何使用一個模塊一個簡單的例子:

class MessagesModule extends Module { 

    static content = { 
    errorMessage { i -> $(".errors").find("li")[i] } 
    flashMessage { $(".message") } 
    } 

} 

該模塊然後輕鬆地在像網頁對象使用所以:

class GroupsPage extends Page { 

    static url = "group" 

    static at = { 
    $("h1").text() == "Groups" 
    $("h2").text() == "Select a group" 
    } 

    static content = { 
    groupEmail { $("input[name=email]") } 
    createGroup { $("#createGroup") } 
    searchGroup { $("#searchGroup") } 
    messages { module MessagesModule } 
    } 

} 

使用斯波克和創業板,您可以再編寫一個簡單的測試:

def "search non-existing group"() { 

    given: "I am on the groups page" 
    to GroupsPage 

    when: "I look for a non existing group" 
    page.groupEmail = "[email protected]" 
    page.searchGroup.click() 

    then: "I remain on that page, there is an info message" 
    at GroupsPage 
    page.messages.flashMessage.text() == "No group found" 
}