Jump to content
WAPT Forum
Sign in to follow this  
Guest Leigh Smith

Accessing the URL of the last request from JavaScript

Recommended Posts

Guest Leigh Smith

Is there a way to get the URL of the last server request in JavaScript code?

 

I can use

 

context.document

 

to access the HTML document for the request but when I tried

 

context.document.URL

 

the url is always set to "about:blank". In a browser I would use "location.href" but this obviously won't work in WAPT.

 

Is there another internal WAPT variable that contains the URL? I've had a look in the help and on the forum and couldn't find anything obvious.

 

The script I am writing saves some of the images requested to external files so that we can analyse them after the test run. This bit works perfectly. I want to access the URL so I can save it in an external log file to identify the source of the image.

 

Thanks in advance.

Leigh

Share this post


Link to post
Share on other sites
Guest Leigh Smith

Hi Sergei,

 

Thanks for your reply and for the updated version of WAPT. Being able to access the Request Header and Body should enable me to get the URL as you said so I'm happy with this solution.

 

However, I've downloaded the new version of WAPT above and tried accessing the requestHeader property from JavaScript but the header seems to be incomplete. It is missing the first line containing the URL that I'm trying to access!

 

I wrote some code to log the header to see if it was working correctly.

 

var headerStr = context.requestHeader.split("\r\n").join(",");

log.message(headerStr);

 

This logs the following:

Accept: text/html, */*,Accept-Language: en-us, *,Accept-Encoding: gzip, deflate,Pragma: no-cache,User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0),Host: meltest1,Referer: http://meltest1/LeighEntTest/Default.html

 

The Request Header shown in the Log in the WAPT Pro UI is:

GET /LeighEntTest/Default.html HTTP/1.1

Accept: text/html, */*

Accept-Language: en-us, *

Accept-Encoding: gzip, deflate

Pragma: no-cache

User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)

Host: meltest1

 

So the "GET" line appears to be missing from the context.requestHeader property.

 

Am I doing something wrong here? I've run the same code on the Response Header to test it and it logs the complete header. I also wrote a regular expression that would pull out the URL from the "GET" line. When I tested this on a complete header string it worked as expected but when I tested it on the context.requestHeader it didn't find the GET line.

 

Thanks,

Leigh

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...