Software QA FYI - SQAFYI

Mercury WinRunner FAQ

Part:   1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29   30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45 

Q: WinRunner script for Waitbusy

# only need to load once, best in startup script or wherever load( getenv("M_ROOT") & "\\lib\\win32api", 1, 1 );
# returns 1 if app has busy cursor, 0 otherwise public function IsBusy(hwnd) {const HTCODE=33554433;
# 0x2000001 const WM_SETCURSOR=32;

return SendMessageLong(hwnd, WM_SETCURSOR, hwnd, HTCODE);

# wait for app to not be busy, optional timeout public function WaitBusy(hwnd, timeout) {const HTCODE=33554433;

# 0x2000001 const WM_SETCURSOR=32;
if(timeout) timeout *= 4;
while(--timeout)
{
if (SendMessageLong(hwnd, WM_SETCURSOR, hwnd, HTCODE) == 0) return E_OK;
wait(0,250);

# 1/4 second }
return -1;

# timeout error code }

# wait busy, provide window instead of hwnd public function WinWaitBusy(win, timeout){auto hwnd
; win_get_info(win, "handle", hwnd);
return WaitBusy(hwnd, timeout); }

# example of how to use it... set_window(win); WinWaitBusy(win);


Q: WinRunner script to get Min and Max

public function fnMinMaxWinrunner (in action)
{
auto handle;
const SW_MAXIMIZE = 3;
const SW_MINIMIZE = 6;
load_dll("user32.dll");
#extern int ShowWindow(long, int);
win_get_info("{class: window, label: \"!WinRunner.*\"}", "handle", handle);
switch(action)
{
case "SW_MINIMIZE" :
{
# Maximizing WinRunner
ShowWindow(handle, SW_MINIMIZE);
wait(2);
break;
}
case "SW_MAXIMIZE" :
{ # Maximizing WinRunner
ShowWindow(handle, SW_MAXIMIZE);
wait(2);
break;
}
}
unload_dll("user32.dll");
};


Q: Type special chars in WinRuneer

type special chars as they are, instead of interpreting them
# data can be read from a data file and then typed into an app
#
# escape the following chars: <> - +
# in a string, quote " and backslash \ will already be escaped
#
# generally won't be a lot of special chars, so
# use index instead of looping through each character
#
function no_special(data )
{
auto esc_data, i, p;
esc_data = "";
while(1)
{
p=32000;
i=index(data,"-");
p=i?(i<p?i:p):p;
i=index(data,"+");
p=i?(i<p?i:p):p;
i=index(data,"<");
p=i?(i<p?i:p):p;
i=index(data,">");
p=i?(i<p?i:p):p;
if (p<32000)
{
esc_data = esc_data substr(data,1,p-1) "\\" substr(data,p,1);
data = substr(data,p+1);
}
else break;
}
esc_data = esc_data data;
return esc_data;
}
# trial run here
data = "This -- is +the+ <yobbo> new test sample";
win_activate("Untitled - Notepad");
win_type("Untitled - Notepad", no_special(data));


Q: Clean up script/function from WinRunner

public function cleanup(in win)
{
   auto i;
   auto edit;
   auto atti;
   set_window(win);
   for (i = 0 ; ; i++)
   {
     edit = "{class:edit,index:"i"}";
     if (obj_exists(edit) != E_OK)
        break;
     obj_get_info(edit,"displayed",atti);
     if (atti == 0)
       break;
      obj_get_info(edit,"enabled",atti);
     if (atti == 0)
       continue;
      edit_get_text(edit,atti);
     if (atti != "")
       edit_set_text(edit,"");
    }
}


Q: How to convert variable from ascii to string?

If you want to generate characters from their ascii codes, you can use the sprintf() function, example:
sprintf("%c",65) will generate "A"
If you want to add a number onto the end of a string, you can simply stick it next to the string, example:
ball=5;
print "and the winning number is: " ball;
Putting them together can get some interesting effects, example:
public arr[] = {72,101,108,108,111,32,102,114,111,109,32,77,105,115,104,97};
msg = "";
for(i in arr) msg = msg sprintf("%c",arr[i]);
print msg;
Hmmm, interesting effect from the elements not being in order. I'll try it again:
msg = "";
for(i=0;i<16;i++) msg = msg sprintf("%c",arr[i]);
print msg;

Part:   1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29   30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45 

Mercury WinRunner FAQ