Adam Papp
Adam Papp

Reputation: 11

In TestFX version 4, how can I wait until an element of the GUI becomes visible?

What Matcher should I use? visible() seems no longer available and unfortunately I could not find an alternative in the org.hamcrest library.

Thanks in advance!

Upvotes: 1

Views: 923

Answers (1)

Dmytro Maslenko
Dmytro Maslenko

Reputation: 2297

You may use Awaitility utility.

This is an example of a utility method where it waits by default up to 10 seconds starting after 10 milliseconds:

public <T extends Node> T lookupById(final String controlId) {
    Awaitility
            .await()
            .pollDelay(10, TimeUnit.MILLISECONDS)
            .until(() -> robot.lookup(controlId).query() != null);

    return robot.lookup(controlId).query();
}

You may implement any condition of waiting, for example, checking of additional visibility property, etc.

The result of negative scenario:

org.awaitility.core.ConditionTimeoutException: Condition with lambda expression in com.MyClass was not fulfilled within 10 seconds.

Upvotes: 1

Related Questions