libcvautomation
1.2
|
import
command from ImageMagick, or something similar. extern "C"
style bindings. cva-match
and cva-input
cva-match
and cva-input
cva-match
allows you to match multiple image files against a root image providing very fine control over how specific the match is cva-input
allows you to drive the X11 server using the XTest extension - for example, clicking on a button from image, clicking a key on the keyboard, and more. #include <libcvautomation/libcvautomation.h>
extern "C"
, and full C++ bindings are not currently planned. Libcvautomation itself is incredibly simple, but interfaces with a few API's (Xlib, libcv) that it is helpful to have an idea of how to use.Now we get into the good stuff. The basic process for application testing is as follows:
import
command, or any other screenshot program. Additionally, libcvautomation will support any image format that OpenCV does. At the time of writing, these are: *.bmp
, *.dib
*.jpeg
, *.jpg
, *.jpe
*.jp2
*.png
*.pbm
, *.pgm
, *.ppm
*.sr
, *.ras
*.tiff
, *.tif
Some tips on creating screenshots:
#!/bin/bash #This is an application test involving libcvautomation and libreoffice . /usr/local/etc/libcvautomation_funcs #Changing any wrapper parameters should go here start_libreoffice_writer () { click_i "screens/gnome-1_menu.png" "screens/kde-1_menu.png" && sleep 1 click_i "screens/gnome-2_officeMenu.png" "screens/kde-2_officeMenu.png" && sleep 1 hover_i "screens/gnome-3_LibreOfficeWriter.png" "screens/kde-3_LibreOfficeWriter.png" jiggle_mouse click sleep 30 } close_libreoffice_writer() { click_i "screens/gnome-4_fileMenu.png" "screens/kde-4_fileMenu.png" && sleep 1 click_i "screens/gnome-5_fileExit.png" "screens/kde-5_fileExit.png" && sleep 1 click_i "screens/gnome-6_discard.png" "screens/kde-6_discard.png" && sleep 1 } start_libreoffice_writer close_libreoffice_writer
#!/bin/bash #This is an application test involving libcvautomation and libreoffice . /usr/local/etc/libcvautomation_funcs #Changing any wrapper parameters should go here
locate libcvautomation_funcs
to find it on your computer. The wrapper itself is a handful of macros used to make our job easy. start_libreoffice_writer () { click_i "screens/gnome-1_menu.png" "screens/kde-1_menu.png" && sleep 1 click_i "screens/gnome-2_officeMenu.png" "screens/kde-2_officeMenu.png" && sleep 1 hover_i "screens/gnome-3_LibreOfficeWriter.png" "screens/kde-3_LibreOfficeWriter.png" jiggle_mouse click sleep 30 }
click_i
is a function to click the mouse at an image - in this case, the gnome or kde menu. click_i
, we make things a bit more readable - the full command line is cva-input -s 'icmouseclick <filename>'
hover_i
is a function to move the mouse to an image - in this case, move it over the LibreOffice menu item. close_libreoffice_writer() { click_i "screens/gnome-4_fileMenu.png" "screens/kde-4_fileMenu.png" && sleep 1 click_i "screens/gnome-5_fileExit.png" "screens/kde-5_fileExit.png" && sleep 1 click_i "screens/gnome-6_discard.png" "screens/kde-6_discard.png" && sleep 1 }
click_i
function to close down LibreOffice writer - Find the "File" menu, click "Exit", and then make sure to discard all changes. start_libreoffice_writer close_libreoffice_writer
If you need to, some things you can do to tune the application test are as follows:
SEARCH_METHOD
TOLERANCE
USE_SANE_TOLERANCE
INT_MIN
to INT_MAX
, the sane tolerance accepts values of 1 - 100 ( \( 1 \approx 0 \), and \( 100 \approx INT\_MAX \)) USE_SANE_TOLERANCE="<any_value>"
USE_SANE_TOLERANCE=""
USE_CENTER
USE_CENTER=""
USE_CENTER="<any_value>"
OUTFILE
and ERRFILE
/dev/null
by default. OUTFILE
and ERRFILE
, set them to any file you want. For example, the following code will create a temporary file for OUTFILE and ERRFILE, and notify you of what they are: OUTFILE=`mktemp` ERRFILE=`mktemp` echo "OUTFILE location: $OUTFILE" echo "ERRFILE location: $ERRFILE"
#Changing any wrapper parameters should go here