Time Execution

Time Execution #

This custom command measures and reports execution time of some lambda expresion. 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.

timeExecution(String name, Command command, int timeout)
timeExecution(String name, Command command)

name - unique identifying name for the command function. If name is an empty string, then name will default to "anonymous".

command - function whose execution will be timed. command must be a lambda expression. command is a functional interface Command.

@FunctionalInterface
public interface Command {
    void execute();
}

timeout - specifies the time in seconds, how long to wait for the command to execute. Timeout value cannot be negative. If the execution time exceeds the timeout value, then an error will be thrown. If timeout parameter is omitted or 0, then no limit on the execution time of command is placed.

Use of the timeExecution custom command will produce a log that contains timing information of the timedCommand. 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 timeExecution name parameter.
  • ${DURATION} is the execution time in milliseconds of the command function.
  • ${START}, ${END} are Unix timestamp values in milliseconds.
public void testUIWithLoadero() {
    int reallyLongPause = 5 * 60 * 1000; // 5 minutes
    open("https://duckduckgo.com/");

    // Example of timing execution without specifying a timeout.
    timeExecution(
        "locate_search_bar_and_wait",
        () -> {
            E(byCssSelector("#search_form_input_homepage"))
                .waitFor(10)
                .untilIsVisible()
                .sendKeys("loadero");
            E(byCssSelector("#search_button_homepage"))
                .waitFor(10)
                .untilIsVisible()
                .click();
            E(byCssSelector("#r1-0 > div > h2"))
                .waitFor(10)
                .untilIsVisible();
            sleep(reallyLongPause);
        }
    );
}
public void testUIWithLoadero() {
    open("https://duckduckgo.com/");

    // Example of timing execution with a timeout.
    timeExecution(
        "locate_search_bar",
        () -> {
            E(byCssSelector("#search_form_input_homepage"))
                .waitFor(10)
                .untilIsVisible()
                .sendKeys("loadero");
            E(byCssSelector("#search_button_homepage"))
                .waitFor(10)
                .untilIsVisible()
                .click();
            E(byCssSelector("#r1-0 > div > h2"))
                .waitFor(10)
                .untilIsVisible();
        },
        10
    );
}