Serenity BDD 剧本验证网页上的多个文本元素

Serenity BDD screenplay verify multiple text elements on the webpage

如何使用 Serenity BDD 验证 bdd 中的多个文本元素和链接?

我正在使用下面的代码,但使用这种方法我必须为网页上的每个元素编写相同的代码副本,这很耗时,是否有任何替代方法来参数化和验证值

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(); }

您可以使用 Ensure 库

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")
);

如果你想要软断言,你也可以这样做:

    Ensure.enableSoftAssertions();
    actor.attemptsTo(
        Ensure.that(FIRST_NAME_FIELD).text().isEqualTo("Foo")
        Ensure.that(LAST_NAME_FIELD).text().isEqualTo("Bar")
    );
    Ensure.reportSoftAssertions();