gpt4 book ai didi

grails - 无法在Grails上将Cucumber与Geb集成

转载 作者:行者123 更新时间:2023-12-02 14:53:41 24 4
gpt4 key购买 nike

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

| 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工具套件中运行测试:
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() }
}

}

最佳答案

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

关于grails - 无法在Grails上将Cucumber与Geb集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15558162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com