grailsgroovyspockfunctional-testinggeb

Grails functional test Geb page object module not working No signature of method


This is the page object.

package myapp.pages
import geb.Page

class LoginPage extends Page {
    static url = "http://localhost:8080/login/auth"
    //static at = {title.contains("Login")}
    static at = {
        waitFor {title.contains("Login")} // Add waitFor here to verify on page
    }
    static content = {
        loginForm { $( 'form') }
        usernameField { $('form').userName }
        passwordField { $('form').password }
        submitButton { $('input#submit' )}
    }

    void  loginSubmit(String email, String password) {
        usernameField = "email@something.com"
        assert $('form').username == "email@something.com"
        passwordField = "secret"
        assert $('form').password == "secret"
        submitButton.click()
    }
}

And this is the LoginSpec test file

package myapp.login

import geb.spock.GebSpec
import grails.testing.mixin.integration.Integration
import grails.transaction.*
import myapp.pages.LoginPage

@Integration
@Rollback
class LoginSpec extends GebSpec {

    def setup() {
    }

    def cleanup() {
    }

    void "user successfully logs in, is redirected to homepage"() {
        given:
        to LoginPage

        when:
        LoginPage.loginSubmit("email@something.com", "secret")

        then:
        title.contains("Dashboard")
    }
}

When i run this test, I get the following error:

groovy.lang.MissingMethodException: No signature of method: static myapp.pages.LoginPage.loginSubmit() is applicable for argument types: (java.lang.String, java.lang.String) values: [email@something.com.com, secret]

I basically get the same error when I hardcode the username and password into the login page loginsubmit function. The selectors are fine, when I use the same selectors directly in the LoginSpec test to set the username and password, the test passes. The issue only occurs when I try to use the page object.


Solution

  • Instead of this:

        when:
        LoginPage.loginSubmit("email@something.com", "secret")
    

    Use this:

        when:
        loginSubmit("email@something.com", "secret")
    

    The issue isn't really a Geb one. The JVM doesn't allow you to invoke an instance method on a class reference as the context necessary to carry out that invocation wouldn't exist. loginSubmit is an instance method, not a static method.

    I hope that helps.