Interview Questions

WinRunner: Use the following templates to assist in your scripting

Mercury WinRunner FAQ


(Continued from previous question...)

WinRunner: Use the following templates to assist in your scripting

As a default header for all scripts.
###########################################################
# Script Name:
# Description:
#
# Project:
# #########################################################
# Revision History:
# Date: Initials: Description of change:
#
###########################################################
# Explaination of what script does:
#
#
###########################################################
#this is here for debugging only, when run in shell script
#will comment out.
#reload ("J:\\CorpQATD\\TD_Daybr\\functions\\functions");
{put code here}

As a default script will reset the WinRunner's environment to have the correct option settings and GUI maps loaded.
###########################################################
# Script Name: Setenv
# Description: This script sets up the environment for the
# the automated testing suite ( ).
# Project:
# #########################################################
# Revision History:
#
# Date: Initials: Description of change:
#
#
###########################################################
# Load the Gui map
#GUI_unload ("c:\\ \\ ");
# remember to use double slashes
# Load Functions
#font group
# Load any dll's
# set any option parameters for this particular script.
# Turns off error message if the test case fails.
setvar ("mismatch_break", "off");
# Turn off beeping
setvar ("beep", "off");
setvar ("sync_fail_beep", "off");
# Make sure context sensitive errors don't trigger failure
setvar ("cs_fail", "off");
# Sets time winrunner waits between executing statements
setvar ("cs_run_delay", "2000");
# Sets time winrunner waits to make sure window is stable
setvar ("delay_msec", "2000");
# Declare any Constant Declarations
# Declare any Variable Declarations


As a default script to use for calling all the scripts in your project.
###########################################################
# Script Name: OpenClose
# Description: This is the calling(main script that runs ....
#
# Project:
# #########################################################
# Revision History:
#
# Date: Initials: Description of change:
#
###########################################################
status=0;
passed=0;
failed=1;
#Run the set up environment script
call "c:\\ "();
#Run the begin script
call "c:\\ "();
# Run
call "c:\\ "();
# Run end script
call "c:\\ "();
# Run the closeenv script
call "c:\\ "();

As a default script to reset your WinRunner environment to the generic default settings.
###########################################################
# Script Name: closeenv
# Description: This script re-sets the environment to the
# default settings.
# Project:
# #########################################################
# Revision History:
#
# Date: Initials: Description of change:
# 1
#
###########################################################
# Load the Gui map
#GUI_unload ("c:\\ \\ "); # remember to use double slashes
# Load Functions
#font group
# Load any dll's
# set any option parameters for this particular script.
# Turns off error message if the test case fails.
setvar ("mismatch_break", "off");
# Turn off beeping
setvar ("beep", "off");
setvar ("sync_fail_beep", "off");
# Make sure context sensitive errors don't trigger failure
setvar ("cs_fail", "off");
# Sets time winrunner waits between executing statements
setvar ("cs_run_delay", "2000");
# Sets time winrunner waits to make sure window is stable
setvar ("delay_msec", "2000");
# Declare any Constant Declarations
# Declare any Variable Declarations


WinRunner: The following code is written to replace WinDiff as used by WinRunner for showing differences in file comparison checks.

Written by Misha Verplak
INSTRUCTIONS
. Place these files into winrunner \arch directory:
wdiff_replace.exe
wdiff_replace.ini

. Rename wdiff.exe to wdiff_orig.exe

. Rename wdiff_replace.exe to wdiff.exe . Edit wdiff_replace.ini to specify the new difference program

FILES
wdiff_replace.exe compiled program
wdiff_replace.ini settings
wdiff_replace.c C source code
wdiff_readme.txt this file :)

#include
#define TITLE_NAME TEXT("wdiff_replace")
#define CLASS_NAME TEXT("funny_class")
#define BC2_APP_PATH TEXT("C:\\Program Files\\Beyond Compare 2\\BC2.exe")
#define WDIFF_INI TEXT("wdiff.ini")
#define WDIFF_REPL_INI TEXT("wdiff_replace.ini")
#define EMPTY_TXT TEXT("[EMPTY]")
extern char** _argv;
int WINAPI
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
DWORD res;
TCHAR sLeftFile[MAX_PATH], sRightFile[MAX_PATH];
TCHAR sAllArgs[MAX_PATH*2];
TCHAR sPathDrive[MAX_PATH], sPathDir[MAX_PATH], sPathFile[MAX_PATH], sPathExt[MAX_PATH];
TCHAR sDiffReplIni[MAX_PATH];
TCHAR sDiffApp[MAX_PATH];
TCHAR sErrMsg[MAX_PATH*2];
TCHAR sArgN[10], sArg[MAX_PATH];
int n;
/* using argv[0] (current fullpath exe), extract directory name, expect to find ini there */
_splitpath (_argv[0], sPathDrive, sPathDir, sPathFile, sPathExt);
sprintf(sDiffReplIni, "%s%s%s", sPathDrive, sPathDir, WDIFF_REPL_INI);
/* read wdiff.ini for WinRunner's two files */
res = GetPrivateProfileString(TEXT("WDIFF"), TEXT("LeftFile"), EMPTY_TXT, sLeftFile, MAX_PATH, WDIFF_INI);
res = GetPrivateProfileString(TEXT("WDIFF"), TEXT("RightFile"), EMPTY_TXT, sRightFile, MAX_PATH, WDIFF_INI);
/* check if got the default string, this means didn't get a value */
if (!strcmp(sLeftFile, EMPTY_TXT) || !strcmp(sRightFile, EMPTY_TXT)) {
MessageBox (NULL, TEXT("Problem reading LeftFile or RightFile from wdiff.ini"), TITLE_NAME, MB_ICONERROR | MB_OK);
return(0);
}
/* read wdiff_replace.ini for file & path of replacement to wdiff */
res = GetPrivateProfileString(TEXT("Diff"), TEXT("diff_app"), EMPTY_TXT, sDiffApp, MAX_PATH, sDiffReplIni);
if (!strcmp(sDiffApp, EMPTY_TXT)) {
sprintf(sErrMsg, "Problem reading diff_app from:\n\n%s", sDiffReplIni);
MessageBox (NULL, sErrMsg, TITLE_NAME, MB_ICONERROR | MB_OK);
return(0);
}
/*
* read wdiff_replace.ini for args
* add the arguments together, with quotes, eg. "arg1" "arg2"
* also substitute for LeftFile and RightFile
*/
sprintf(sAllArgs, "");
n=1;
while(1) {
sprintf(sArgN, "arg%d", n);
res = GetPrivateProfileString(TEXT("Diff"), sArgN, EMPTY_TXT, sArg, MAX_PATH, sDiffReplIni);
if (!strcmp(sArg, EMPTY_TXT)) break;
if (!strcmp(sArg, TEXT("LeftFile"))) strcpy(sArg, sLeftFile);
if (!strcmp(sArg, TEXT("RightFile"))) strcpy(sArg, sRightFile);
if (n == 1) {
sprintf(sAllArgs, "\"%s\"", sArg);
}
else {
sprintf(sAllArgs, "%s \"%s\"", sAllArgs, sArg);
}
n++;
}
/* Run alternative diff application with its args (could use spawn here?) */
res = execlp (sDiffApp, TEXT("dummy"), sAllArgs);
/* exec replaces current app in the same env, so only get to here if problems */
sprintf(sErrMsg, "Problem running diff_app:\n\n%s", sDiffApp);
MessageBox (NULL, sErrMsg, TITLE_NAME, MB_ICONERROR | MB_OK);
return 0;
}

(Continued on next question...)

Other Interview Questions