Wait function

The problem of non-constant waiting time

Some applications are dependent on external elements to be able to continue their processing: waiting for a response from a server, waiting for the results of a calculation, waiting for the full display of a page that may depend on the implementations of the browsers, etc.

This poses a problem when performing the functional tests: how to correctly manage this waiting without causing a situation of failure of the tests and without spending too much time waiting?

The solution is not to wait a given time to continue the test, for obvious reasons: you do not know how long you'll have to wait. In addition you will completely pollute your database of automated tests by sprinkling here and there waiting times sometimes useless, which will considerably slow down the execution of all your tests.

That's why you will not find a "wait" function in Agilitest ...

The Agilitest solution: make a "check on occurrence"

What is it about ?

An Occurrence Check is an Agilitest action that verifies that there is one or more items present or missing in the page or software being tested.

This solution will tell Agilitest that you want to control the number of occurrences of an object in your application.

The action checking the occurrences of an object in Agilitest

It is applicable in the following situations:

  • We want to wait until the page has finished loading to continue processing. In this case, we can perform an occurence check on an item that will display at the bottom of the page at the end of the upload.
  • We want to wait a modification of the page which will remove elements already printed. In this case we perform a check on occurrence equal to 0 (absence check) on an item which must disappear before continuing the test.

In both cases and as long as the conditions of success of the check on occurrence are not met, Agilitest will start to consider itself "in a situation of potential failure" of the test, and will therefore multiply the controls to avoid generating a false negative.

At the end of its control, Agilitest will produce a test failure situation, unless, in the meantime, the conditions for successful check are met, and therefore the items we were expecting are either present or have been removed.

The option "Max trials" in Agilitest

The trick is to tell Agilitest how many tests it will have to perform to wait for the conditions of the check. This is done by selecting a number of max tries that he will have to perform before considering "to be in failure" on this action.

Each action has the ability to wait and retry multiple times. This greatly contributes to the robustness of the tests when you know that your server may be in a situation of not delivering the desired page immediately.

The maximum number of trials is limited to 50, but the waiting time between each test follows an exponential curve: this allows to quickly check the conditions of success when they are present, but also to wait "a certain time '' for a long treatment to be done.

Using this solution we could even ask to wait until the end of a trailer on an Android application broadcast video ...

How to still wait for a fixed period?

There is always a solution with Agilitest, and in this case it involves using a piece of Java code, here's how:

  • In the Agilitest Explorer, select the java directory in src / main at the same level as your .ats files
  • Right-click and select: Create java script.
  • The editor opens a popup to request the name of the script, enter wait and click OK.
  • The editor opens a java code editing window, paste the following code in the function testMain ():

try {
final int ms = Integer.parseInt(prm(0, "1000"));
} catch (Exception e) {}

  • Drag-drop the "" script from the Agilitest Explorer to where you want to call it in your test.

TIP: If you want to be able to specify the wait time directly from your ATS script in Agilitest, you can declare a parameter passed by value to the script and then use the following code:

try {
final int ms = getParameter(0).toInt();
} catch (Exception e) {}

Still require support?
Contact support