STMTimer for measuring transactions


The STMTimer monitors the time taken for specific actions, such as loading a page or completing a login, and records any performance or availability issues. It allows you to start a timer before an action and stop it after the action is complete to capture the total response time and any issues.

For example, you can write a script that measures how long it takes to load a login page and logs an error if the page title or form is missing.

The detailed explanations of the available functions, including their purposes, syntax, parameters, descriptions, and usage examples, can be found in the sections below.

start(timer_name)

Syntax

start(timer_name)

Parameter

ParameterDescription
timer_name (string)A unique name assigned to the timer instance.

Description

The start() function initiates the time tracking for the specified timer that measures the duration of all actions performed until the timer is stopped. If another timer with the same name is active, a timer error is raised to prevent duplicate or overlapping timers. 

Example

customTimer.start('ENGLISH')

In this example, customTimer.start('ENGLISH') function creates a timer named ENGLISH and begins measuring the time for the English Wikipedia page transaction, which includes navigating to the page and validating its content and sections. The timer continues to run until it is explicitly stopped with stop() function, allowing you to capture the total duration of the action.


stop(timer_name)

Syntax

stop(timer_name)

Parameters

ParameterDescription
timer_name (string)The name of the timer.

Description

The stop() function terminates the specified timer and calculates the total duration of all actions taken since the timer started. The output, along with any related accuracy or availability errors, are displayed in JSON format. If there is no active timer with the specified name, a timer error will be raised. Use the stop(timer_name) function to stop a timer after completing an action.

Example

customTimer.stop('ENGLISH')

In this example, customTimer.stop('ENGLISH') function stops the timer named ENGLISH, which was started before navigating to the English Wikipedia page. Stopping the timer marks the end of the English Wikipedia page transaction, which includes page navigation and content validation steps. The total duration measured by the timer is then finalized and saved.


set_accuracy_error(timer_name, reason)

Syntax

set_accuracy_error(timer_name, reason)

Parameters

ParameterDescription
timer_name (string)The name of the timer to associate with the error.
reason (string or None)A description of the accuracy error.

Description

The set_accuracy_error() function records an accuracy error message for the given timer. The accuracy errors indicate that the page or action did not match the expected result, such as incorrect content or a missing element. If a timer does not exist, it automatically gets created before logging the error. 

Example

driver.set_accuracy_error("Homepage: Expected heading 'The Free Encyclopedia' found")

In this example, the function driver.set_accuracy_error("...") records an accuracy error with the current page during its validation. The error arises because the heading on the homepage does not match the expected text: "The Free Encyclopedia".


set_availability_error(timer_name, reason)

Syntax

set_availability_error(timer_name, reason)

Parameters

ParameterDescription
timer_name (string)The name of the timer to associate with the error.
reason (string or None)A description of the availability error.

Description

The set_availability_error() function records an availability error message for the given timer. The availability errors indicate that the action or page was not accessible due to issues like timeouts, failed responses, or network problems. If a timer does not already exist, it automatically gets created before logging the error. 

Example

customTimer.set_availability_error("ENGLISH", "English Wikipedia: Editor count element missing or page failed to load")

In this example, customTimer.set_availability_error("ENGLISH", "...") function records an availability error for the ENGLISH timer during the English Wikipedia page transaction. This error signifies that a required page element is either missing or the page fails to load.

Information
Important

The transaction-level set_availability_error(timer_name, reason) and set_accuracy_error(timer_name, reason) functions are different from the driver-level set_availability_error(reason="") and set_accuracy_error(reason="") functions. The transaction-level methods require both a timer name and a reason, while the driver-level methods require only a reason.

 

 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*

BMC PATROL for Synthetic Monitoring 25.4