State assertion (enabledIsTrue, enabledIsFalse, checkIsON, checkIsOFF)
Checks on the enabled/disabled and checked/unchecked state of the last grabbed element.
Functions
| function | description |
|---|---|
select(selector).enabledIsTrue(waitSeconds:) |
Asserts the element is enabled. Waits up to waitSeconds for a state change. The target is the element grabbed last. |
select(selector).enabledIsFalse(waitSeconds:) |
Asserts the element is disabled. Same waiting behavior. |
select(selector).checkIsON(prefer:, waitSeconds:) |
Asserts the element is checked. prefer: picks the source to read the state from (.classifier / .accessibility) for this one command; omitted = the run profile decides. |
select(selector).checkIsOFF(prefer:, waitSeconds:) |
Asserts the element is not checked. prefer: is the same as in checkIsON. Warns at the end of the run if the element never reported a checked state (on or off). |
All four are chainable on the return value of exist / select, and each also has an implicit
free-function form that acts on the last grabbed element (e.g. enabledIsTrue()).
Example
select("#login_btn").enabledIsFalse()
tap("#email"); type("test@example.com")
tap("#password"); type("password123")
select("#login_btn").enabledIsTrue()
select("#toggle_notifications").checkIsON()
Notes
- The checked state is read from accessibility. iOS implementations report it in different ways and
fleetest reads all of them (the selected trait, a switch value of
"1"/"0", React Native's"checkbox, checked"and so on). - Some elements never report a checked state (for example a checkbox built from a SwiftUI
Button).checkIsONon such an element fails with "reports no check state". Verify a text that reflects the state withtextIs, or have the app expose it (in SwiftUI,.accessibilityRepresentation { Toggle(...) }).checkIsOFF, on the other hand, passes on an element that reports no state (a warning appears at the end of the run). To really verify it is off, check a text that reflects the state withtextIs, or add CheckStateClassifier samples. - Implementations that report only "on" (Compose checkboxes on iOS, for example): once the same
scenario has seen the element on, a missing report is read as off.
checkIsOFFon an element that was never seen on passes without knowing the state, and a warning is shown at the end of the run. - An element in an indeterminate (partially checked) state fails both
checkIsONandcheckIsOFF. enabledIsTrue/enabledIsFalseafterselectjudge the state at the moment of the select (if it does not match, they read the screen again and wait). An element that draws no text (such as a loading skeleton row) makesselectreturn an empty element because it is not visible; the state at the moment of the select is still used (its text value is not exposed).
Judging the checked state from images (CheckStateClassifier)
Parts whose accessibility reports no checked state can be judged by an image classifier trained from sample images.
<project>/vision/classifiers/CheckStateClassifier/
[ON]/ sample images of the "on" state (png / jpg)
[OFF]/ sample images of the "off" state
[INDETERMINATE]/ sample images of the partially checked state (optional)
- Each sample should be exactly the element's frame cropped from a screenshot (the element is cropped the same way when it is judged).
- With samples in
[INDETERMINATE], a partially checked look is judged indeterminate and bothcheckIsONandcheckIsOFFfail for that reason (a fleetest-specific label). Without them, it is judged on or off. - The classifier always answers one of the sample labels. If switches or radios on the same screen are judged too, add samples of them as well (looks that are not in the samples are easy to misjudge).
- The first judgement trains the classifier (a few seconds). The result is kept under
.fleetest/and is retrained only when the samples change. - The run profile's
preferCheckStateClassifier(defaulttrue) prefers the classifier over accessibility. Withfalse, it is used only for elements whose accessibility reports no checked state. - To change it for one command, pass the argument:
checkIsON(prefer: .classifier)judges with the classifier when there are samples, andcheckIsON(prefer: .accessibility)judges with accessibility for elements whose accessibility reports a checked state (elements that report none are still judged by the classifier). The choice is shown on the step in the report.checkIsOFFtakes the same argument; when omitted, the run profile decides. - Steps judged from the image carry the note
check-state-classifiedin the results. - When accessibility and the classifier disagree, the step does not decide right away: it retakes the screenshot and reads again
(up to 7.5 seconds), because the screen image can lag behind. If they still disagree, the classifier's answer is used and the
step carries the note
check-state-disagreed. - Each judgement also re-checks two of your own samples (one per label). If the classifier gets one of them wrong,
its answer is not used and the checked state comes from accessibility only (note
check-state-classifier-failed). This happens when Vision / Core ML on the Mac is temporarily misbehaving. If it persists, reboot the Mac. - When the app area of the screenshot (apart from the status bar and the bottom strip) is a single colour (all black or
all white: nothing was captured, or nothing is drawn), the image is not judged either, and the checked state comes from accessibility only (note
check-state-classifier-failed). While the step waits, it takes the screenshot again. - When a check judged from the image fails, the screenshot the classifier judged is attached to the report right under the failed step, so you can see what it looked at.
options=(training settings) andimageFilter=binary(also train on black-and-white versions of the samples) in the header comment of anMLImageClassifier.swiftplaced in the classifier folder are read too.- imageIs uses the same mechanism to assert the label of an element's image.
- Capture and check samples with
fleetest vision capture --classifier CheckStateClassifier --label "[ON]" --selector "#…"andfleetest vision check(details on the imageIs page). - On Android, both
isCheckedandisSelectedare considered — tabs and selectable rows that only reportisSelected(notisChecked) are still recognized as checked.