Page 1 of 1

WebDocument Navigate - HTTP Response Code

Posted: Tue Nov 08, 2016 9:17 pm
by johnzer
Hey all,

I'm testing a web application and need to make sure that navigating to a URL returns a response code of 200.

How could I get the HTTP response code after navigating to a new page? I would have to do this across several browsers (IE, Chrome, Firefox, Safari).

Thanks!

Re: WebDocument Navigate - HTTP Response Code

Posted: Tue Nov 08, 2016 9:28 pm
by odklizec
Hi,

There is no built-in function/action to achieve this, but since Ranorex is built on .Net, you can do almost anything you want with it. Check for example this post...
http://www.ranorex.com/forum/get-the-er ... tml#p16510

Re: WebDocument Navigate - HTTP Response Code

Posted: Tue Nov 08, 2016 9:48 pm
by johnzer
odklizec wrote:Hi,

There is no built-in function/action to achieve this, but since Ranorex is built on .Net, you can do almost anything you want with it. Check for example this post...
http://www.ranorex.com/forum/get-the-er ... tml#p16510
Thanks for the reply!

I'm currently using this to check the status code of the HTTP request, but I'm having to use the Navigate() method as well.

It seems that creating a WebRequest object to the URI I need doesn't actually cause the browser to navigate to that URL. Am I doing this wrong?'

My code below

Code: Select all

if(Browser == "chrome")
        	{
        		BrowserArgs = "--args --user-data-dir --force-renderer-accessibility";
        	} else
        	{
        		BrowserArgs = "";
        	}
        	
        	Host.Local.OpenBrowser(URL, Browser, BrowserArgs, KillExisting, Maximized, ClearCache, false, ClearCookies);
        	
        	HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(URL);
        	
        	HttpWebResponse httpRes = (HttpWebResponse)httpReq.GetResponse();
        	
        	if((int) httpRes.StatusCode != 200)
        	{
        		Report.Log(ReportLevel.Warn, "Request to page returned status " + httpRes.StatusCode.ToString());
        	} else
        	{
        		Report.Log(ReportLevel.Success, "Request to page returned status " + httpRes.StatusCode.ToString());
        	}
        	
        	httpRes.Close();

Re: WebDocument Navigate - HTTP Response Code

Posted: Fri Nov 11, 2016 2:08 pm
by RobinHood42
Hi

I'm unfortunately not sure what's the problem here since your code sample is just working fine on my side.
May I ask you if you could provide more information about the situation?

Also, since this code is regular .NET code and not related to Ranorex itself, I assume that the Ranorex Support Team cannot provide any solution for your problem.

Cheers,
Robin