Jacobvu84 / serenity-pageobject-junit-webdriver

4 stars 1 forks source link

Tạo Question Object trong serenity #81

Open Jacobvu84 opened 3 years ago

Jacobvu84 commented 3 years ago
  1. Xây dựng model object cần kiểm tra.
public class AdvertisementInfor {
    private final String title;
    private final String sponsor;
    private final String adType ;

    public AdvertisementInfor(String title, String sponsor, String adType) {
        this.title = title;
        this.sponsor = sponsor;
        this.adType = adType;
    }

    public String getTitle() {
        return title;
    }

    public String getSponsor() {
        return sponsor;
    }

    public String getAdType() {
        return adType;
    }

    @Override
    public String toString() {
        return String.format("{Title='%s', Sponsor='%s', Ad Type ='%s'}", title, sponsor, adType);
    }
}
Jacobvu84 commented 3 years ago
  1. Tạo câu hỏi
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Question;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.serenitybdd.screenplay.questions.Text;

import static net.serenitybdd.screenplay.questions.ValueOf.the;

public class Advertisement implements Question<AdvertisementInfor> {

    @Override
    public AdvertisementInfor answeredBy(Actor actor) {
        String title = BrowseTheWeb.as(actor).getTitle();
        String sponsor = the(Text.of(SPONSOR).viewedBy(actor));
        String adType = the(Text.of(AD_TYPE).viewedBy(actor));

        return new AdvertisementInfor(title, sponsor, adType);
    }

    public static Advertisement information() {
        return new Advertisement();
    }
}
Jacobvu84 commented 3 years ago
  1. Cách dùng
import static net.serenitybdd.screenplay.GivenWhenThen.*;
import static net.serenitybdd.screenplay.matchers.ConsequenceMatchers.displays;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.Is.is;

@Test
    public void should_be_able_to_identify_the_advertisement() {

        .............
        jacob.should(
            seeThat(Advertisement.information(),
                displays("Title",equalTo("Quần áo trẻ em")),
                displays("Sponsor",equalTo("Gấu Gấu Shop")),
                displays("Ad Type", containsString("Image"))
            )
        );
    }