Klaas-Jan Hofstede
Klaas-Jan Hofstede

Reputation: 9

Custom messages in logging for failing tests with Geb/Spock?

I'm busy with an e2e test in Geb/Spock, I was wondering how I can add custom messages. Now I only get a stacktrace like this:

geb.error.RequiredPageContentNotPresent: The required page content 'pages.patientConversation.PcModal -> contact: geb.navigator.EmptyNavigator' is not present
    at geb.content.TemplateDerivedPageContent.require(TemplateDerivedPageContent.groovy:60)
    at geb.content.PageContentTemplate.create_closure1(PageContentTemplate.groovy:63)
    at geb.content.PageContentTemplate.create_closure1(PageContentTemplate.groovy)

etc ...

This is an example of my test:

 def "allow for searching contacts"() {
    when:
    to LoginPage
    login(emailAddress, defaultPassword)
    then:
    at QuickBar
    when:
    startButton.click()
    then:
    at Modal
    when:
    selectContactButton.click()
    contactSearchField.value(context.pcUser2.surname)
    then: "the contact is shown in the search results"
    contact.isDisplayed()
}

I figured the text "the contact is shown in the search results" would be present in the error message, but apparently it doesn't. Is there maybe another way in Geb of Spock to print custom messages for more clarity?

Especially for 'at checkers' I would like to have custom messages, because when an at check fails, you only get:

java.lang.NoSuchMethodError: geb.error.GebAssertionError.<init>(Ljava/lang/Object;Ljava/lang/Throwable;)V

at geb.waiting.WaitTimeoutException.<init>

etc

EDIT: Hmmm I realize now, the test failed because it also checks for the required page content, before doing the "then". Still I would like the ability to add custom messages (especially for 'at checkers') ... Does anybody know if that is possible?

Upvotes: 0

Views: 1321

Answers (1)

Royg
Royg

Reputation: 1685

You can use the custom-message to add a custom message to WaitTimeoutException

class HomePage extends Page {

    static at = {
        waitFor(message:"My custom message")    {title == "Acme Corporation"}
        waitFor(message:"My custom message",20) {$("#roadRunner")}
    }
}

Upvotes: 7

Related Questions