Skip to content

Wait

The Wait modules lets the flow wait for various events.

Wait for seconds

Wait the given amount of seconds.

Parameters

  • timeout the number of seconds to wait

Example

javascript
Wait.forSeconds(2);

Wait for milliseconds

Wait the given amount of milliseconds.

Parameters

  • timeout the number of milliseconds to wait

Example

javascript
Wait.forMilliseconds(200); // Wait for 0.2 seconds

Wait for field

Wait for the given field to appear - will return when field appear or throw an exception when the given amount of seconds has elapsed.

Parameters

  • field the field to wait for e.g. Fields["myfield"]
  • timeout the max amount of seconds to wait for the field to appear
  • options additional optional arguments
    • pollDelayInMs int, how many ms between checks that the field is present or not - default is 200

Example

javascript
Wait.forField(Fields["myfield"], 10);

// Poll every 1s
Wait.forField(Fields["myField"], 10, { pollDelayInMs: 1000 });

Wait for field to disappear

Wait for the given field to disappear - will return when field disappears or throw an exception when the given amount of seconds has elapsed.

Parameters

  • field the field to wait for e.g. Fields["myfield"]
  • timeout the max amount of seconds to wait for the field to disappear
javascript
Wait.forFieldToDisappear(Fields["myfield"], 10);

Wait for window

Wait for the given window to appear - will return when a matching window appears or throw an exception when the given amount of seconds has elapsed. There is also a forWindowToDisappear variant.

Parameters

  • title the title of the window to wait for
  • timeout the max amount of seconds to wait for the field to appear

Example

javascript
// Wait for a window with Notepad in its title to appear, max 10s
Wait.forWindow("Notepad", 10);
// Wait for Notepad to disappear again
Wait.forWindowToDisappear("Notepad", 10);

Wait for lock

Wait.forLock(...) allows for exclusive access to a shared resource among concurrently running flows (from separate sessions) or from other asynchronous tasks (e.g. when using the Task module).

Parameters

  • lockName The name of the lock
  • callback The function to call with exclusivity under the named lock
  • opts Options (default: { timeout: 3000 })

Return value

true if the lock was obtained within the timeout. false otherwise

Example

To access a shared resource with exclusivity:

javascript
function accessSharedResourceFn() {
  // Access the shared resource here...
}

if (!Wait.forLock('resourceLock', accessSharedResourceFn, { timeout: 5000 })) {
  throw Error('Failed to access the shared resource');
}

Wait for click

Wait.forClick(...) and Wait.forRightClick(...) can be used to wait for a user to click a given field.

Parameters

  • field an instance of a Field to wait for click on
  • options an object containing optional arguments;
    • throws bool, if true then an exception is thrown if the field was not clicked before timout has elapsed - default is true
    • timeout int, for how many ms should we wait before giving up - default is 60000

Return value

If option.throw is false then true is returned if the field was clicked, false otherwise.

Example

js
// Simple wait - will throw error if "OK" is not clicked within 60s
Wait.forClick(Fields["OK"]);

// Do not throw an error and wait only 5s
if (!Wait.forRightClick(Fields["Cancel"], { "throws": false, "timeout": 5000 })) {
  // No click
} else {
  // "Cancel" was clicked
}

Wait for predicate

Wait.for(...) can be used to wait for an arbitrary condition to be met. Use this for any condition that isn’t directly supported by other methods in the Wait api.

Parameters

  • predicate a function returning a truthy value when the awaited condition is met and falsy values otherwise.
  • options an optional object containing arguments;
    • throws bool, if true then an exception is thrown if the predicate has not returned a truthy value before timout has elapsed - default is true
    • timeout the number of ms we wait before giving up - default is 10000
    • interval the number of ms to pause between each invocation of the predicate. Default is 200

Return value

The first truthy value returned by the predicate is returned or null if no such value was produced. If the throw option is true (default) and no truthy value is produced by the predicate, an exception is thrown in stead.

Example

js
function predicate() {
  return new Field('**/combobox').read();
}
// Wait 3 seconds for field to get a value - no timeout exception
var maybeValue = Wait.for(predicate, { throws: false, timeout: 3000 });
if (!maybeValue) {
  // Handle timeout
}
// Wait 10 seconds with exception on timeout
try {
  Wait.for(predicate);
} catch (e) {
  // Handle the timeout
}