-
Notifications
You must be signed in to change notification settings - Fork 44
RedDeer basics
Matchers are widely used in RedDeer to perform selection based on given criteria like comparing if given widget fits required class or if test corresponds with given regex expression. RedDeer is currently using hamcrest matchers which can be changed in the future.
Matchers are internally used but you can use them also externally and mix them and also create your own customized matchers and that can be used in many lookup constructors.
For example you can use this constructor with available machers or your own implementation
public DefaultText(Matcher... matchers){
for example if you want to find DefaultText with text that contains version in standard (major,minor,build) format inside you can perform something like this:
Matcher regexMatcher = new RegexMatcher(".*\\d+\\.\\d+\\.\\d+.*")
Text t = new DefaultText(new WithTextMatcher(regexMatcher));
WithTextMatcher extracts text from widget and compares it to given RegexMatcher.
You can use multiple matcher classes provided by RedDeer like
- RegexMatcher
- VersionMatcher
- WithTextMatcher
- WithStyleMatcher
- WithTooltipTextMatcher
- WithLabelMatcher
- and others
Wait conditions are used in cases when tests have to wait for state or condition. Test continues only when specific wait condition pass and therefore developer can be sure that the test environment is in proper state.
RedDeer implements two basic waits to perform conditional waiting:
-
WaitUntil - waiting until a specific condition is met, then testing ends
-
WaitWhile - wait while a specific condition is met, then testing ends
If we want to wait for all jobs to finish, we can use
new WaitWhile(new JobIsRunning())
or the opposite - wait until at least one job is running
new WaitUntil(new JobIsRunning())
Every wait has a timeout which can be set by TimePeriod. If timeout is not specified TimePeriod.DEFAULT is used as a default (10 seconds). Once the wait condition timeout, a new WaitTimeoutExpiredException
In case we have a long running jobs, we can specify TimePeriod.LONG timeout (60s)
new WaitWhile(new JobIsRunning(), TimePeriod.LONG)
To pause test for exact time period use static method sleep(timePeriod) of class AbstractWait. It will sleep current thread for a specified time period.
Pauses test for 5 seconds:
AbstractWait.sleep(TimePeriod.getCustom(5));
We do not recommend this approach. Remember that on different machines the execution speed may vary quite a lot. So a test using sleep may work in your environment but it may not work in another environent (like CI).
You can implement your own wait condition by implementing WaitCondition interface or by extending AbstractWaitCondition.