testla-project / testla-screenplay-playwright-js

Playwright implementation of the testla screenplay core package
MIT License
28 stars 5 forks source link

Retry capabilities for blocks of actions/tasks/questions #39

Open kbrueckner opened 1 year ago

kbrueckner commented 1 year ago

Imagine the following scenario: A user triggers some interaction in a UI. In the background some data is put on a data stream is processed by a backend service and ends up updating an existing entry in a database. For that scenario a test could look like follow:

John.attemptsTo(
    Type.in(INPUT_FIELD, ‘some change’),
    Click.on(SUBMIT_BUTTON),
);

Const entity = await DBAdmin.attemptsTo(
    Query.dataset(123),
);
DBAdmin.asks(
    Entity.hasAttribute(entity, { attr: ‘some change’ });
);

The challenge could be, that the whole flow takes some time so that the changes are not immediately found in the DB but require some time. A Retry routine would help to overcome that. An idea how that could look like is:

John.attemptsTo(
    Type.in(INPUT_FIELD, ‘some change’),
    Click.on(SUBMIT_BUTTON),
);

DBAdmin.retries(
    DBAdmin.attemptsTo(
        Query.dataset(123),
    ),
    DBAdmin.asks(
        Entity.hasAttribute(entity, { attr: ‘some change’ });
    ),
).withInterval(30000).withMaxRetries(5);

In case the actions inside a retry are split among different users

DBAdmin.and.DBAdmin2.retry(
    DBAdmin.attemptsTo(
        Query.dataset(123),
    ),
    DBAdmin2.asks(
        Entity.hasAttribute(entity, { attr: ‘some change’ });
    ),
).withInterval(30000).withMaxRetries(5);
JEnglandOhalo commented 10 months ago

https://github.com/awaitility/awaitility/wiki/Usage is a quite nice library in Java for synchronizing operations in tests. I quite like its fluent API

I wonder if it could be combined with Questions?

DBAdmin
   .waits()
   .atMost(5, SECONDS)
  .until(Entity.hasAttribute(entity, { attr: ‘some change’ }))
kbrueckner commented 8 months ago

This actually should be implemented in the screenplay core package