1

我正在尝试设置 Grails (2.2) + Cucumber (0.8.0) + Geb (0.9.0-RC-1) 环境,但我的 Cucumber 步骤定义没有找到 Geb 页面 - 因此,我得到了很多缺少属性异常:

| Server running. Browse to http://localhost:8080/weddo
| Compiling 3 source files.
| Running 13 cucumber tests...
groovy.lang.MissingPropertyException: No such property: page for class: WishlistStepDefinitions
    at WishlistStepDefinitions$_run_closure5.doCall(WishlistStepDefinitions.groovy:68)
    at ?.Then the total gifted amount should be 0(ChoosingGift.feature:14)
groovy.lang.MissingMethodException: No signature of method: WishlistStepDefinitions.wishAmountsFromCategory() is applicable for argument types: (java.lang.Integer) values: [1]
    at WishlistStepDefinitions$_run_closure6.doCall(WishlistStepDefinitions.groovy:72)
    at ?.And I write "1" on every wish on the 1 category(ChoosingGift.feature:25)
groovy.lang.MissingMethodException: No signature of method: WishlistStepDefinitions.namedWishAmountFromCategory() is applicable for argument types: (java.lang.String, java.lang.Integer) values: [wish_1_2, 0]
    at WishlistStepDefinitions$_run_closure7.doCall(WishlistStepDefinitions.groovy:78)
...

WishlistStepDefinitions.groovy(顶部):

import static cucumber.api.groovy.EN.*

import weddo.Wish
import weddo.WishCategory

import pages.WishlistPage

Given(~'^I am on the "([^"]*)" page$') { String pageName ->
    if (pageName.matches(/wishlist/)) {
        to WishlistPage
    }
}

Then(~'^the total gifted amount should be (\\d+)$') { int expectedTotalAmount ->
    assert page.totalAmount.value() == expectedTotalAmount 
}

When(~'^I write "([^"]*)" on every wish on the (\\d+) category$') { String amount, int categoryPosition ->
    wishAmountsFromCategory(categoryPosition).each {
        it.value(amount)
    }
}
...

WishlistPage.groovy(顶部):

package pages

import geb.Page
import org.openqa.selenium.Keys

class WishlistPage extends Page {
    static url = "/"
    static at = {
        title.startsWith("Wishlist")
    }

    static content = {
        totalAmount = {
            $("#amount")
        }
        wishAmountsFromCategory = { categoryIndex ->
            $(".category", categoryIndex).find(".wishes input[data-bind*='currentGiftAmount']")
        }
        wishAmountFromName = { wishName ->
            $(".wishes .control-group").find(".control-label", text: wishName).parent().parent().find("input[data-bind*='currentGiftAmount']")
        }
...

还有一个 GebConfig.groovy、CucumberConfig.groovy 和 env.groovy。最后一个应该将步骤定义粘合到 Geb 页面(据我所知)。但它似乎没有被执行。这是它的内容(env.groovy):

import geb.binding.BindingUpdater
import geb.Browser

import static cucumber.api.groovy.Hooks.*

def bindingUpdater
Before () {
    bindingUpdater = new BindingUpdater (binding, new Browser ())
    bindingUpdater.initialize ()
}

After () {
    bindingUpdater.remove ()
}

我在 Eclipse Groovy/Grails Tool Suite 中运行测试,使用:

grails test-app functional:cucumber

有人可以帮忙吗?

编辑:第一个错误(第 68 行)是指此代码中的断言:

67. Then(~'^the total gifted amount should be (\\d+)$') { int expectedTotalAmount ->
68.     assert page.totalAmount.value() == expectedTotalAmount 
69. }

编辑 2:在 BuildConfig.groovy 中,我有(摘录):

    ...
    def gebVersion = "0.9.0-RC-1" //"0.7.2"
    def cukesVersion = "0.8.0"
    def seleniumVersion = "2.27.0" //"2.25.0"

    dependencies {
        test("org.seleniumhq.selenium:selenium-htmlunit-driver:$seleniumVersion") {
            exclude "xml-apis"
        }
        test("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion")
        test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion")
        test "org.gebish:geb-junit4:$gebVersion"
    }

    plugins {
        runtime ":hibernate:$grailsVersion"
        runtime ":jquery:latest.release"
        runtime ":resources:latest.release"

        compile ":google-visualization:latest.release"
        compile ":cloud-foundry:1.2.3"

        test "org.grails.plugins:geb:$gebVersion"
        test ":cucumber:$cukesVersion"
        // Uncomment these (or add new ones) to enable additional resources capabilities
        //runtime ":zipped-resources:1.0"
        //runtime ":cached-resources:1.0"
        //runtime ":yui-minify-resources:0.1.4"

        build ":tomcat:$grailsVersion"
    }
}

和 grails-conf/CucumberConfig.groovy:

cucumber {
    features = ["test/cucumber/wishlist"]
    glue = ["test/cucumber/steps"]
}

和测试/功能/GebConfig.groovy

import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.chrome.ChromeDriver

// Use htmlunit as the default
// See: http://code.google.com/p/selenium/wiki/HtmlUnitDriver
driver = { 
    def driver = new HtmlUnitDriver()
    driver.javascriptEnabled = true
    driver
}

environments {

    // run as “grails -Dgeb.env=chrome test-app”
    // See: http://code.google.com/p/selenium/wiki/ChromeDriver
    chrome {
        driver = { new ChromeDriver() }
    }

    // run as “grails -Dgeb.env=firefox test-app”
    // See: http://code.google.com/p/selenium/wiki/FirefoxDriver
    firefox {
        driver = { new FirefoxDriver() }
    }

}
4

1 回答 1

0

我认为不支持 HtmlUnitDriver。从配置中删除它并将 Firefox 驱动程序设置为默认值。

于 2013-07-14T14:05:39.063 回答