Search code examples
eclipsemavengroovygebcucumber-jvm

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
    page.doLogin(user,password)
}

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/loginpin.do"       
    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
        buttonLogin.click()
    }
}

Here is the HTML for the form:

<form id="mainForm" action="/TSADG_BORGER/loginpin.do" 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>                                              
                    <div class="col-sm-6">
                        <div class="skts-process-form-section skts-required  ">
                            <p><label for="pnr">Cpr-nummer</label></p>
                            <div>
                                <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>
                        </div>
                        <div class="skts-process-form-section skts-required">
                            <p><label for="tastselvKode">TastSelv-kode</label></p>
                            <div>
                                <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">                                                                    
                            </div>
                        </div>
                        <br>
                        <p>
                            <input type="submit" id="bt1" class="btn btn-primary skts-validate" value="Fortsæt" autocomplete="off">
                        </p>
                    </div>
                </div>
            </form>

Any help and input is appreciated.


Solution

  • 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 content...is not present", then that was absolutely correct.

    Really silly mistake on my part...