How do I verify multiple text elements and links in the bdd using Serenity BDD ?
I am using below code but using this approach i have to write same copy of code for every element on the webpage which is timeconsuming, is there any alternate way to parametrize and verify values
private static final String APIBUILDER = "app-data-api-card .card-header";
@Subject("the displayed notebook")
public static class APIBUILDER implements Question<String> {
@Override
public String answeredBy(Actor actor) {
return BrowseTheWeb.as(actor).findBy(APIBUILDER).getText();
}
public static Question<String> value() { return new APIBUILDER(); }
You can use the Ensure library
static By FIRST_NAME_FIELD = By.id("first_name");
static By LAST_NAME_FIELD = By.id("last_name");
actor.attemptsTo(
Ensure.that(FIRST_NAME_FIELD).text().isEqualTo("Foo")
Ensure.that(LAST_NAME_FIELD).text().isEqualTo("Bar")
);
If you want soft assertions, you could also do this:
Ensure.enableSoftAssertions();
actor.attemptsTo(
Ensure.that(FIRST_NAME_FIELD).text().isEqualTo("Foo")
Ensure.that(LAST_NAME_FIELD).text().isEqualTo("Bar")
);
Ensure.reportSoftAssertions();