-
Notifications
You must be signed in to change notification settings - Fork 70
fMBT GUI Test Interface FAQ
Questions on matching bitmaps:
- Why locating a bitmap fails?
- How can I find suitable OIR parameters for matching a bitmap?
- How can I avoid repeating OIR parameters on every Bitmap method call?
- How can I get coordinates of a bitmap?
- What is the most efficient way to detect which screen the device under test is showing?
Compared screenshot and reference bitmap do not match. For instance, transparency, scaling, antialiasing and slight palette changes are difficult or impossible to see with bare eye, but may cause recognition of the bitmap fail.
Bitmap methods (tapBitmap, ...) require 100 % exact match by default. This can be relaxed by adjusting OIR (optical image recognition) parameters. For instance,
>>> d.tapBitmap("ref-image.png", colorMatch=0.8)
allows 20 % difference on each color channel value on pixel-to-pixel comparisons. Even a bigger threshold may be needed to cope with partial transparency.
fMBT's default OIR engine has a method that searches for OIR parameters that enable finding a reference bitmap on a screenshot. Example:
>>> d.oirEngine().adjustParameters(d.screenshot(), "ref-bitmap.png")
You can give adjustParameters
a range of colorMatch, bitmapPixelSize, screenshotPixelSize, and scale values from which it should find a working combination. For more information, see
>>> help(d.oirEngine())
>>> help(d.oirEngine().adjustParameters)
OIR parameters can be provided in .fmbtoirrc
files. Parameters given in the file apply to all reference bitmaps in the same directory. An example of a pretty liberal .fmbtoirrc
:
colorMatch = 0.8
bitmapPixelSize = 2
screenshotPixelSize = 2
OIR parameters given in Bitmap method calls in test scripts will override parameters read from the .fmbtoirrc
file.
Coordinates of a bitmap are available through found Item
instances. Example:
>>> allItems = d.screenshot().findItemsByBitmap("ref-image.png")
>>> firstItem = allItems[0]
>>> print "(x1, y1, x2, y2) ==", firstItem.bbox()
>>> print "center (x, y) ==", firstItem.coords()
waitAnyBitmap(list-of-reference-bitmaps[, waitTime=n][, pollDelay=n])
waits until any of the reference bitmaps appears on the display, or waitTime expires. It returns a list of bitmaps that contains all reference bitmaps that are visible in the latest screenshot.
Example:
d.tapBitmap("window-close.png")
whatISee = d.waitAnyBitmap(["desktop.png", "browser.png", "camera.png"], waitTime=1.0)
if "desktop.png" in whatISee:
...