Wait actions

There are five types of waits that you can use within a script:

  • Wait for Page Complete

  • Wait for Network

  • Wait for Time

  • Wait for Validation

  • Wait for Event

Each of these waits has a specific purpose and should be used for specific situations.

Wait for Page Complete

Wait for Page Complete tells the agent to wait until a page load is considered “complete”. This wait consists of a number of network waits as well as waits for specific document or browser events to occur. It is designed to properly handle the different events that can take place during a page load.

The following diagram shows the wait for page workflow. In this workflow, only two components can be tweaked: the Page Complete delay and the pending read time used for the Comet detection.

image

This wait allows the “Page Complete” phase to take place and then allows a minimum of 1500 ms for any timeout events to occur after onload.

Each browser agent detects the “Page Complete” status differently. The IE agent waits for the DocumentComplete event and also checks that the Internet Explorer browser's ReadyState property is set to READYSTATE_COMPLETE. The Firefox, Chrome, and Mobile agents only wait for the DocumentComplete event.

In the Internet Explorer browser, an option is available to modify the way the browser performs the Page Complete detection illustrated in the preceding figure. This method may be more reliable in some use cases. To turn this option on, the Debug mode must be enabled in the Recorder:

Close any open instances of the Recorder.

Locate the desktop shortcut for the Recorder, right-click the shortcut, and select Properties from the dropdown menu.

The Shortcut tab appears.

In the Target field, go to the very end of the existing target string (outside the double quotes) and add the following flag:

 -debug

Click Apply and then click OK.

Open the Recorder and verify that a Debug menu now appears in the menu bar.

The option to enable the wait option appears if you select the Script icon in the timeline, and then select the Playback tab in the script details pane. A check box labeled Enable onload based wait for page complete appears.

Wait for Network

Wait for Network waits between a minimum of 200 ms and the wait timeout value (60000 ms by default) for any pending network requests to complete, as depicted in the following figure.

image

If there are no pending requests at 200 ms, the wait considers itself complete and the script moves to the next action.

Use a Wait for Network when the agent needs to wait for objects to load, but a page navigation does not take place (for example, XHR calls from AJAX events).

Warning

Do not use this type of wait as a substitute for a Wait for Page Complete, because it does not check for DOM or browser ready states and it cannot guarantee that all the correct events have taken place.

The following diagrams show different Wait for Network scenarios.

The following figure depicts a case where Wait for Network completes at 200 ms because there are no pending objects at the 200 ms mark. Any requests made after this checkpoint and before the next wait action will still be measured; however, the agents will not block the next action from executing while these objects load.

image

In the following figure, the wait terminates after the third request completes, because the Wait for Network will stop if there are requests in progress when a given request completes. The fourth request will be measured, but the script will not be blocked. The script will continue to the next scripted action as this object loads.

image

In the following figure, the wait timeout was exceeded.

image

Wait for Time

Wait for Time enables you to specify how long the agent should wait. Use this wait only if there is a specific situation in which the script needs to wait before moving on to the next action; for example, you may require that a transaction wait for a few seconds to ensure that certain back-end processes take place before it can proceed.

A common use for this wait is in a registration situation, where the script needs to log into a newly created account. The script may need to wait a few seconds after submitting the information to create the account before it can actually access it.

Wait for Validation

Wait for Validation blocks the agent until it can successfully find the DOM element specified. This wait is ideal for situations where the application may present a “loading…” page before the page the script needs to act on. You can add a wait for validation against an element found on the page after the “loading…” message.

In a Wait for Validation, the agent continuously loops through the validation against the current page DOM (this is most likely changing during the process) until it locates the element specified or until it times out. The default wait timeout for Wait for Validation is 30 seconds. This default can be overridden in the Wait Timeout field in the Recorder, if the element regularly takes more than 30 seconds to load.

Wait for Validate only accepts an element match for the validation because the validation is taking place on the DOM level. The match should target a specific element on the page, not the entire HTML element. Matching against the entire HTML element may introduce errors, specifically on the Firefox agent.

To ensure that all objects load after the agent finds the element, you should always follow a Wait for Validation with a Wait for Page Complete or a Wait for Network, depending on what type of network activity is taking place.

Wait for Event

Wait for Event provides a way to tell the agent to wait until a specific client-side event has happened, as opposed to waiting for a full page to load or for all network activity to subside. This option makes it possible to measure the “perceived” load time of a given page. The wait provides these possible events to select from:

DOMReady

Tells the agent to wait until the DOM is ready, although the page may still be loading additional content. Each agent determines DOMReady differently. The IE agent waits until the document's readyState is changed to interactive. The Firefox agent waits until the browser's DOMContentLoaded event is fired.

load

Tells the agent to wait until the page's onload event has completed. The IE agent determines the load time by waiting until the target window's final DocumentComplete event is fired. The Firefox agent waits for the Firefox browser's load event to fire.

More information on the browser-specific events can be found at these websites:

Adjusting timeout, deadline, and delay values

All waits are bound by the various configuration settings defined for the browser agents. In some cases, these values may require some fine-tuning for the script to properly wait for the expected content. It is important to understand the different settings and their default values, and to know when it is appropriate to modify them.

Wait timeout

All Wait actions, with the exception of Wait for Time, are capped by the wait timeout value. In the action configuration for the different wait types, this is the Maximum time to wait. If the agent is in a wait state that exceeds that value, it throws a wait timeout error, which is flagged as a Timeout Exceeded error in Dynatrace Synthetic data.

Default value – none

Maximum value – none

Page Complete Delay

The Page Complete Delay is applied within a Wait for Page Complete after the agent has confirmed that the browser's readyState is Complete. This wait provides a buffer in case there are any additional requests that need to go through.

Default value – none

Maximum value – none

Pending Read Wait

The Pending Read Wait is applied within a Wait for Page Complete to allow time for additional asynchronous events after the page is loaded.

Default value – 3 seconds

Maximum value – 3 seconds

Connection Timeout

The Connection Timeout is a network-level timeout reported by the agent when it fails to connect to a host server within the specified amount of time. The default value corresponds with the amount of time a real browser would take to report a connection timeout error.

Default value – 25 seconds

Maximum value – 25 seconds

Read Timeout

The Read Timeout is the value associated with the Socket Receive Timeout error reported in the Dynatrace Portal. This error occurs when the agent fails to receive any data from the host server within a specified window of time. The length of that window is defined by the Read Timeout value.

Default value – 40 seconds

Maximum value – 120 seconds

Soft Deadline

The Soft Deadline applies to the cumulative network time recorded for a given page, or for the entire transaction level. Network time includes all the response times that Dynatrace Synthetic reports, with the exception of Client Time.

Soft timeouts are reported as Timeout Exceeded Errors in the Dynatrace Portal.

Default value – 60 seconds

Maximum value:

  • Script and step – 240 seconds

  • Action – 220 seconds

Hard Deadline

The Hard Deadline applies to the same things as the Soft Deadline. The only difference is that if the Hard Deadline threshold is met, the data is automatically cut from the database. Usually this deadline is reached when the agent is stalled on a particularly large object on the page.

Default value – 90 seconds

Maximum value:

  • Script and step – 290 seconds

  • Action – 220 seconds