<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vidar's Musings &#187; statuscode</title>
	<atom:link href="http://www.kongsli.net/nblog/tag/statuscode/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kongsli.net/nblog</link>
	<description>Deep thoughts on shallow topics</description>
	<lastBuildDate>Fri, 27 Jan 2012 07:36:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Internet Explorer automation/Watin: catching navigation error codes</title>
		<link>http://www.kongsli.net/nblog/2008/07/08/internet-explorer-automationwatin-catching-navigation-error-codes/</link>
		<comments>http://www.kongsli.net/nblog/2008/07/08/internet-explorer-automationwatin-catching-navigation-error-codes/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 12:20:02 +0000</pubDate>
		<dc:creator>vidarkongsli</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[Software testing]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[internetexplorer]]></category>
		<category><![CDATA[statuscode]]></category>
		<category><![CDATA[watin]]></category>
		<category><![CDATA[web test]]></category>

		<guid isPermaLink="false">http://www.kongsli.net/nblog/?p=64</guid>
		<description><![CDATA[One question have troubled me for some time when automating Internet Explorer (actually, I am doing web testing with Watin): how to test for HTTP status codes. Finally, I figured out how to do this. The lies in an event that the InternetExplorer object raises when navigation is unsuccessful. I ended up with writing a [...]]]></description>
			<content:encoded><![CDATA[<p>One question have troubled me for some time when automating Internet Explorer (actually, I am doing web testing with Watin): how to test for HTTP status codes. Finally, I figured out how to do this. The lies in an event that the InternetExplorer object raises when navigation is unsuccessful.</p>

<p>I ended up with writing a C# helper class:
<pre>using System.Net;</pre>
<pre>using WatiN.Core;</pre>
<pre>using SHDocVw;</pre>
<pre>using Microsoft.VisualStudio.TestTools.UnitTesting;</pre>
<pre>using System.Globalization;</pre>
<pre>namespace Test</pre>
<pre>{</pre>
<pre>    public class NavigationObserver</pre>
<pre>    {</pre>
<pre>        private HttpStatusCode _statusCode;</pre>
<pre>        public NavigationObserver(IE ie)</pre>
<pre>        {</pre>
<pre>            InternetExplorer internetExplorer = (InternetExplorer)ie.InternetExplorer;</pre>
<pre>            internetExplorer.NavigateError += new DWebBrowserEvents2_NavigateErrorEventHandler(IeNavigateError);</pre>
<pre>        }</pre>
<pre>        public void ShouldHave(HttpStatusCode expectedStatusCode)</pre>
<pre>        {</pre>
<pre>            if (!_statusCode.Equals(expectedStatusCode))</pre>
<pre>            {</pre>
<pre>                Assert.Fail(string.Format(CultureInfo.InvariantCulture, "Wrong status code. Expected {0}, but was {1}",</pre>
<pre>                    expectedStatusCode, _statusCode));</pre>
<pre>            }</pre>
<pre>        }</pre>
<pre>        private void IeNavigateError(object pDisp, ref object URL, ref object Frame, ref object StatusCode, ref bool Cancel)</pre>
<pre>        {</pre>
<pre>            _statusCode = (HttpStatusCode)StatusCode;</pre>
<pre>        }</pre>
<pre>    }</pre>
<pre>}</pre>
Note that I use Visual Studio test runner to run my web tests. Then, I can use this in my test:
<pre>using (IE ie = new IE())</pre>
<pre>{</pre>
<pre>    NavigationObserver observer = new NavigationObserver(ie);</pre>
<pre>    ie.GoTo("http://some.where.com");</pre>
<pre>    observer.ShouldHave(HttpStatusCode.NotFound);</pre>
<pre>}</pre></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.kongsli.net%2Fnblog%2F2008%2F07%2F08%2Finternet-explorer-automationwatin-catching-navigation-error-codes%2F&amp;title=Internet%20Explorer%20automation%2FWatin%3A%20catching%20navigation%20error%20codes" id="wpa2a_2"><img src="http://www.kongsli.net/nblog/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.kongsli.net/nblog/2008/07/08/internet-explorer-automationwatin-catching-navigation-error-codes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

