Highlighted
Absent Member.. Absent Member..
Absent Member..
3134 views

How to get Error Codes in VuGen Script?

Jump to solution

Hi,

 

is there a function in VuGen, which can retrieve error codes like "Error -27798" in a case of a functions failure or is there a function, who give me the corresponding error string?

 

Thank you for your help in advance.

 

Best regards,

hs

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

Re: How to get Error Codes in VuGen Script?

Jump to solution

Ok, in reading through the LR documentation, help files and function references nothing is jumping out at me as a built in feature inside LR to do this. If anyone else has a way I would love to hear it too, please post it.

 

That being said, I've come up with a work around for you. This is a total cheat and you 'll need to modify this to work from the controller when you push your script to mutiple threads on your generators. I've tested this in the Virtual User Generator, but not running from the controller.

 

Paste this custom function into your script, after the vuser_init { } section. change the section for tempFile to the directory where your script is saved, then call it from your script just after the action causing the error:

// This function is used to open the script's output file and check for 
// a string that indicates there's an error code:
// 		'Error -'
nb_output_read_file(){

	long fileStream;     // set variables for the function
	char tempFile[64];
	char line[256];

	int x = 0; // set our loop marker

	// set the location of the vuser output file
	sprintf(tempFile, "C:\\myLRscripts\\capture_error_code\\output.txt");  

	fileStream = fopen(tempFile, "r"); // open the file for reading

	// loop through the output.txt file looking for the string 'Error -'
	// which should indicate an error code
	while((fgets(line, 256, fileStream) != NULL) && x==0 ){

		// if the current line contains an error code write the lin
		// to the log
		if ( strstr(line, "Error -") != 0) {
			lr_output_message("line : %s", line);
			x = 1; // once the error is found set the marker, kill the loop
		}
	} 

	fclose(fileStream);  // close the file
}

 

For this to work you'll need to change your script's runtime settings to this:

  Run-time Settings > Miscellaneous > Error Handling | check 'Continue on error'

This is a global setting for all the code in your script, so if you use this setting you'll need to write your own error handling for everything.

 

Alternatively you could change this setting dynamically just for the part you need to have it continue on error:

    lr_continue_on_error(LR_ON_ERROR_CONTINUE);

Then, afterwards switch it back:

    lr_continue_on_error(LR_ON_ERROR_NO_OPTIONS);

 

The cheat is this, as long as you have logging turned on (run-time settings) when you run the script LR writes the file 'output.txt' to the script directory. So, as the script is running you access this file and read from it.

 

I'll leave whatever string manipulation on the error line up to you and you'll need to find where the multiple vusers are writing this output file during the controller playback if you want to use this in a scenario, but this does allow you to read the error codes of a LR error during script playback.

 

Again, if anyone has a much simpler way of capturing the error codes please post it.

 

SIDE NOTE:

While looking into this I did a way to capture returned HTTP codes. I know that isn't what you asked for here, but if you're curious calling web_get_int_property will grab the previous calls HTTP reutrn code:

int HttpRetCode;

web_url("... web call ...");

HttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE );
lr_output_message("HttpRetCode : %d", HttpRetCode);

 

 

View solution in original post

0 Likes
10 Replies
Highlighted
Absent Member.
Absent Member.

Re: How to get Error Codes in VuGen Script?

Jump to solution

Hi Hs,

 

You want to retrieve the error message? Once it comes up it normally stops execution of the script. Are you looking to save the error message somewhere.

 

Regards,

Mario M.

HP LR/PC Support

If you are customer you can try posting on our internal forums for more personalized support.

LoadRunner:
http://h30499.www3.hp.com/t5/LoadRunner-Support-Customer/bd-p/loadrunner-support-customer-forum

Performance Center:
http://h30499.www3.hp.com/t5/Performance-Center-Support/bd-p/performance-center-support-customer

How to:
http://www.youtube.com/watch?v=4ChlysWupWM

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.
0 Likes
Highlighted
Absent Member.. Absent Member..
Absent Member..

Re: How to get Error Codes in VuGen Script?

Jump to solution

Hmm...ok. Well, after execution. I thought, if e.g. a "web_url"-function fails, the error will be clear and i can catch this error in script. I want to cath this error and work with it. No chance?

0 Likes
Highlighted
Absent Member.
Absent Member.

Re: How to get Error Codes in VuGen Script?

Jump to solution

The errors are logged on the replay log, and if they are not warning, normally the script will stop execution when the error comes up and you can see it and work with it.

 

Like that error you mentioned, Error -27798, if you highlight it and hit F1 it will give you a description and possible things to try and work with it.

 

Regards,

Mario M.

HP LR/PC Support

If you are customer you can try posting on our internal forums for more personalized support.

LoadRunner:
http://h30499.www3.hp.com/t5/LoadRunner-Support-Customer/bd-p/loadrunner-support-customer-forum

Performance Center:
http://h30499.www3.hp.com/t5/Performance-Center-Support/bd-p/performance-center-support-customer

How to:
http://www.youtube.com/watch?v=4ChlysWupWM

If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: How to get Error Codes in VuGen Script?

Jump to solution

You could add some error handling code into your script. Rather than capture the specific error code, each of the LR functions have a return value, usually '0' (LR_PASS) or '1' (LR_FAIL), so you can capture this returned int and write in code to handle a failure if that's what you're looking for.

 

int x;

lr_start_transaction("1_abc_request");
x = web_url("www.abc.com", "URL=http://www.abc.com/", "TargetFrame=", "TargetBrowser=My Browser", "Resource=0", "RecContentType=text/html", "Snapshot=t1.inf", "Mode=HTML", LAST ); if (x != LR_PASS){ lr_error_message("URL not reached!"); lr_end_transaction("1_abc_request", LR_FAIL); } else { lr_output_message("URL success!"); lr_end_transaction("1_abc_request", LR_AUTO); }

 

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

Re: How to get Error Codes in VuGen Script?

Jump to solution

@Nathan: I know these custom error messages, but the problem is, that i will loose important informationen like the error messages from BAC, which have sometimes more detailed information to the error.

So, i want to catch the error from bac during the execution of the script and extend it with custom error messages of my own.

As i see it, there i no chance... 😞

Nonetheless, thank your for your help!

 

best regards

hs

 

 

0 Likes
Highlighted
Absent Member.
Absent Member.

Re: How to get Error Codes in VuGen Script?

Jump to solution

Ok, in reading through the LR documentation, help files and function references nothing is jumping out at me as a built in feature inside LR to do this. If anyone else has a way I would love to hear it too, please post it.

 

That being said, I've come up with a work around for you. This is a total cheat and you 'll need to modify this to work from the controller when you push your script to mutiple threads on your generators. I've tested this in the Virtual User Generator, but not running from the controller.

 

Paste this custom function into your script, after the vuser_init { } section. change the section for tempFile to the directory where your script is saved, then call it from your script just after the action causing the error:

// This function is used to open the script's output file and check for 
// a string that indicates there's an error code:
// 		'Error -'
nb_output_read_file(){

	long fileStream;     // set variables for the function
	char tempFile[64];
	char line[256];

	int x = 0; // set our loop marker

	// set the location of the vuser output file
	sprintf(tempFile, "C:\\myLRscripts\\capture_error_code\\output.txt");  

	fileStream = fopen(tempFile, "r"); // open the file for reading

	// loop through the output.txt file looking for the string 'Error -'
	// which should indicate an error code
	while((fgets(line, 256, fileStream) != NULL) && x==0 ){

		// if the current line contains an error code write the lin
		// to the log
		if ( strstr(line, "Error -") != 0) {
			lr_output_message("line : %s", line);
			x = 1; // once the error is found set the marker, kill the loop
		}
	} 

	fclose(fileStream);  // close the file
}

 

For this to work you'll need to change your script's runtime settings to this:

  Run-time Settings > Miscellaneous > Error Handling | check 'Continue on error'

This is a global setting for all the code in your script, so if you use this setting you'll need to write your own error handling for everything.

 

Alternatively you could change this setting dynamically just for the part you need to have it continue on error:

    lr_continue_on_error(LR_ON_ERROR_CONTINUE);

Then, afterwards switch it back:

    lr_continue_on_error(LR_ON_ERROR_NO_OPTIONS);

 

The cheat is this, as long as you have logging turned on (run-time settings) when you run the script LR writes the file 'output.txt' to the script directory. So, as the script is running you access this file and read from it.

 

I'll leave whatever string manipulation on the error line up to you and you'll need to find where the multiple vusers are writing this output file during the controller playback if you want to use this in a scenario, but this does allow you to read the error codes of a LR error during script playback.

 

Again, if anyone has a much simpler way of capturing the error codes please post it.

 

SIDE NOTE:

While looking into this I did a way to capture returned HTTP codes. I know that isn't what you asked for here, but if you're curious calling web_get_int_property will grab the previous calls HTTP reutrn code:

int HttpRetCode;

web_url("... web call ...");

HttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE );
lr_output_message("HttpRetCode : %d", HttpRetCode);

 

 

View solution in original post

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

Re: How to get Error Codes in VuGen Script?

Jump to solution

Hey Nathan,

 

thank you for your effort. The web part looks good - thank you for this hint.

 

The "workaround" have to be before the vuser_end, so that i can read it during the script execution. Will it work in this way? That would be great. I will give it a try.

 

best regards,

 

hs

0 Likes
Highlighted
Absent Member.
Absent Member.

Re: How to get Error Codes in VuGen Script?

Jump to solution

Yes, it'll work during the script playbeck. The script is actively writing to Output.txt as it executes (again, as long as logging is turned on in your Run-time settings), so you just read from it and you'll be able to grab anything written out up to that point.

 

Just keep in mind that the act of reading from the log file causes that very event to write to the log. My function kills the loop reading from the file once the error code is found to avoid an infinite loop.

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

Re: How to get Error Codes in VuGen Script?

Jump to solution

Thank you. I will use it. 😄

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Re: How to get Error Codes in VuGen Script?

Jump to solution

Hi Nathan,

It is capturing more errors, like 'Error -26366: "Text=HTTP/1.1 200 OK" not found for web_reg_find '

Is there no way to capture it without using file code. I have the same requirement where I have to catpure all kind of connection related error (connection_shutdown, connection timed out etc) with exact timestamp when it occured. I already have many code return to manipulate such errors and insert them into influxDB and do not want to add more bulky code. 

 

Thanks,

Ritesh.

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.