Jacobvu84 / serenity-pageobject-junit-webdriver

4 stars 1 forks source link

Kiểm tra số lượng elements có cùng locator #67

Open Jacobvu84 opened 4 years ago

Jacobvu84 commented 4 years ago

Example:

import static net.serenitybdd.screenplay.questions.AggregateQuestions.theTotalNumberOf;

...
     then(theActorInTheSpotlight()).should(
                seeThat(theTotalNumberOf(row(ChatScreen.TEXT.of(message))), equalTo(2)));

Trong ví dụ trên, kiểm tra trong trong màn hình chat có 2 dòng tin nhắn.

Jacobvu84 commented 4 years ago

serenity core

package net.serenitybdd.screenplay.questions;

import net.serenitybdd.screenplay.Question;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;

public class AggregateQuestions {

    public static <T> Question<Integer> theTotalNumberOf(Question<? extends Collection<T>> listQuestion) {
        return new CountQuestion(listQuestion);
    }

................

Your implement

public class WebElementArrayQuestion implements Question<List<WebElementState>> {
    private final Target target;

    public WebElementArrayQuestion(Target target) {
        this.target = target;
    }

    @Override
    public List<WebElementState> answeredBy(Actor actor) {
        return new ArrayList<>(target.resolveAllFor(actor));
    }

    public static Question<List<WebElementState>> row(Target target) {
        return new WebElementArrayQuestion(target);
    }
}