3
votes

I have a secured grails application with the spring security plugin and right now I am trying to do some tests with the login process with no success till now. Has anybody an idea of what is the problem?

This is my LoginPage.groovy

package pages.login

import geb.Page


class LoginPage extends Page {
    static url = "login/auth"

    static at = {
        title ==~ /Login/
    }

    static content = {
        loginForm { $("form") }
        username { $("input", type:"text", name:"j_username") }
        password { $("input", type:"password", name:"j_password") }
        loginButton{ $("input", type:"submit", value:"Login") }
    }
}

And this is the test using junit4:

import geb.junit4.GebReportingTest

import pages.copyright.*
import pages.login.LoginPage
import org.junit.Test

class CopyrightCRUDTests extends GebReportingTest {

    @Test
    void doSomeCrud() {

        to LoginPage
        at LoginPage
        $("form").j_username() << "admin"
        $("form").j_password() << "XXXXX"
        loginButton.click()

        to AuthenticatedPage
        at AuthenticatedPage

    }
}

The AuthenticatedPage is a page which needs authentication, but in this moment it is imposible to be authenticated using geb. Does anybody know anything about this issue?

Thanks in advance!

2
what's the error you are getting? use firefox driver and see what is going on... - zoran119
You shouldn't need this: to AuthenticatedPage - 34m0
Also at LoginPage is unnecessary - Armand

2 Answers

0
votes

Try rewriting doSomeCrud() as follows:

to LoginPage
loginForm.j_username = 'admin'
loginForm.j_password = 'XXXXX'
loginButton.click()
waitFor { at AuthenticatedPage }
0
votes

I don't know if this will help you since you are not using Spock, but I had a few issues with login as well (can't remember exactly what though)

I eventually found this code that I put in a spec extending GebSpec.

This gets called before each of the tests requiring a login:

  def setupSpec() {
    Browser.drive {
      go baseUrl
        $("form.login").with {
          username = System.getenv("APP_USERNAME")
          password = System.getenv("APP_PASSWORD")
        }
        $("input[name='submit']").click()
      }
  }

It doesn't seem like much, but the use of 'with' on the form worked for me.