Wait
Instructs the Actor to wait before proceeding either for a set @serenity-js/core~Duration or until a given Expectation is met.
Useful when a test scenario can't take advantage of automatic synchronisation between Protractor and Angular (see UseAngular), or when the application under test is animation-heavy.
Extends:
Examples:
<!--
After about 1 second, the text will change from 'Loading...' to 'Ready!'
-->
<h1 id="status">Loading...</h1>
<script>
(function () {
setTimeout(function () {
document.getElementById('status').textContent = 'Ready!'
}, 1000);
})();
</script>
import { Target } from '@serenity-js/protractor';
import { by } from 'protractor';
class App {
static status = Target.the('status widget')
.located(by.id('status'));
}
import { actorCalled, Duration } from '@serenity-js/core';
import { BrowseTheWeb, Wait } from '@serenity-js/protractor';
import { Ensure, equals } from '@serenity-js/assertions';
import { protractor } from 'protractor';
actorCalled('Aurora')
.whoCan(BrowseTheWeb.using(protractor.browser))
.attemptsTo(
Wait.for(Duration.ofSeconds(1.5)),
Ensure.that(App.status, equals('Ready!')),
);
// Please note that while the above implementation works,
// this approach is inefficient because at best
// the actor might wait too long and at worst the test
// might become "flaky" if any external interference
// (like network glitches, animations taking a bit too long etc.)
// makes the actor wait not long enough.
import { actorCalled } from '@serenity-js/core';
import { BrowseTheWeb, Wait, Text } from '@serenity-js/protractor';
import { equals } from '@serenity-js/assertions';
import { protractor } from 'protractor';
actorCalled('Aurora')
.whoCan(BrowseTheWeb.using(protractor.browser))
.attemptsTo(
Wait.until(Text.of(App.status), equals('Ready!')),
// app is ready, proceed with the scenario
);
// Wait.until makes the Actor keep asking a Question,
// in this case Text.of(App.status), until the answer meets
// the expectation, or a timeout expires (default: 5s).
//
// Please note that both Ensure and Wait can be used with
// the same expectations, like `equals`.
import { actorCalled, Duration } from '@serenity-js/core';
import { BrowseTheWeb, Wait, Text } from '@serenity-js/protractor';
import { equals } from '@serenity-js/assertions';
import { protractor } from 'protractor';
actorCalled('Aurora')
.whoCan(BrowseTheWeb.using(protractor.browser))
.attemptsTo(
Wait.upTo(Duration.ofSeconds(3))
.until(Text.of(App.status), equals('Ready!')),
// app is ready, proceed with the scenario
);
Tests:
Static Member Summary
Static Public Members | ||
public static |
Default timeout of 5 seconds used with Wait.until. |
Static Method Summary
Static Public Methods | ||
public static |
for(duration: Answerable<Duration>): Interaction Instantiates a version of this Interaction configured to wait for a set duration. |
|
public static |
until(actual: Answerable<Actual>, expectation: Expectation<any, Actual>): Interaction Instantiates a version of this Interaction
configured to wait until the answer to the question ( |
|
public static |
upTo(duration: Duration): WaitBuilder Instantiates a version of this Interaction
configured to wait until the answer to the question ( |
Static Public Members
Static Public Methods
public static for(duration: Answerable<Duration>): Interaction source
Instantiates a version of this Interaction configured to wait for a set duration.
public static until(actual: Answerable<Actual>, expectation: Expectation<any, Actual>): Interaction source
Instantiates a version of this Interaction
configured to wait until the answer to the question (actual
) meets the expectation
,
or a Wait.Default_Timeout expires.
Params:
Name | Type | Attribute | Description |
actual | Answerable<Actual> | A Question that the Actor will keep asking until the answer meets the Expectation provided |
|
expectation | Expectation<any, Actual> | An Expectation to be met before proceeding |
public static upTo(duration: Duration): WaitBuilder source
Instantiates a version of this Interaction
configured to wait until the answer to the question (actual
) meets the expectation
,
or a custom timeout expires.
Params:
Name | Type | Attribute | Description |
duration | Duration | Custom timeout to override Wait.Default_Timeout |