Jacobvu84 / selenium-vietnam-training-course

Questions Tracking
7 stars 5 forks source link

How to IF...ELSE with serenity action #59

Open Jacobvu84 opened 5 years ago

Jacobvu84 commented 5 years ago
actor.attemptsTo(
     ....
     Check.whether(Platform.isAndroid())
                    .andIfSo(
                                    Login.android(), Do.task())
                    .otherwise(
                                    Login.iOS(), Do.task()),
     ....
);
Jacobvu84 commented 5 years ago
package com.asksqa.tasks;

import static net.serenitybdd.screenplay.Tasks.instrumented;

import com.asksqa.model.UserAccount;
import com.asksqa.questions.Platform;

import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.conditions.Check;
import net.thucydides.core.annotations.Step;

public class Login implements Task {

    UserAccount account;
    String osType;

    {
        this.osType = Platform.getOSType();
    }

    public Login(UserAccount account) {
        this.account = account;
    }

    @Override
    @Step("{0} signs in with #osType device")
    public <T extends Actor> void performAs(T actor) {

        actor.attemptsTo(
            Check.whether(Platform.isAndroid())
                .andIfSo(SignIn.android(account))
                .otherwise(SignIn.iOS(account)));

    }

    public static Login credentials(UserAccount account) {
        return instrumented(Login.class, account);
    }

}