Image assertion (imageIs)
Classifies the image of the last grabbed element with a classifier trained from sample images (DefaultClassifier) and asserts its label.
Functions
| function | description |
|---|---|
select(selector).imageIs(label, waitSeconds:) |
Asserts that the label the element's image is classified as contains label. Retakes and waits up to waitSeconds. |
imageIs(label, waitSeconds:) |
The implicit form acting on the last grabbed element. |
Where the sample images go
<project>/vision/classifiers/DefaultClassifier/
@i/Settings/[Camera Icon]/ sample images (png / jpg)
@i/Settings/[General Icon]/
...
- The label is the image's parent folder. Folders can be nested to any depth (per OS, per screen and so on).
- The judgement looks only at the part of the label from the last
[([Camera Icon]). Putting the same[…]in two folders is a configuration error and fails. - Each sample should be exactly the element's frame cropped from a screenshot (the element is cropped the same way when it is judged).
- The classifier always answers one of the sample labels. Add samples of the other, easily confused elements on the same screen too, not only the one you want to recognise (at least two labels are needed).
- Files starting with
#are not used for training.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. - The first judgement trains the classifier (a few seconds). The result is kept under
.fleetest/and is retrained only when the samples change. - It works the same way as CheckStateClassifier, which judges checked states from images (each classifier has its own folder).
- When
imageIsfails, the screenshot the classifier judged is attached to the report right under the failed step. - Each judgement also re-checks two of your own samples. If the classifier gets one of them wrong (Vision / Core ML on
the Mac is temporarily broken), its answer is not used and
imageIsfails with that reason.
Capturing and checking samples (CLI)
Instead of cropping samples by hand, capture them from the live device. The element's frame is cropped with the same function the judgement uses, so the crops always match.
fleetest vision capture --project <project> --classifier DefaultClassifier \
--label "@i/Settings/[Camera Icon]" --selector "#element-id" --port <bridge port>
fleetest vision check --project <project>
On Android, pass --platform android --serial <serial> instead of --port.
vision capturerefuses mistakes before saving, such as a label that does not fit the classifier (a folder name that does not end with[…]) or the same label in another folder.vision checktrains if needed and checks whether the classifier can tell its own samples apart. Samples it gets wrong are named in a warning (samples that cannot be told apart will also be confused on real screens). It only warns; the exit code stays 0.- The same warning appears at the end of a scenario when a run finds such samples.
- For using this from MCP, see MCP server.
Example
select("#settings_camera").imageIs("[Camera Icon]")
Notes
- Without samples, or without samples whose label contains
label, the check fails immediately. - The failure message shows the label the image was classified as and its confidence.
- In a variant run, a failure also says whether the label folder has an image taken for that variant (a file named
*-variant-<name>.png). If it has none, add one withft_capture_elementandvariant; if it has one, check the screen for breakage instead of adding another.