serenity-bdd / serenity-demos

64 stars 170 forks source link

Validate displayed element inside Task #42

Open manucolt92 opened 6 years ago

manucolt92 commented 6 years ago

Hi there!! I'm trying to validate some displayed elements in the page before do some things. But I don't know how. Anybody can helps me please? For e.g.

@Step("{0} adds a todo item called #thingToDo") public void performAs(T actor) { actor.attemptsTo( [VALIDATIONS HERE BEFORE ACTIONS] Enter.theValue(thingToDo).into(ToDoList.NEW_TODO_FIELD), Hit.the(RETURN).keyIn(ToDoList.NEW_TODO_FIELD) ); }

wakaleo commented 6 years ago

You can use something like:

actor.should(seeThat(the(TodoList.NEW_TODO_FIELD), isVisible()));
manucolt92 commented 6 years ago

I didn't explain myself very well sorry! I need to see those elements displayed and if those elements are not displayed, wait until they appear and then do some things like complete fields or do some clicks. It's something related to the transaction between pages. Thank you in advance!

wakaleo commented 6 years ago
actor.should(eventually(seeThat(the(TodoList.NEW_TODO_FIELD), isVisible())));

Or

actor.attemptsTo(
        WaitUntil.the(TodoList.NEW_TODO_FIELD,  isVisible()),
         ...
);

Or

actor.attemptsTo(
        WaitUntil.the(TodoList.NEW_TODO_FIELD,  isVisible()).forNoMoreThan(30).seconds(),
         ...
);
wakaleo commented 6 years ago

I prefer the first because it reads pretty much as you said "I need to see those elements displayed" == "the actor should see that the todo list field is visible"