1
votes

I'm trying to setup a Grails (2.2) + Cucumber (0.8.0) + Geb (0.9.0-RC-1) environment but my Cucumber step definitions are not finding the Geb pages - hence, I'm getting lots of 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 (the top part):

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 (top part):

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']")
        }
...

There's also a GebConfig.groovy, CucumberConfig.groovy and env.groovy. This last one should glue the step definitions to the Geb pages (from what I know). But it seems not be being executed. Here's its contents (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 ()
}

I'm running the tests inside Eclipse Groovy/Grails Tool Suite using:

grails test-app functional:cucumber

Can someone help?

EDIT: The first error (on line 68) refers to the assertion in this code:

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

EDIT 2: Inside BuildConfig.groovy, I have (excerpt):

    ...
    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"
    }
}

And grails-conf/CucumberConfig.groovy:

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

And test/functional/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() }
    }

}
1
please write WishlistStepDefinitions.groovy:68 line code - plsgogame
hey @plsgogame, I've just updated the post with that line of code. Thanks! - fegemo
grails config please, i add cucumber plugin on dependencies ? - plsgogame
@plsgogame, I've just update the post again - fegemo
so, i think, i can try run example on official page, for understanding our problem. try github.com/hauner/grails-cucumber/wiki/… . Thx, i dont use cucumber, but i use spock with geb and all work correct. - plsgogame

1 Answers

0
votes

I think that HtmlUnitDriver is not supported. Delete it from config and set Firefox driver as default.