RequiredPageContentNotPresent error in geb 0.12.2

I am getting the following error when trying to run a geb test as a part of a Maven build in Eclipse:

Scenario: Perform login  Time elapsed: 0.009 sec  <<< FAILURE!
geb.error.RequiredPageContentNotPresent: The required page content 'userName - SimplePageContent (owner: LoginPage, args: [], value: null)' is not present

The only pattern to the error seems to be that it is thrown every time I try to use the geb selector to select/find some page content, but using the selector should work out-of-the-box, right?

I am using the following tools and libraries:

  • Eclipse Mars Java EE ID (version: 4.5.1)
  • geb (version 0.12.2)
  • Selenium (version 2.48.2)
  • Groovy (version 2.4.5)
  • Cucumber (version 1.2.4)

Here is my .feature file:

Feature: Login

  Scenario: Perform login
    Given the user is at the login page
    When the user enters <some_uid> and <some_pwd>
    Then the user should be logged in

Here is my steps definition:

package stepdefs

import pages.LoginPage

import static cucumber.api.groovy.EN.*

Given(~"the user is at the login page") { ->
    to LoginPage
    assert at(LoginPage)

When(~"the user enters (.*) (.*)") { user, password ->
    at LoginPage

Then(~"the user should be logged in"){ ->
    assert at(LoginResultPage)

Here is my page definition:

package pages

import geb.Page

class LoginPage extends Page {

    static url = "/TSADG_BORGER/"       
    static at = { title == "TastSelv Borger" }

       static content = {       
        loginForm { $($/form/$,id:"mainForm") }
        userName { loginForm.find("input",id:"pnr") }
        pass { loginForm.find("input",id:"tastselvKode") }
        buttonLogin { loginForm.find("input",id:"bt1") }

    def doLogin(user, password) {
        userName = user
        pass = password

Here is the HTML for the form:

<form id="mainForm" action="/TSADG_BORGER/" role="form" method="post" autocomplete="off">
                <input type="hidden" name="dispatch" value="Valider">       
                <div class="row skts-centered-padding">
                    <div class="col-sm-12">                         
                        <h1>Log på med TastSelv-kode</h1>
                    <div class="col-sm-6">
                        <div class="skts-process-form-section skts-required  ">
                            <p><label for="pnr">Cpr-nummer</label></p>
                                <input id="pnr" type="text" value="" class="form-control skts-required-val" name="pnr" size="16" maxlength="14" data-validation-event="blur" data-show-type="string" data-show-facets="pattern" data-show-facet-values="/(^\d{10}$)|(^\d{6}\-\d{4}$)/" aria-required="true" aria-invalid="false" aria-describedby="pnrError " autocomplete="off">                                   
                        <div class="skts-process-form-section skts-required">
                            <p><label for="tastselvKode">TastSelv-kode</label></p>
                                <input id="tastselvKode" type="password" value="" class="form-control skts-required-val" name="tastselvKode" size="16" maxlength="16" data-show-type="string" data-show-facets="pattern" data-show-facet-values="/^[^]{7,16}$/" data-validation-event="blur" aria-required="true" aria-invalid="false" aria-describedby="tastSelvKodeError " autocomplete="off">                                                                    
                            <input type="submit" id="bt1" class="btn btn-primary skts-validate" value="Fortsæt" autocomplete="off">

Any help and input is appreciated.


I would rearrange your content section a bit:

static content = {       
    loginForm { $("form#mainForm"") }
    userName { $("input#pnr") }
    pass { $("input#tastselvKode") }
    buttonLogin { $("input#bt1") }

Use jQuery selectors in Geb! They are very handy. Note that if you use unique ids $("#mainForm"") will have the same effect as $("form#mainForm""). First version is easier, second is more expressive ;)

More info:


The problem has been resolved.

I was so convinced that it had to be a problem with the selectors, so it took me a while to get my head out of the sand and take a step back. When I did that, I realised that the URL in the "LoginPage" class actually did a redirect to another page, which I was not expecting. The page I was redirected to did obviously not contain any of the objects I was looking for in my contents section. So, when the error message stated that "The required page not present", then that was absolutely correct.

Really silly mistake on my part...

Need Your Help

Facebook login throws "Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed

c# facebook facebook-login

I know this question was already asked many times, but still It seems to throw this error altough I tried several url addresses.

Objective-c - syntax for addObserver that returns a boolean value

objective-c parameters callback nsnotification addobserver

I am trying to add an sdk call to my Xcode project, and in their documentation, they say: