Inizia ora la tua demo e risparmia sui primi 12 mesi!

Blog

How to Successfully Handle the Random Loading Time

Pubblicato da Il 19 Maggio 2020 in Blog, Tips

A very common issue with automated tests is how to handle the random loading time of the UI and its objects. 

Indeed loading time is often not constant, so the testers have to try to prevent possible delays during the execution of the automated tests to let them run properly. 

Of course, the easiest solution could be using an oversized sleep time with the hope it will be enough to let the test not fail.  

By, in this approach, you are creating complications that will make the execution of the tests slow and/or unstable, even though this time, the functional behavior you are introducing could be just a workaround and not something you want to consider. 

From our point of view, the more effective and, at the same time, the easiest way to handle this issue is to wait for the objects just until they are loaded. 

In the following example, we have a very dummy web application under test with 3 enabled buttons and a disabled one.

Clicking the button with the label “Button”, the message “You pressed Button” should appear.

We will test this behavior in the test script example, so we expect to read the message: “You pressed Button”.

We will also check if the disabled button is actually disabled.


Buttons


A very easy automated test script written in Java by using the Maveryx APIs and JUnit follows.


/**
* This Test Case provides an example of managing buttons using the relevant Maveryx APIs.
* @throws Exception
*/
@Test
public void click() throws Exception {
    //the buttons to test
    GuiButton button = new GuiButton(“Button“);
    GuiButton buttonDisabled = new GuiButton(“Disabled Button“);

    assertTrue(button.isEnabled()); //check if the button is enabled
    assertTrue(!buttonDisabled.isEnabled()); //check if the button is not enabled

    button.click(); //click the button

    GuiLabel message = new GuiLabel(“message“);
    message.waitForObject(3, 2); //check three times with 2 seconds time-steps if the message is visible
    assertEquals(“You pressed Button!”, message.getText()); //check expected message has been displayed
}


Alternatively, we can write the test through a codeless approach based on keywords. 

In the following xls file, we wrote the same automated test script using the Maveryx keywords. Also, we decided to generalize the runtime object recognition by using the generic HTML_OBJECT nature instead of the LABEL one used in the previous Java example (GuiLabel)


How to Handle the Random Loading Time

In both executions, the Maveryx Test Automation Framework tried to locate the “You pressed Button” object at runtime, checking if it was visible for a maximum of three tries and waiting 2 seconds between the checks. 

In our case, both the executions succeeded at the second check, just after 2 seconds. 

With this function, it is possible to set a time limit and locate the object right after it is loaded (with a good time approximation). It just depends on the chosen time step.