Showing posts with label wrcode. Show all posts
Showing posts with label wrcode. 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 ############################################################

Wednesday, May 21, 2008

Winrunner - Handling Dynamic objects

Most of the Winrunner users are using playback methods to develop the scripts. Here I have given two code snippets to handle dynamic objects.

Code: To find Image

public function SetToSearchPage() { web_sync(200); set_window("{class: window, MSW_class: html_frame,active:1}",60); web_image_click("{class: object,MSW_class: html_rect,html_name: \"search_gnav.gif\"}", 0, 0); web_sync(250); } #End of SetToSearchPage()

Code: To find correct Window, after clicking a link
public function SetTitle() { set_window("{class: window, MSW_class: html_frame,active:1}",20); win_get_info("{class: window, MSW_class: html_frame,active:1}","html_name", sWinTitle); #report_msg("RE Source Page Title is " & sWinTitle); if (index(sWinTitle, "Users") != 0) { set_window("My Users",40); #report_msg("My Users page has been identified"); } else if (index(sWinTitle, "Group") != 0) { set_window("Group",20); #report_msg("Group page has been identified"); } else if (index(sWinTitle, "View Agenda") != 0) { set_window("View Agenda",30); #report_msg("View Agenda page has been identified"); }else { report_msg("Couldn't find the window in GUI MAP is " & sWinTitle); } }

Tuesday, May 20, 2008

Winrunner - File Handling

Winrunner code is similar to 'C' code. Any automation suite must have file handling functions for various scenarios. It may be just text files or any data files. Winrunner also has few methods for file handling. Below few sample code snippets are given..

Code: To read a file

#--------------------------------- # Method : fileRead # Author : T.Palani Selvam # Purpose : Read all contents of a file. # Parameters: String, contains file name. # # Returns : - Nil - # Caller : # Calls : - Nil - #---------------------------------- public function fileRead(in m_sFile) { auto iLine; auto sEachLine; auto sFileContent; printf("fileRead is going to process for " & m_sFile); file_open(m_sFile,FO_MODE_READ); iLine = 0; while(file_getline(m_sFile, sEachLine) == 0) { sFileContent = sFileContent & sEachLine; iLine++; printf(sEachLine); } #report_msg(sFileContent); #Line is too length file_close(m_sFile); } #end of fileRead(in m_sFile)


Code: To write info to a file
#------------------------------ # Method : fileWrite # Author : T.Palani Selvam # Purpose : Write Given inputs to a file. # Parameters: String, contains file name. # # Returns : - Nil - # Caller : # Calls : - Nil - #----------------------------- public function fileWrite(inout m_sFile) { auto iLine; auto sEachLine; auto iBool; auto null=""; printf("fileWrite is going to process for " & m_sFile); file_open(m_sFile, FO_MODE_WRITE); iLine = 0; do { sEachLine = create_input_dialog("Enter Input to write in " & m_sFile); if (sEachLine == null ) { #equals to NULL iBool = 0; } else { iBool = 1; iLine = iLine + 1; file_printf(m_sFile,"%s",sEachLine & "\r\n"); printf(sEachLine); } } while(iBool == 1); file_close(m_sFile); #Closing file } #end of fileWrite(in m_sFile)


Code: To Append info to a file
#----------------------------------- # Method : fileAppend # Author : T.Palani Selvam # Purpose : Write Given inputs to a file. # Parameters: String, contains file name. # # Returns : - Nil - # Caller : # Calls : - Nil - #---------------------------------- public function fileAppend(inout m_sFile) { auto iLine; auto sEachLine; auto iBool; auto null=""; printf("fileAppend is going to process for " & m_sFile); file_open(m_sFile, FO_MODE_APPEND); iLine = 0; do { sEachLine = create_input_dialog("Enter value to append in " & m_sFile); if (sEachLine == null ) { #equals to NULL iBool =0; } else { iBool = 1; iLine = iLine + 1; file_printf(m_sFile,"%s",sEachLine & "\r\n"); printf(sEachLine); } } while(iBool == 1); file_close(m_sFile); } #end of fileAppend(in m_sFile)

Thursday, May 15, 2008

Winrunner - Code for TimeStamp

I used to develop a function to have timestamps in all the testing tools. I have written same in Winrunner also. It will be useful to create unique files and set the dateTime info whenever needed. Below I have given the TSL (Test Script Language) code snippet for timestamps.

TSL Code: TimeStamp for Current time



#This function returns the current system time like this --> "24Jan2003_11hh_20mm_45ss"
public function GetTime() {
# w - in terms of Word
auto sDate, sTime, sDayW, sDayN, sMonthW, sMonthN, sYear, sHour, sMinute, sSecond;
auto sCurDate, sCurTime;
auto sArrDate[], sArrTime[];
auto sReturn;

sCurTime = get_time();
sCurDate = time_str(sCurTime); #returns like Mon Dec 16 16:09:56 2002

split (sCurDate, sArrDate, " ");
sDayW = sArrDate[1];
sMonthW = sArrDate[2];
sDayN = sArrDate[3];
sTime = sArrDate[4];
sYear = sArrDate[5];

split(sTime, sArrTime, ":");
sHour = sArrTime[1];
sMinute = sArrTime[2];
sSecond = sArrTime[3];

sReturn = sDayN & sMonthW & sYear & "_" & sHour & "hh_" & sMinute & "mm_" & sSecond & "ss";

return sReturn;

} #end of GetTime()

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.");