Serenity-js: If + Task: how to play with attemptsTo?

Created on 4 May 2018  路  5Comments  路  Source: serenity-js/serenity-js

Hi @jan-molak, hi everyone

I have a situation where if I want to fill a form. I'd like to have a boolean, and if true -> Do interaction 1 and 2, then click submit, else Do interaction 1 and submit (so 2 is conditioned). Thing is, if I use an if within my attemptsTo(), it just doesn't work as it expects performables only.

I tried something like this.
`export class FillIForm implements Task {

public static using(freeOffer: boolean, phone: string, iban: string): Fill....Form {
    return new FillForm(freeOffer, code, iban);
}

performAs(actor: PerformsTasks): PromiseLike<void> {
    let action : Tasks; //I actually tried several things here, not sure what to put that would make that work

    if (this.freeOffer) {
        action = {
             Enter.theValue(this.phone).into(plop.phone),
             Click.on(Iban.submitButton),
        }
    }
    else {
         action = {
            Enter.theValue(this.phone).into(plop.phone),
            Enter.theValue("fakeIban").into(plop.iban),
            Click.on(plop.submitButton),
        }
    }
    return actor.attemptsTo(action);
}

constructor(private freeOffer: boolean, private phone: string, private iban: string) {}`

I would rather just have an "if" within attemptsTo() but I did not believe this could work considering it expects a given type of objects, so I didn't try much on that direction.

What would you advise?

documentation question

Most helpful comment

Hi @san-ouadghiri, excellent timing! About 2 weeks ago I have added conditional activitites:

San.attemptsTo(
    Check.whether(this.freeOffer)
        .andIfSo(
            Enter.theValue(this.phone).into(plop.phone),
            Click.on(Iban.submitButton),
        )
        .otherwise(
            Enter.theValue(this.phone).into(plop.phone),
            Enter.theValue("fakeIban").into(plop.iban),
            Click.on(plop.submitButton),
        ),
)

Does this help?
Jan

All 5 comments

Hi @san-ouadghiri, excellent timing! About 2 weeks ago I have added conditional activitites:

San.attemptsTo(
    Check.whether(this.freeOffer)
        .andIfSo(
            Enter.theValue(this.phone).into(plop.phone),
            Click.on(Iban.submitButton),
        )
        .otherwise(
            Enter.theValue(this.phone).into(plop.phone),
            Enter.theValue("fakeIban").into(plop.iban),
            Click.on(plop.submitButton),
        ),
)

Does this help?
Jan

That EXACTLY what I need \o/ ! Super thank you !

@jan-molak Actually, the check is not available (it seems) on 1.10.12, the last release. I guess that as the release was done 25d ago, and the change 13d ago. Do you plan on releasing soon?

Hey @san-ouadghiri! Check is part of @serenity-js/core, which serenity-js depends on.
I've just bumped that dependency version so you should get the latest core when you npm install the latest serenity-js.

I'm official its first user \o/ !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vijay-kumar-singh picture vijay-kumar-singh  路  3Comments

jan-molak picture jan-molak  路  4Comments

y3rsh picture y3rsh  路  4Comments

rajeshwarp picture rajeshwarp  路  5Comments

rakeshnambiar picture rakeshnambiar  路  5Comments