What are Condition Factories?

Conditions are used to test properties. Locator-specific properties can be tested through special conditions that are surfaced via condition factory methods. Surfacing conditions this way makes building assertions in the IDE easy. For instance, if we are testing properties of a button, the IDE’s content assist proposes the following conditions:

Continuing with this example, if the test we are writing is of enablement, our resulting assertion could look like this:

ui.assertThat(new ButtonLocator("OK").isEnabled());

Implementing a Condition Factory

Implementing a condition factory is as simple as adding an instance method that returns an ICondition to a locator. For example, the ButtonLocator's enablement condition factory might be written like this:

public ICondition isEnabled() {
	return new IsEnabledCondition(this, true);

Here the IsEnabledCondition is responsible for testing whether the locator’s target widget is in fact enabled (in simple cases this might just be done in line).