-
Notifications
You must be signed in to change notification settings - Fork 69
GUI testing
Antti Kervinen edited this page Apr 24, 2014
·
22 revisions
fMBT provides utilities for GUI testing:
- Python libraries that implement similar GUI test interface for multiple platforms
- fmbtandroid for Android phones, tablets and emulator
- fmbttizen for Tizen mobile and emulator (X server) and Tizen IVI (Wayland + Weston)
- fmbtvnc for anything that runs VNC servers
- fmbtwindows for Windows desktops, laptops and tablets
- fmbtx11 for X servers
- fmbt-scripter - a tool for
- capturing reference bitmaps from screenshots from Android, Tizen, VNC, Windows and X
- editing and debugging Python GUI test scripts.
GUI test interfaces for multiple platforms have a lot in common, but also some platform-specific extensions.
While this document gives only an overview, you will get full parameter and return value documentation for each GUI test interfaces with Python:
python -c 'import fmbtandroid; help(fmbtandroid.Device)'
python -c 'import fmbttizen; help(fmbttizen.Device)'
python -c 'import fmbtvnc; help(fmbtvnc.Screen)'
python -c 'import fmbtwindows; help(fmbtwindows.Device)'
python -c 'import fmbtx11; help(fmbtx11.Screen)'
If you want help from a single method, use python -c 'import
fmbtandroid; help(fmbtandroid.Device.refreshScreenshot)'
, for
instance.
-
refreshScreenshot
fetches the latest screenshot from the device under test. <act>Bitmap and <act>OcrText methods (liketapBitmap
,swipeOcrText
) use most recently fetched screenshot. -
refreshView
fetches UI elements currently on the screen. <act>Text methods (liketapText
) use most recently fetched UI element information. - Screenshots are automatically stored in the "screenshots" directory
under the working directory, unless something else is specified with
setScreenshotDir
andsetScreenshotSubdir
. - Disk space needed by screenshots can be controlled with
setScreenshotLimit
andsetScreenshotArchiveMethod
. -
screenshot().save(filename)
saves the latest screenshot to given file.
fmbtandroid | fmbttizen | fmbtvnc | fmbtwindows | fmbtx11 | |
refreshScreenshot | Y | Y | Y | Y | Y |
refreshView | Y |
-
verifyBitmap
andverifyOcrText
return True if a bitmap or a text is recognized from latest screenshot. -
screenshot().findItemsByBitmap
andscreenshot().findItemsByOcr
return full list of items matching a bitmap or a text. Full documentation on OIR and OCR parameters can be found withhelp(obj.oirEngine())
andhelp(obj.ocrEngine())
. -
verifyText
returns True if a UI element with given text is found from latest UI element information. -
view().findItemsByClass
,view().findItemsById
,view().findItemsByText
return full list of UI elements matching given criteria. - Items found with
findItemsBy...
can be acted upon withtapItem
andswipeItem
.
fmbtandroid | fmbttizen | fmbtvnc | fmbtwindows | fmbtx11 | |
verifyBitmap verifyOcrText | Y | Y | Y | Y | Y |
verifyText | Y | ||||
screenshot | Y | Y | Y | Y | Y |
view | Y | ||||
ocrEngine | Y | Y | Y | Y | Y |
oirEngine | Y | Y | Y | Y | Y |
- tap<what> sends touch down and touch up (or mouse button down, mouse button up) events on given location. The location can be given as absolute coordinates or unity coordinates, or it can be based on a bitmap, text recognized by OCR, or a text from UI elements.
- platforms that support both touch and mouse events will get a touch event by default. When called with optional argument button=X, a mouse event with button X is sent. If button=0, then only mouse move is sent, resulting in hovering over given location.
fmbtandroid | fmbttizen | fmbtvnc | fmbtwindows | fmbtx11 | |
drag | touch | touch mouse | mouse | touch mouse | mouse |
swipe, swipeBitmap, swipeOcrText | touch | touch mouse | mouse | touch mouse | mouse |
swipeText | touch | ||||
tap, tapBitmap, tapOcrText | touch | touch mouse | mouse | touch mouse | mouse |
tapText | touch |
-
pressKey
sends a key press and release. -
type
types given text. -
keyNames
returns list of key names supported by pressKey.
fmbtandroid | fmbttizen | fmbtvnc | fmbtwindows | fmbtx11 | |
keyNames | Y | Y | Y | ||
pressKey | Y | Y | Y | Y | Y |
type | Y | Y | Y | Y | Y |
-
shellSOE
executes shell command and returns triplet: (Status, Output, Error), that is- child process exit status
- what was printed to standard output
- what was printed to standard error
fmbtandroid | fmbttizen | fmbtvnc | fmbtwindows | fmbtx11 | |
shellSOE | Y | Y | Y |
-
enableVisualLog
starts tracing all GUI test interface method calls, return values, exceptions, captured screenshots and reference bitmaps. The log is written to given HTML file during the test run. -
fmbtlogger.text
andfmbtlogger.csv
log method calls, return values and exceptions of any Python object, including instances of GUI test interfaces. The log format is plain text or CSV. Seepython -c 'import fmbtlogger; help(fmbtlogger.text)'
for more information.
fmbtandroid | fmbttizen | fmbtvnc | fmbtwindows | fmbtx11 | |
enableVisualLog | Y | Y | Y | Y | Y |
Prerequisites:
-
adb
from Android SDK, Platform tools - Enable USB debugging from device settings.
Example:
import fmbtandroid d = fmbtandroid.Device() d.swipe((0.5, 0.85), "east") # open lock screen
Prerequisites:
-
sdb
from Tizen SDK for testing a Tizen mobile device -
ssh
for testing Tizen IVI
Tizen mobile example:
import fmbttizen d = fmbttizen.Device() d.pressPower()
Tizen IVI example:
import fmbttizen d = fmbttizen.Device(loginCommand="ssh root@ivi") d.refreshScreenshot().save("current-screen.png")
Prerequisites:
- Install vncdotool: https://github.com/sibson/vncdotool
Example:
import fmbtvnc d = fmbtvnc.Screen("IP-ADDRESS-OF-VNC-SERVER") d.tap((0.5, 0.5), button=0) # hover mouse on the middle of the screen
Prerequisites for Windows device:
- Install Python 2.X.
- Copy fMBT's pythonshare directory to Windows.
- In the pythonshare directory, run
c:\python27\python.exe setup.py install
- Launch pythonshare-server to which fmbtwindows can connect to:
cd \python27\scripts python pythonshare-server --interface=all --password=xxxxxxxx
Example:
import fmbtwindows d = fmbtwindows.Device("IP-ADDRESS-OF-THE-DEVICE", password="xxxxxxxx") d.type("Hello Windows")
Example:
import fmbtx11 d = fmbtx11.Screen(":2") d.enableVisualLog("calls.html") d.refreshScreenshot()