Check functions

Some functions for comparing screen images or text are listed below. The results are stored using the Comment statement and so you must declare the use of a logfile.

 

''We log the results of the checks in the WinTask Log file.
'So use Configure/Run menu and check Log checkbox and Limited checkbox.
'After having run the checks, the results can be seen using File/Open Log menu

'If there is an error when comparing reference file and the one captured,
'we change file extension from .bmp to .err.

'This function is called by the check functions which are listed after the declaration of this first function.

function gene_fich$(fichier_bmp$)

local tamp$, res$, rep_fich$,nom_fich$, fin, pos

 

'extract filename without path

fin=0

tamp$=fichier_bmp$

repeat

pos=instr(tamp$,"\")

if pos=0 then

fin=1

else

lg=len(tamp$)

tamp$=right$(tamp$,lg-pos)

endif

until fin=1

nom_fich$=tamp$

 

'extract path

pos=instr(fichier_bmp$,tamp$)

rep_fich$=left$(fichier_bmp$,pos-2)

 

nom_fich$=left$(nom_fich$,len(nom_fich$)-3)

 

res$=rep_fich$+"\"+nom_fich$+"err"

if exist(res$)=1 then

kill(res$)

endif

gene_fich$=res$

endfunction

 

'-----------------------------------------------------------------

'this function tests if an image is in a window

function test_bitmap_fen(fichier_bmp$, fen_test$,t_max,nom_du_test$)

local res

res=1

 

PAUSE t_max seconds until
Bitmap(fichier_bmp$)
InWindow(fen_test$)
PauseFalse
res=0
EndPause

if res=0 then

comment("Test : "+nom_du_test$+" FAILED.")

fich_cour$=gene_fich$(fichier_bmp$)

UseWindow(fen_test$)
CaptureBitmap(fich_cour$)

comment("Actual image can be viewed in "+fich_cour$)

else

comment("Test : "+nom_du_test$+" SUCCESS")

endif

 

test_bitmap_fen=res

endfunction

 

'---------------------------------------------------------------

'function testing if an image is in a specific area of a window

 

function test_bitmap_zone(fichier_bmp$, fen_test$, pos_x, pos_y, hauteur, largeur, t_max, nom_du_test)

 

local res

res=1

 

PAUSE t_max seconds until
Bitmap(fichier_bmp$)

InWindow(fen_test$)
InArea( pos_x, pos_y, hauteur,largeur )

PauseFalse

res=0

EndPause

if res=0 then

comment("Test : "+nom_du_test$+" FAILED.")

fich_cour$=gene_fich$(fichier_bmp$)

UseWindow(fen_test$)
CaptureBitmap(fich_cour$, InArea(pos_x, pos_y, hauteur, largeur) )

comment("Actual image can be seen in "+fich_cour$)

else

comment("Test : "+nom_du_test$+" SUCCESS")

endif

test_bitmap_zone=res

endfunction

 

'-----------------------------------------------------------------------

'function testing if a text is in a window

function test_texte_fen(texte_cherche$, fen_test$, t_max, nom_du_test$)

local res

res=1

 

Pause t_max seconds until

Text(texte_cherche$)

InWindow(fen_test$,1)

PauseFalse

res=1

EndPause

 

if res=0 then

comment("Test : "+nom_du_test$+" FAILED.")

a$=capture$(fen_test$,0,1)

else

comment("Test : "+nom_du_test$+" SUCCESS")

endif

 

test_texte_fen=res

endfunction

 

'-----------------------------------------------------------------------

'function testing if a text is in a specific area of a window

function test_texte_zone(texte_cherche$, fen_test$, pos_x, pos_y, hauteur, largeur, t_max, nom_du_test$)

local res, a$, t, sortie

res=0

t=0

 

repeat

a$=CaptureArea$(fen_test$,0,pos_x,pos_y,hauteur,largeur)

if instr(a$,texte_cherche$)<>0 then

res=1

else

pause 1

t=t+1

endif

until res=1 or t > t_max

 

if res=0 then

comment("Test : "+nom_du_test$+" FAILED.")

comment("Waited text : "+texte_cherche$)

a$=capturearea$(fen_test$,0,pos_x,pos_y,hauteur,largeur)

comment("Actual text " + a$)

else

comment("Test : "+nom_du_test$+" SUCCESS.")

endif

 

test_texte_zone=res

endfunction

 

'*******************************************************************************

'EXAMPLE

'You must first create your reference bitmaps called here notepad1.bmp,notepad2.bmp, ...

 

shell("Notepad")

 

UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad",1)

SendKeys("toto<Enter>")

 
'Test Find window

'You must first create the reference bitmap for the Notepad Find window. You can use HardCopy WinTask function for creating notepad1.bmp

UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)

ChooseMenu(Normal,"&Edit|&Find...;Ctrl+F")

 

test_bitmap_fen("C:\Program Files\WinTask\Scripts\notepad1.bmp", "NOTEPAD.EXE|#32770|Find",20,"Window to look for NOTEPAD")

 

'close Find window

UseWindow("NOTEPAD.EXE|#32770|Find",1)

Click(Button,"Cancel")

 

'text typing

UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad",1)

SendKeys("tita<Enter>")

SendKeys("toto<Enter>")

SendKeys("titi<Enter>")

SendKeys("toto<Enter>")

 

test_texte_fen("titi","NOTEPAD.EXE|Edit|Untitled - Notepad|1",10,"Edit window NOTEPAD")

 

'look for titi

 

UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)

&#9;ChooseMenu(Normal,"&Edit|&Find...&#9;Ctrl+F")

 

UseWindow("NOTEPAD.EXE|#32770|Find",1)

WriteEdit("1","titi")

Click(Button,"&Find Next")

 

'You must first create the reference bitmap for the Notepad not found window.
'You can use HardCopy WinTask function for creating notepad2.bmp - for example:
'HardCopy("C:\Program Files\WinTask\Scripts\notepad2.bmp", 2, 0)

'test Find result

test_bitmap_fen("C:\Program Files\WinTask\Scripts\notepad2.bmp", "NOTEPAD.EXE|#32770|Notepad",20,"Search without occurence NOTEPAD")

 

UseWindow("NOTEPAD.EXE|#32770|Notepad",1)

Click(Button,"OK")

 

'search up

UseWindow("NOTEPAD.EXE|#32770|Find",1)

Click(Radio,"&Up")

Click(Button,"&Find Next")

 

'test Find result

test_bitmap_fen("C:\Program Files\WinTask\Scripts\notepad3.bmp","NOTEPAD.EXE|Edit|Untitled - Notepad|1",20,"Search with occurence NOTEPAD")

 

'close

UseWindow("NOTEPAD.EXE|#32770|Find",1)

Click(Button,"Cancel")

 

'close notepad

KillApp("notepad.exe",1)