Search code examples
javaintellij-ideagherkincucumber-serenity

Serenity Java predicate failed


I am developing some automated tests with Java 11.0.11 over Serenity+Cucumber+Gherkin in ScreenPlay pattern

have already done over a dozen stepsDefinition currently working without error but this one:

//SomeStepDefinitions.java:
String bar = "my String";

105:       theActorInTheSpotlight().should(
                seeThat(
                        theActorInTheSpotlight -> XPATH_TARGET1.resolveFor(theActorInTheSpotlight).getText()
                        , equalTo(bar)
                )
        );

throws arbitriarly

TEST FAILED

17:04:45.023 [Test worker] DEBUG  - RELATED ISSUES: 
17:04:45.087 [Test worker] ERROR  -     Test failed at step: Then do something step definitions$$ lambda$796/0x00000001006ce840 should be Predicates.equalTo(my String)
17:04:45.087 [Test worker] ERROR  -     predicate failed

predicate failed
java.lang.AssertionError: predicate failed
    at net.serenitybdd.screenplay.ErrorTally.throwSummaryExceptionFrom(ErrorTally.java:38)
    at net.serenitybdd.screenplay.ErrorTally.reportAnyErrors(ErrorTally.java:32)
    at net.serenitybdd.screenplay.Actor.should(Actor.java:322)
    at stepdefinitions.Folder1.Folder2.SomeStepDefinitions.Foo(SomeStepDefinitions.java:105)

any thoughs?


Solution

  • To anyone with this problem, already bypassed the problem with:

            theActorInTheSpotlight().attemptsTo(
                    Ensure.that(FOO.value().answeredBy(theActorInTheSpotlight())).isEqualTo(bar)
            );
    
    
    class FOO extends WebDriverQuestion implements Question<String> {
        @Override
        public String answeredBy(Actor actor) {
                return Text.of(XPATH_TARGET1).viewedBy(actor).asString();
        }
        public static FOO value(){
            return new FOO();
        }
    }
    

    I still want to know why initial code failed randomly.