Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exception handling_urgent help please

Status
Not open for further replies.

mathon

Programmer
Apr 20, 2005
31
0
0
DE


I have written a testscript with an input-file where the control names, window names, etc. are quoted. Furthermore I have defined GUI-Maps and the parameter in the input file are defined according to the GUI-Maps. Now I want to add an exception handling if the test case could not be executed correctly. When the exception occurs I want to create a screen shot of the screen and go on with the next test case.
My input file looks like this (the lines are read in and are separated and the the commands like menu_select_item are defined for this parameter in the test script):
[TC 1]
Main;No;Button;buttonPress
...
[TC 2]
...

Could anyone give me some explanations how I can define that?
 
Are you using WinRunner or QTP?

Can you also give a little more detail about what the script does and what you are trying tro achieve with it.

Posting the code may help us to help you better.

Thanks
Dave

"Probably the only Test Analyst on Tek-Tips"

Take a look at Forum1393 & sign up if you'd like
 
Hello,

the main test script looks like this:

#global variables
public g_sGuifolder;
public g_sConfigfile;
public g_sSysdate;
public g_sSearchpath;
public g_sLogging;

#constants
public const cLevelTA = 200;
public const cLevelTC = 100;
public const UNKNOWN_CONTROLTYP = -9999;

rc = E_OK;

#set the enviromentvariables
g_sSearchpath = "C:\\Testrun\\";
g_sConfigfile = g_sSearchpath & "config.ini";

#Load required Libraries
rc = reload(g_sSearchpath & "Libs\\File", 0, 1);
rc = reload(g_sSearchpath & "Libs\\Util", 0, 1);
rc = reload(g_sSearchpath & "Libs\\Test", 0, 1);
rc = reload(g_sSearchpath & "Libs\\SpecialTAs", 0, 1);

#Unload and close all open and loaded Guimaps
if (rc == E_OK) {
rc = GUI_close_all();
rc = GUI_unload_all();
}

#read configfile
rc = getConfigValue(g_sConfigfile, "Executionfolder", g_sExecfolder);
rc = getConfigValue(g_sConfigfile, "Guimaps", g_sGuifolder);
rc = getConfigValue(g_sConfigfile, "Log", g_sLogging);

rc = set_window(Main);
if(rc!=E_OK)
startApplication();
g_sSysdate = getSysDate(); #implement function in "Util"

# write log headline

writeLog("<TestfallName>--<Datum>--<Control>--<Status>--<eventueller Fehler>");

#open the application in intial state


rc = startApplication(); #implement function in "Test"


#process the Testset
if (rc==E_OK)
{
rc = doTestSet();
}

#clear global variables
g_sGuifolder = "";
g_sConfigfile = "";
g_sSysdate = "";
g_sSearchpath = "";
g_sLogging = "";

#unload loaded Libraries
rc = unload(g_sSearchpath & "Libs\\File");
rc = unload(g_sSearchpath & "Libs\\Util");
rc = unload(g_sSearchpath & "Libs\\Test");
rc = unload(g_sSearchpath & "Libs\\SpecialTAs");

and the Testscript where the lines of the input file are read in and the commands (switch statement) are executed looks like this:

#declared in Testrun
extern g_sSearchpath;
extern g_sConfigfile;
extern g_sGuifolder;
extern g_sLogging;
extern g_sSysdate;
extern termination;
static tl_msg;
#function processes the testset
public function doTestSet()
{
auto sInputValues[];
auto rc = E_OK;

#start logging if global variable is true
if (g_sLogging==TRUE)
{
rc = logClear();
rc = logString("Starting Testset at " & g_sSysdate & "...");
if (rc!=E_OK)
pause ("ERROR: Could not write to 'Testlog.txt'");
}


#get rows from Input.csv
rc = getInputValues(g_sSearchpath & "\Input.csv", sInputValues);

if (rc!=E_OK)
logString(" ERROR: Couldn't read Testset in '" & g_sSearchpath & "\Input.csv'");
else
{


#loop through all TestCases and execute them

rc = executeTestCases(sInputValues);

if (g_sLogging==TRUE)
{
rc = logString("Testset finished at " & getTime());
if (rc!=E_OK)
pause ("ERROR: Could not write to 'Testlog.txt'");
}


if (rc!=E_OK)
pause ("ERROR: Could not execute Testset");
}


}



public function executeTestCases(inout sInputValues[])
{
auto rc = E_OK;
auto sTemp[];
auto sTC;
auto sControlName;
auto sControlTyp;
auto sActionTyp;
auto sWindow;
auto sArgument;
auto sState;
auto sFunction;
auto sLevel;
auto i = 0;



do
{
#ignore comments
if (substr(sInputValues,1,1)=="#")
{}
else
{
# get the TestCase Name
if (match(sInputValues, "\[*\]"))
{
sLevel = cLevelTC;
sTC = substr(sInputValues, 2, length(sInputValues)-2);
if (g_sLogging==TRUE)
rc = logString(" processing TA: '" & sTC & "' at " & getTime());



}
#get TestAction Values
else
{
sLevel = cLevelTA;
split(sInputValues,sTemp, ";");
sWindow = sTemp[1];
sControlName = sTemp[2];
sControlTyp= sTemp[3];
sArgument = sTemp[4];
sActionTyp = sTemp[5];

#load Guimap and set window according to sWindow;

rc = GUI_open(g_sGuifolder & sWindow & ".gui");
rc = GUI_load(g_sGuifolder & sWindow & ".gui");
rc = set_window(sWindow);


#case of speacial treatment of Testaction call appropriate function
if (match(sInputValues, "SPTA_*")==1)
{
rc = eval(sInputValues & "();");
}
else
{
#process Control
if (g_sLogging==TRUE)
rc = logString(" performing '" & sControlName & "' with Controltyp '" & sControlTyp & "'" );

switch (sControlTyp)
{
case "list":
if(sActionTyp=="listSelect")
{
rc = list_select_item (sControlName,sArgument);
}

if(sActionTyp=="listActivate")
{
rc = list_activate_item (sControlName,sArgument);
}
break;

case "toolBar":

rc = toolbar_button_press("ToolbarWindow32", sControlName);
break;

case "textField":

rc = edit_set(sControlName, sArgument);
break;

case "Button":
rc = button_press(sControlName);
break;

case "menuItem":
rc = menu_select_item (sArgument";" & sControlName);
break;

default:
rc = UNKNOWN_CONTROLTYP;
pause("Unknown Controltyp");
}
tl_step(termination,1, tl_msg);

}

#wait 1,5 sec to handle next Control
wait(1,5);
rc = GUI_unload_all();
rc = GUI_close_all();

}


}
i++;
}
while(sInputValues!="");
}


#Starts the application so that the testcases can be executetd

public function startApplication()
{
auto rc = E_OK;
auto buttonText;
auto buttonInfo;

#start the application
invoke_application("","","", SW_SHOW);


return rc;

#A Crash Events in the Recovery Manager was defined for the case
#if the application crashes.

}

The problems which can occur in the test is that a window pops up with an notification or an error message.In that case I should be able to decide between a made screenshot and continue with the next testcase and a made screenshot and the whole test will be terminated.
The input file looks like this:

#Window;ControlName;ControlTyp;Argument;ActionTyp(optional)
[TC 1]
Main;Open;menuItem;File;menuItemSelect
OpenArchive;Search in:_0;list;Harddisk (C:);listSelect
Main;MakeExe;menuItem;Actions;menuItemSelect
[TC2]
TestNotification;Nein;Button;buttonPress
WinZipSelfExtractor;Close;Button;buttonPress
Main;CloseArchive;menuItem;File;menuItemSelect
Main;Exit;menuItem;File;menuItemSelect


I hope now you have a better overview about my problem...?

mathon

 
First you need to trap the error event. Look to do this with a window_exists check which names the error box. You;ll need to create the error pop up in the GUI Map

Something like :

if(window_exists(ErrorBox))
errorTrap();

and declare a function errorTrap which offers a choice of grabbing a screenshot and then skipping to the next test, or terminates the test entirely.

Dave

"Probably the only Test Analyst on Tek-Tips"

Take a look at Forum1393 & sign up if you'd like
 
Hello,

I have already created GUI-Maps of the certain error windows which could be occur and I thought that it must be an if-question something like this. Two kinds of error windows can occur. Is it possible to write in TSL something like the following:

if(window_exists(ErrorBox) || window_exists(ErrorBox2))

//something like the logical or in c# or java or do i have to solve this in another way?

But now unfortunately I have some more questions beside the above one:

1) Where do I have to add this if question? at the beginning of the executedTestCases method or before the switch statement or anywhere else?

2) How can I create screen shots with TSL? I only know how to create screen shots in c# for PocketPc's.

3) How can I "jump" in case of an error to the next testcase and continue the test? - The testcases are only defined in the inputFile with the following statement [TC 1], [TC 2], etc.

4) So far I only have worked out the solution to terminate the whole test in killing the process of the tested programm but I think that is not a good solution. How can I terminate the whole test in a good way?

I know that's a lot questions but I am a little in a hurry because the tests of the release should be executed very soon. Hopefully you can help me once more.

mathon
 
You can, but it's look more like :

if(((window_exists(ErrorBox)) || (window_exists(ErrorBox2)))

1. I'd suggest putting it in wherever you see the errors appearing during execution. Step through the code to find the point at which the code halts.

2. Look in the Help file regarding taking a snapshot of the screen, or creating a bitmapped checkpoint.

3. Put into the error handling function a condition to break the loop, increment your test case variable i and start again. You appear to have pulled the test cases into an array in the first instance, is this not the case?

4. In the error handling, where you break the loop have the code exit the function. Again, check the TSL help file for specifics.

I see you are working with WinZip files. These can be awkward to get a good result with. What is the intended purpose of the script? I can infer, but I'll be better able to help you if you tell me what you are trying to achieve.

Thanks
Dave

"Probably the only Test Analyst on Tek-Tips"

Take a look at Forum1393 & sign up if you'd like
 

Exactly the you know the structure of my input file and the rows are read in and saved in an array. For example the testcase numer is saved in the sTC variable.

1) Thats the problem that I no between which lines or better said at which line the two errors occur but I do not know where I have to state the if question to call the trapError function. The programm which is tested could throw exception according to the quality of the input file. Means that the programm should open the file and the first error could occur that the file could not be opened because it is damaged or something else. In that case a window appears with an error message that the file could not be read and so no more action of the test could be excecuted. So I do not exaclty know where I should place this if question..?

2) Okay I looked in the references and found something: I think I have to first settting up a Bitmap Checkpoint in that way:
Tools - General Options; Run - Settings; Select Capture bitmap on verification failure; Select Desktop;
And then in the trapError Message I only have to quote the following statement:
desktop_capture_bitmap(image_name);
How it works when this function is called often - is only the existing bmp-file overwritten or are created more bmp-files, because it would be bad when only one bmp-file is created and this one would be overwritten at any time?
Is that right in that way?

3) With break the loop you mean the do-while loop or? The do-while loop could only be broken when the condition while(sInputValues!=""); is not true anymore, means that I have to set the sInputValues variable to null something like this ?
sInputValues = "";
The problem is how could I increment the sTC variable in an easy manner because the value of this variable looks something like this: [TC 1], [TC 2], etc.

4)So when I don't want to continue with the next testcase but terminate the whole test I only have to quote this codeline?
texit() //this would terminate the test according to the reference

Mathon
 
1. If you know where the error boxes will appear, make sure you trap the error there. From what you've said it looks like you've already trapped the error at the start (file cannot be read)

2. Generally, I would use :
desktop_capture_bitmap(image_name & sTC);
as this would concatenate your test case name onto the image_name used.

3. You could still increment the sTC by adding a line reading sTC = "[TC "&i+1&"]" where i is the current number of the loop. This will allow reentry to the loop at the next test case.

4. Yes.

It looks to me like your intention is to automate the creation of WinZip Self-extracting .exe files. Is this the case?

Dave

"Probably the only Test Analyst on Tek-Tips"

Take a look at Forum1393 & sign up if you'd like
 

Yes that's sub-testcases - the extracting.

1) No it must be in the executeTestCases function or? The startApplication function in the Testrun-script (main script) the startApplication is called and the application is started. Then the input file respectively the rows are read in and the executedTestCase Methode executes the rows respectively the commands in the rows of the input file. Is it not right to place the if-quesion after this statements?:
#load Guimap and set window according to sWindow;

rc = GUI_open(g_sGuifolder & sWindow & ".gui");
rc = GUI_load(g_sGuifolder & sWindow & ".gui");
rc = set_window(sWindow);

Because there the test would set the usually followed window but the window does not appear because an error message window occurs? - the problem is in that case that when the sWindow is not available then test does not continue but an exception occurs that the window cannot be set and the if quesion is not executed in that case. Do you konw what I mean?

2) or I use something like this:
desktop_capture_bitmap(image_name & get_Time);

3)But I alread have this statement:
sTC = substr(sInputValues, 2, length(sInputValues)-2);
//which extracts the testcase from the input file
I do not exactly know how you mean that?

4)I already tried to define such trapError function (I would place it in the Test script - this would be the second script of my posting:

public function trapErrorTerminate()
{

texit();

}

public function trapErrorContinue()
{

desktop_capture_bitmap(image_name & get_Time);

//how could i jump back in the executeTestCases with the next testCase?

mathon
 
1. turn the rc=set_window into an if condition. If the rc != E_OK then call the error trap function.

2. Sure.

3. Your statement takes the input from the file (which reads [TC 1] for example) and cuts it down to TC 1. It then sets this value to sTC. My version simply incremented the number at the end. Though you should remove the concatenated [ and ]s from the statement.

4. Insert a call to the function with the amended sTC as a parameter.

Why do you need to do this? It's not really a test you would run repetitively, so why automate? It isn't efficient to automate unless the test is repeatable and needs repeated a lot.

Dave

"Probably the only Test Analyst on Tek-Tips"

Take a look at Forum1393 & sign up if you'd like
 

Thats stress test which should indicate the reliability of some systems but it is only a sub-test in our department.

1) I already tried this in that way:
if((rc=set_window)!=E_OK)
....//execute this code but this code will not be executed when the set_window operation could not be executed successfully. Have I still did something wrong?


2)I always get an error when I use the texit() function only like this:
texit();

3) So you mean I should insert after this statement
sTC = substr(sInputValues, 2,length(sInputValues)-2);
sTC = "[TC "&i+1&"]";
Thus I do not need the first line any more?

4)In this function:

public function trapErrorContinue()
{

desktop_capture_bitmap(image_name & get_Time);

}

You said that I need to call the function with the incremented sTC? but the executeTestCases needs as parameter a String respectively the rows of the input file. Have I understand something wrong?


Sorry for your inconvenience but this is one of my first projects with WR.



 
1. You need the set_window condition in full :

if((rc=set_window(window_name, timeout))!=E_OK)
{
blah blah
}
else
{
blah blah
}

2. Check the syntax - use the help files.

3. Your statement sets sTC to the current test case. My statement increments the number to move it onto the next test case. If you pass sTC back after incrementing it, the next test case will be processed. You only need to increment the code if you are continuing from a fail, so that is where this code should go.

4. Your function TrapErrorContinue should contain code to:

1. Capture the screenshot
2. Set up the next test case (increment the case)
3. Return to the main program and pick up the next test item for processing.

Cheers
Dave

Cheers,
Dave

Probably the only Test Analyst on Tek-Tips

animadverto vos in Abyssus!

Take a look at Forum1393 & sign up if you'd like
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top