Skip to main content

Time Execution

This custom command measures and reports execution time of some function. It allows timing the execution of some flow in a website, e.g., logging in, checking out in an e-commerce site, joining a WebRTC call. Results from this command can be used in post-run analysis.

def time_execution(name: str, command: Callable, timeout: int or None = None) -> None

name - identifying name for the command callable. If name is an empty string, then command.__name__ attribute value will be used if it is available, otherwise name will default to "anonymous". If name is provided then the maximum length for this argument is 150 characters and can only contain alphanumeric characters, underscores and hyphens.

command - a Callable object whose execution will be timed. command can be a lambda expression.

timeout - specifies the time in seconds, how long to wait for the command to execute. Timeout value must be positive. If the execution time exceeds the timeout value, then an error will be thrown. timeout parameter can be omitted and if done so, then no limit on the execution time of command is placed.

Use of the time_execution custom command will produce a log that contains timing information of the time_execution. The log message structure is shown bellow.

[LOADERO] Execution time for '${NAME}': ${DURATION}ms (start: ${START}; end: ${END}).
  • ${NAME} has the value that was supplied to time_execution name parameter.
  • ${DURATION} is the execution time in milliseconds of the command function.
  • ${START}, ${END} are Unix timestamp values in milliseconds.
def test_on_loadero(driver: TestUIDriver):
really_long_pause = 300
driver.navigate_to("https://duckduckgo.com/")

def locate_search_bar():
e(
driver, "css", "#searchbox_input"
).wait_until_visible().send_keys("QA Processes")
e(driver, "css", "[aria-label='Search']").wait_until_visible().click()
e(driver, "css", "#r1-0 > div > h2").wait_until_visible()
time.sleep(really_long_pause)

# Example of timing execution without specifying a timeout.
time_execution("locate_search_bar", locate_search_bar)
def test_on_loadero(driver: TestUIDriver):
driver.navigate_to("https://duckduckgo.com/")

def locate_search_bar():
e(
driver, "css", "#searchbox_input"
).wait_until_visible().send_keys("QA Processes")
e(driver, "css", "[aria-label='Search']").wait_until_visible().click()
e(driver, "css", "#r1-0 > div > h2").wait_until_visible()

# Example of timing execution with a timeout.
time_execution("locate_search_bar", locate_search_bar, 10)