Highlighted
Respected Contributor.
Respected Contributor.
998 views

Capturing HTTP Response Codes in Truclient?

I have been searching for hours trying to find a way to capture HTML navigation response codes in Truclient, and the only posts I can find on this forum are from 2013 indicating the functionality had not been implemented at that time.

In the HTTP / HTML client I can leverage XMLHttpRequest, but that does not appear to be valid in TruClient as the below code fails with an "XMLHttpRequest is not defined" error message:

var httpOpen;
httpOpen = new XMLHttpRequest();
httpOpen.open("HEAD", myURL, false);
httpOpen.send();

//If the opened page returns a 404 error code then retrieve a new page URL value, else exit FOR Loop
if (httpOpen.status == 404) {
    myURL = "http://" + LR.getParam("host") + LR.getParam("PDP_Link");
    lr_output_message("Url is: %s",myURL);
    } else {
        pageFound = "true";
   }
}

I need to be able to trap page response error codes and (in the case of a 404 or 500 return) re-try the navigate step up to 5 times. Any way to do this if the above doesn't work in TruClient?

 

0 Likes
3 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Capturing HTTP Response Codes in Truclient?

Hi,

Why should you iniate the http request on your own using JavaScript code? This is not supported by TruClient but regardless the browser will trigger those requests for you as a result of the oeprations done in the UI level.

There is a way to create a listener for http responses in TruClient Firefox. It is not available in TruClient IE. It requires deep familiarity with Firefox API's and since Firefox keep on changing their API's I would not advise implementing it this way.

I suggest using the following approach

1. Add a "Wait for Object" Step after any step that triggers a navigation and might fail

2.  Add a "Catch Error" step after the wait for object. 

3. Inside the Catch Error add Reload step.

Whenever 404 or 500 will appear the wait for object step will fail and catch step will trigger the page reload

Hope it helps

Regards,

Shlomi

 

 

 

Highlighted
Respected Contributor.
Respected Contributor.

Re: Capturing HTTP Response Codes in Truclient?

Thanks! I can't find any documentation on how to set the "Catch Error" step to trap the 404 and / or 500 errors, the references in the LR help file only indicate how to create the "catch Error" step, not how to actually use it to trap a specific error.

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Capturing HTTP Response Codes in Truclient?

The "Catch Error" step does not capture http errors, i suggested adding a "Wait for Object" step in order for it to fail and then the "Catch Error" will capture it.

Good Luck

Shlomi

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.