Showing posts with label tsl. Show all posts
Showing posts with label tsl. Show all posts

Friday, July 4, 2008

Winrunner - Tooltip verification

Winrunner does not have any built-in function, to get tooltip. Jerry McGowan has written TSL code to verify the tooltip. I was searching my old winrunner scripts. At that time, I found this sample code.

Already I have written a post for tooltip verification by QTP. Post QTP - Tooltip verification in Browser

Winrunner (TSL) code - To verify Tooltip

############################################################ # Function: # check_tootip() # # Description: # Moves the mouse to a specified location within an object # to activate the object popup text message. The expected # popup message is then compared to the actual text, and # the function returns E_OK if the text is found. # # Parameters: # object - Name of the object # tip - The expected tip text that should popup when # the mouse is moved over the object. # x - The x position within the object to move the mouse # y - The y position within the object to move the mouse # # Returns: # "E_OK" if the tip is found, "E_NOT_FOUND" otherwise. # # Syntax: # rc = check_tooltip(object,tip,x,y); # # Example: # check_tooltip("ToolbarWindow32","Create Order",5,5); # ############################################################ function check_tooltip(in object, in tip, in x, in y) { auto parent, text; # Move to the first button of the toolbar obj_mouse_move (object, x,y); # Wait until the tip is displayed. wait(1); # Get the text for the window. obj_get_info(object,"parent",parent); win_get_text(parent, text); # You can then search the contents of text to see if # the expected tip is displayed. if (index (text, tip) > 0) { tl_step ("Tool tip", PASS, tip); return (E_OK); } else { tl_step ("Tool tip", FAIL, tip); return (E_NOT_FOUND); } }; ############################################################ # End of script ############################################################

Thursday, July 3, 2008

Winrunner - SET_WINDOW and WIN_ACTIVATE

This is one of my favorite and Expert questions in Winrunner.

  1. What is the difference between "set_window" and "win_activate"?
  2. When would you use "set_window" and when would you use "win_activate"?

win_activate has the syntax win_activate(window);. The win_activate function
makes the specified window the active window by bringing it into focus and
raising it to the top of the display. (It is the equivalent to clicking on the
window banner)

Set_window has the following syntax: set_window(window,[time]);
The set_window function directs input to the right application window. This
directs the GUI map to this window. It also sets the scope for object
identification in the GUI map.

The most important difference is that set_window has a timing option.
WinRunner will wait a maximum of the number used in the function, PLUS the system set timeout, to wait for the window to appear. Win_activate assumes the window is already on the desktop and has no timing option.

Monday, March 24, 2008

Class Mapping in Winrunner

Class Mapping concept is explained in Custom Objects . Winrunner (WR) also provides class mapping. The Class Mapping enables you to map a custom class to a Standard class.

You can map the classes by two ways.


  • By using Winrunner editor. Use GUI Map editor from Tools Menu.

  • By setting dynamically through TSL (Test Script language) code. See following code snippet.


Code:


#-------------------------------------------------------------------------
# Method : WindowsCustomTextbox
# Author : T.Palani Selvam
# Purpose : It directs the execution according to actions in text box & mapping with given class.
# Parameters:
# sCtrlName - contains name of that control.
# sAction - contains type of the action should be happened.
# sData - contains data to be checked or played in controls.
# sCustomClass - contains class name to be mapped.
# Returns : Integer - returns int value (TRUE = 1 or non-Zero, FALSE = 0)
# Caller :
# Calls : - Nil -
#Logical expressions are assigned the value 1 if true, and 0 if false - From TSL Reference.
#-------------------------------------------------------------------------
public function WindowsCustomTextbox(in sCtrlName,in sAction,in sData, in sCustomClass) {
auto sResult;
auto sMappedClass;
auto sLocation;

get_class_map(sCustomClass , sMappedClass); #Get mapped Class name.
#Verify thr control name type.
sLocation = IdentifyType(sCtrlName);
if (sLocation != "") {
sCtrlName = "{class: edit,MSW_class: " & sCustomClass & ",location: " & sLocation & " }";
}

if (sMappedClass != "edit") {
set_class_map(sCustomClass , "edit"); #Mapping.
sResult = WindowsTextbox(sCtrlName,sAction,sData);
unset_class_map(sCustomClass); #released mapping.
}else {
sResult = WindowsTextbox(sCtrlName,sAction,sData);
}
return sResult;

} #end of function WindowsCustomTextbox

Wednesday, March 5, 2008

Getting Link count in Winrunner

I used to write hardcore code for Automation. I had a situation like, the script has to find searched items and it has to click on particular search item. Also I need to test pagination. The search results are dynamic and I need to select the items as well as need to verify the pagination links.

The following TSL snippet finds the number of links and number of rows in a given table.



public aRowCount, aColCount;
public aCell;
public aRow, aCol;
public aTemp;
public aItem, ar, ac;

public alinkcount, alinkrow;
public aout, atext;
public areturn;

# Browser Main Window
win_activate ("Browser Main Window");

# Search Items
set_window ("Search Items", 2);
wait(5);

tbl_get_rows_count("Link No", aRowCount);
tbl_get_cols_count("Link No", aColCount);

report_msg (aRowCount & " is row count");
report_msg (aColCount & " is col count");

alinkrow = 0;
alinkcount =0;
for (arow=1;arow<= aRowCount; arow++) {
web_obj_get_child_item( "Link No", arow, 1, "html_text_link", 0, aout);

report_msg (aout & " -link description");
if (length(aout) !=0 ) {
alinkcount = alinkcount + 1;
#web_tbl_get_cell_data("Link No",arow,aColCount,0,atext,areturn);
web_obj_get_child_item( "Link No", arow, aColCount, "",0 , atext);
report_msg(atext & " text in the cells");
if (length(atext) !=0 ) {
alinkrow = alinkrow + 1;
}
report_msg(alinkcount & " - total no of links in the table.");
report_msg(alinkrow & " - total no of links having full rows.");
}
}

pause(alinkcount & " - total no of links in the table.");
pause(alinkrow & " - total no of links having full rows.");