Jacobvu84 / screenplay-cucumber-webdriver

The demo shows the integration of Serenity BDD, Screenplay and Cucumber JVM.
1 stars 1 forks source link

Retreive the text value of a field from the target as a Question object #2

Open Jacobvu84 opened 5 years ago

Jacobvu84 commented 5 years ago
public class TheOutboundJourneySummary {
    public static Question<String> origin() {
        return TheTarget.textOf(OutboundJourneySummary.ORIGIN);
    }

    public static Question<String> destination() {
        return TheTarget.textOf(OutboundJourneySummary.DESTINATION);
    }
}

If you are using Java 8, you can also use a Lambda expression

public class TheOutboundJourneySummary {
    public static Question<String> origin() {
        return actor -> Text.of(OutboundJourneySummary.ORIGIN).viewedBy(actor).asString();
    }
}
Jacobvu84 commented 5 years ago

package com.learnauto.ticketbooking.question;

import com.learnauto.ticketbooking.ui.OutboundJourneySummary;

import net.serenitybdd.screenplay.Actor; import net.serenitybdd.screenplay.Question; import net.serenitybdd.screenplay.questions.Text;

public class TheOutboundJourneySummary implements Question{

@Override
public String answeredBy(Actor actor) {
    return Text.of(OutboundJourneySummary.ORIGIN).viewedBy(actor).asString();
}

public static Question<String> origin() {
     return new TheOutboundJourneySummary();
}

public static Question<String> destination() {
    return actor -> Text.of(OutboundJourneySummary.DESTINATION).viewedBy(actor).asString();
}

}