Wait

Use the wait object to wait for a particular session or screen state. For example, you can wait until the cursor is found at a particular location or text is present at a certain location before continuing with the macro execution.

Wait functions are often used in conjunction with asynchronous functions such as connect() and sendKeys().

NOTE:All functions take timeouts as an optional parameter and have a default time out value of 10 seconds (10000ms).

Important: All wait functions require the ‘yield’ keyword in front of them. This allows the macro to block execution until the conditions of the wait function are met.

[parameter] denotes an optional parameter.

Table 5-36 Waiting for the host

METHODS

setDefaultTimeout(timeout)

Sets the default timeout value for all functions.

Parameters

{Number} default timeout to use for all wait functions in milliseconds.

Returns

None

Throws

{RangeError} If the specified timeout is less than zero.

forConnect([timeout])

Waits for a connect request to complete.

Parameters

{Number} in milliseconds.

Returns

{Promise} Fulfilled if the session is already connected or when connection occurs. Rejected if the wait times out.

forDisconnect([timeout])

Waits for a disconnect request to complete.

Parameters

{Number} timeout in milliseconds.

Returns

{Promise}Fulfilled if the session is already disconnected or when it finally disconnects. Rejected if the wait times out.

forFixedTime([timeout])

Waits unconditionally for fixed time. Time is in milliseconds (ms)

Parameters

{Number} timeout in milliseconds.

Returns

{Promise}Fulfilled after time elapses

forCursor(position, [timeout])

Waits for the cursor to arrive at the specified position.

Parameters

{Position} The position specifying the row and column,

{Number} timeout in milliseconds

Returns

{Promise}Fulfilled if the cursor is already located or when it is finally located. Rejected if the wait times out.

forText(text, position, [timeout])

Wait for text located at a specific position on the screen

Parameters

{String} text to expect

{Position} position specifying the row and column

{Number}timeout in milliseconds

Returns

{Promise} Fulfilled if the text is already at the specified position or whenever it is located. Rejected if the wait times out.

Throws

{rangeError} if the position is not valid.

forHostPrompt(text, column,[timeout])

Waits for a command prompt located at a particular column on the screen.

Parameters

{String} text prompt to expect

{Number} column where cursor is expected

{Number} timeout in milliseconds.

Returns

{Promise} Fulfilled if the conditions are already met or when the conditions are finally met. Rejected if the wait times out.

Throws

{rangeError} if the column is out of range.