WebDocument Navigate - HTTP Response Code

Class library usage, coding and language questions.
johnzer
Posts: 16
Joined: Thu Aug 18, 2016 9:27 pm

WebDocument Navigate - HTTP Response Code

Post by johnzer » Tue Nov 08, 2016 9:17 pm

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!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3914
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: WebDocument Navigate - HTTP Response Code

Post by odklizec » Tue Nov 08, 2016 9:28 pm

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
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

johnzer
Posts: 16
Joined: Thu Aug 18, 2016 9:27 pm

Re: WebDocument Navigate - HTTP Response Code

Post by johnzer » Tue Nov 08, 2016 9:48 pm

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();

User avatar
RobinHood42
Posts: 238
Joined: Fri Jan 09, 2015 3:24 pm

Re: WebDocument Navigate - HTTP Response Code

Post by RobinHood42 » Fri Nov 11, 2016 2:08 pm

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