Highlighted
Absent Member.. Absent Member..
Absent Member..
551 views

Error Handling - Fail Script on Find

I have been plagued by this problem for quite some time - even though I want my script to stop and exit on error, what actually happens is that the same transaction keeps executing over and over when it find the error string.

So, I have:

lr_start_transaction("Tx1");

web_reg_find("Text/IC=An unexpected error has occurred.","Fail=Found","ID=FE unexpected error", LAST);

web_submit_data("moduleDispatcher.do", ...;

lr_end_transaction("Tx1");

Also, my runtime settings for Error Handling does not have "Continue on error" selected.

So when this script executes in the Controller, and it encounters "An unexpected error has occurred", the vuser just rapidly resubmits the web_submit_data in an infinite loop until I stop execution.

What am I missing here?
0 Likes
5 Replies
Highlighted
Absent Member.
Absent Member.

Re: Error Handling - Fail Script on Find

HI james...

Web_reg_find works after the web_submit happens try this code hope it will help you.

It is a general code customize it acc to your need.


web_reg_find("Text=Web",
"SaveCount=SaveCount",
"Search=All",
LAST);

lr_start_transaction("Txn1");


web_submit_data("WBMain.aspx_2",
"Action=http://{P_URL}/web.aspx",
"Method=POST",
"RecContentType=text/html",
"Referer=http://{P_URL}/web.aspx",
"Snapshot=t8.inf",
"Mode=HTTP",




if(atoi(lr_eval_string("{SaveCount}"))==0)
{
lr_error_message("%s", lr_eval_string("Trancaction "));
lr_end_transaction("Txn1", LR_FAIL);
lr_exit( LR_EXIT_ITERATION_AND_CONTINUE,LR_FAIL );
}



lr_end_transaction("Txn1",LR_PASS);
0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: Error Handling - Fail Script on Find

As Praveen says use the SaveCount but you can also do your check like this:

if(strcmp(lr_eval_string("{SaveCount}"), "0") == 0)
{
lr_end_transaction("Txn1", LR_FAIL);
lr_error_message("%s", lr_eval_string("Trancaction "));
lr_exit( LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
}
else
{
lr_end_transaction("Txn1", LR_PASS);
}

Alan

0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: Error Handling - Fail Script on Find

Excellent. Only one change, because I want my script to exit:

lr_exit( LR_EXIT_VUSER, LR_FAIL);

Now, according to the documentation, I shouldn't need this. I quote the help for web_reg_find:

"Example 3

In the following example, web_reg_find searches for the text string "Error." If the string is found, it fails and the script execution stops.

web_reg_find("Text/IC=Error", "Fail=Found", LAST);

web_url("Step", "URL=...", LAST);"

So, what we are saying here is that either the 1. code is not working as documented, or 2. documentation is wrong. Right?
0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: Error Handling - Fail Script on Find

I think that the statement in Ex 3 is wrong. Using Fail= just sets the success criteria for the web_reg_find. The description of Fail in the Function reference says nothing about stopping the execution just failing the check.

I have used the SaveCount method for years. I know the reason that I started using it was that the return code is always success so I could not do like:

int rc;

rc = web_reg_find(....

if(!rc)....

I also see that since you would be looking for matches to "error" that you would also need to use != 0 instead in the supplied code. My mistake.

Alan
0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: Error Handling - Fail Script on Find

I had thought that as well. However, I did see that when I used web_global_verification, the vuser would fail and exit, though not in all cases.

I find LR error handling to be very random.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.