JBoss Community Archive (Read Only)

Graphene 1

Waiting

In almost every interaction with tested application, there is a need for waiting to completion of that action i.e. to wait for reaction triggered by user interaction.

Each of this reaction should provide some visible or hidden change to the DOM tree. We can then find conditions, which describes this change.

We can say, that we are waiting for satisfying the conditions after our interaction.

For example, we have application implementing the incremental counter, which must be started first, described by this locators:

JQueryLocator buttonStart = jq("#start");
JQueryLocator buttonIncrement = jq(":button");
IdLocator textCount = id("#count");

First, we need to start the counter, let's click on the button:

selenium.click(buttonStart);

To ensure that we will not continue with another interaction before the latter was completed, we have to wait for satisfying the condition "counter is prepared for incrementation":

Wait.waitSelenium.timeout(60000).interval(1500).until(elementPresent.locator(textCount));

The declaration above says that we test in interval 1,5 sec. and the condition is testing that element with locator textCount is present. Note that first test for condition will start in delay of one interval (1,5 sec). If the condition is evaluated as unsatisfied after 60 seconds, the code above will raise the timeout exception. 

This unreadable section can be easily modified to be pretty more readable, using capabilities of Graphene Utility, and we will continue to present this method of improving readability:

waitModel.until(elementPresent.locator(textCount));

So we have satisfied that counter was started, and it should be definitely preset to value zero:

assertEquals("0", selenium.getText(textCount));

Let's try the functionality of button Increment:

selenium.click(buttonIncrement);

After this step we will need define another condition, which will be satisfied after increasing the value of counter to "1" - for this purpose, we will create own condition object, reusing the predefined condition of type TextEquals:

TextEquals countEquals = textEquals.locator(textCount);

Let's use this condition in action:

waitAjax.until(countEquals.text("1"));

Note: waitGui is similar to waitModel, and was created from Wait.waitAjax or may be also created by call new AjaxWaiting().

It's obvious, that with waiting for satisfying each condition, we also assert that the condition has to become true to successfully continue in current test. There is no need for additional assertion on value.

Sometimes however we need to wait for value that is unknown in time of interaction. There comes Retrievers into play.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-10 12:13:26 UTC, last content change 2012-03-19 13:26:32 UTC.