Link Search Menu Expand Document

Basic Interactions

AndThen

One limitation of chaining tasks is, that a result of one task can only be used in the following task and not by any other following tasks. To get around this limitation you can use the AndThen task group.

Ability

none

Methods

name parameter description
.run()* func : (actor: Actor, result: ParameterType) => Promise group tasks to reuse a task result in multiple other tasks

Examples

Both Task2 and Task3 will need the result of Task1 as input parameter. To path the parameter to both Tasks you can use the AndThen task group.

Josh.attemptsTo(
    Task1.of(taskParameter),
    AndThen.run((actor: Actor, task1Result: Task1ReturnType) => {
        actor.attemptsTo(
            Task2.of(task1Result),
            Task3.of(task1Result)
        )       
    }),
    Task4.of(taskParameter))

REPEAT

Repeat will retry activities until a question result meets an expected result.
Whenever you have to implement an active polling to observe a status change use this action.

The final result of the activity list will be passed to the next activity following the Repeat activity.

Ability

none

Methods

name parameter description
.activities()* activity: Activity, …. sleep for the amount of time in ms
.until() question: Question the question to retrieve the result
.is() expected: Assertion the assertion to check the questions result
.retryFor() retries: number, duration: Duration query the question for # of ‘retries’ and wait for ‘duration’ between retries

Examples

To wait for a status change by pressing a refresh button you could do:

Josh.attemptsTo(
    Repeat.activities(
        Click.on(REFRESH_BUTTON)
    ).until(
        Text.of(STATUS_FIELD)
    ).is(
        Expected.to.equal(`SUCCESS`)
    )   
)

Check every two seconds for a status change and abort after 10 checks.

Josh.attemptsTo(
    Repeat.activities(
        Click.on(REFRESH_BUTTON)
    ).until(
        Text.of(STATUS_FIELD)
    ).is(
        Expected.to.equal(`SUCCESS`)
    ).retryFor(
        10, Duration.in.seconds(2)
    )   
)

Pass the activity result to the following task:

Josh.attemptsTo(
    Repeat.activities(
        Get.from(resource))
    .until(Result.ofLastActivity())
    .is(Expected.to.deep.equal({status: "success"}))   
)

SEE

The See interaction executes a Question and checks if the answer matches a given state. e.g.

See.if(Text.of(MYELEMENT))
    .is(Expected.toBe(`Total: $123.456`))

Possible Questions are:

See Questions.

The Matcher is a function of type (answer: <TYPE>) => boolean). You can provide you own function or choose one provided by the Expected module.

See Matcher.

Ability

none

Methods

name parameter description
.if()* question: Question extract
.is() matcher: (value: ) => boolean) verify that the Question passed in if() fulfills the function
.repeatFor() maxIterations: number, interval: number repeat until check is true for maxIterations and wait for intervall between retries
.then() activities: Activity[] if check is true execute the following activites
.otherwise() activities: Activity[] if check is false execute the following activities

Examples

See action using .then() and .otherwise().

Josh.attemptsTo(
    See.if(Text.of(myElement))
        .is(Expected.toBe(`The Text`))
        .repeatFor(5, 5000)
        .then(
            Click.on(mySaveButton))
        .otherwise(
            Click.on(myCancelButton)))

The Activity Result preceding the See action will be passed through to
the next Activity following the See action.

e.g.

actor.attemptsTo(
    PrecedingTask.doingSomething(),
    
    See.if(MyQuestion)
       .is(Expected.to.equal(something)),
    
    FollowingTask.usingResultFromPrecedingTask()
)

… or checking the result of the preceding task before continuing with further activities.

actor.attemptsTo(
    PrecedingTask.doingSomething(),
    
    See.if(Result.ofLastActivity())
       .is(Expected.to.equal(something)),
    
    FollowingTask.usingResultFromPrecedingTask()
)

SLEEP

Sleep will pause the interaction execution flow. Only the execution is paused, the generation of the interaction and task objects is not interrupted and will be finished first.

Ability

none

Methods

name parameter description
.for()* sleepTime: number sleep for the amount of time in ms
.because() sleepReason: string reason to use the sleep, will be used in activity log

In later versions Sleep will only be used in debug mode and will be automatically deactivated during test execution. So please be careful when using it.

Example

Josh.attemptsTo(
    Sleep.for(5000)
)

WAIT

Wait for a web element to change its state.
Right now you can wait until the element:

  • is / is not visible
  • is / is not enabled

To specify the desired state the UntilElementCondition condition shall be used.

Ability

none

Methods

name parameter description
.for()* element: SppElement the element it should be waited for (presence or absence)
.andCheck() condition: UntilElementCondition the state the element should have

Example

Josh.attemptsTo(
    Wait
        .for(Googles.INPUT_FIELD)
        .andCheck(UntilElement.is.visible)
)