<?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>hamang.net &#187; Testing</title>
	<atom:link href="http://hamang.net/tag/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://hamang.net</link>
	<description>- the everyday life</description>
	<lastBuildDate>Wed, 10 Feb 2010 09:52:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Working with WebTests</title>
		<link>http://hamang.net/2006/09/06/working-with-webtests/</link>
		<comments>http://hamang.net/2006/09/06/working-with-webtests/#comments</comments>
		<pubDate>Wed, 06 Sep 2006 09:36:39 +0000</pubDate>
		<dc:creator>Knut Hamang</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I have found very few articles on how to make customized WebTest with Visual Studio 2005 Team Edition for Testers or Visual Studio 2005 Team Suite. However, I bumped into this great article that show some of the more advanced techniques for authoring advanced and custom WebTests.
The article had excatly what I needed. My goal is to [...]]]></description>
			<content:encoded><![CDATA[<p>I have found very few articles on how to make customized WebTest with Visual Studio 2005 Team Edition for Testers or Visual Studio 2005 Team Suite. <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/WTAuthDebug.asp" target="_blank">However, I bumped into this great article that show some of the more advanced techniques for authoring advanced and custom WebTests</a>.</p>
<p>The article had excatly what I needed. My goal is to make a crawler that fetches most of the URL&#039;s on a website. This is useful for testing resources on the server when content is cached. Hitting the same page over and over again is not useful for testing memory resources. The test must fill the cache to it&#039;s limits and then we can see what performance the users will experience.</p>
<p>If the article is removed (or the server is down), here is the example code I used. I have of course modified it (removed links to external pages, javascripts, CSS/Images, etc.) to match the site I am running the test against, but the core code is the same.<br />
<code><br />
</code> <!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 \cf1 using\cf0  System;\par ??\cf1 using\cf0  System.Collections.Generic;\par ??\cf1 using\cf0  System.Text;\par ??\cf1 using\cf0  Microsoft.VisualStudio.TestTools.WebTesting;\par ??\cf1 public\cf0  \cf1 class\cf0  \cf4 LoopingCoded\cf0  : WebTest\par ??\{\par ??    \cf1 public\cf0  LoopingCoded()\par ??    \{\par ??    \}\par ??    \cf1 public\cf0  \cf1 override\cf0  \cf4 IEnumerator\cf0 &lt;WebTestRequest&gt; GetRequestEnumerator()\par ??    \{\par ??        \cf5 // Issue a search for the term "Microsoft"\par ??\cf0         WebTestRequest request7 = \cf1 new\cf0  WebTestRequest(\cf6 "http://testserver/website/Search.aspx"\cf0 );\par ??        request7.ThinkTime = 20;\par ??        request7.Method = \cf6 "POST"\cf0 ;\par ??        FormPostHttpBody request7Body = \cf1 new\cf0  FormPostHttpBody();\par ??        request7Body.FormPostParameters.Add(\cf6 "txtSearch"\cf0 , \cf6 "Microsoft"\cf0 );\par ??        request7.Body = request7Body;\par ??        \cf1 yield\cf0  \cf1 return\cf0  request7;\par ??        \cf5 // Loop through each anchor tag in the search result and issue a request to each tag's target url (href)\par ??\cf0         \cf1 foreach\cf0  (HtmlTag tag \cf1 in\cf0  \cf1 this\cf0 .LastResponse.HtmlDocument.GetFilteredHtmlTags(\cf6 "a"\cf0 ))\par ??        \{\par ??            WebTestRequest loopRequest = \cf1 new\cf0  WebTestRequest(tag.GetAttributeValueAsString(\cf6 "href"\cf0 ));\par ??            \cf1 yield\cf0  \cf1 return\cf0  loopRequest;\par ??        \}\par ??    \}\par ??\}} --></p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black;">
<p style="margin: 0px;"><span style="color: blue;">using</span> System;</p>
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Collections.Generic;</p>
<p style="margin: 0px;"><span style="color: blue;">using</span> System.Text;</p>
<p style="margin: 0px;"><span style="color: blue;">using</span> Microsoft.VisualStudio.TestTools.WebTesting;</p>
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">LoopingCoded</span> : WebTest</p>
<p style="margin: 0px;">{</p>
<p style="margin: 0px; padding-left: 30px;"><span style="color: blue;">public</span> LoopingCoded()</p>
<p style="margin: 0px; padding-left: 30px;">{</p>
<p style="margin: 0px; padding-left: 30px;">}</p>
<p style="margin: 0px; padding-left: 30px;"><span style="color: blue;">public</span> <span style="color: blue;">override</span> <span style="color: #2b91af;">IEnumerator</span>&lt;WebTestRequest&gt; GetRequestEnumerator()</p>
<p style="margin: 0px; padding-left: 30px;">{</p>
<p style="margin: 0px; padding-left: 60px;"><span style="color: green;">// Issue a search for the term &#034;Microsoft&#034;</span></p>
<p style="margin: 0px; padding-left: 60px;">WebTestRequest request7 = <span style="color: blue;">new</span> WebTestRequest(<span style="color: #a31515;">&#034;http://testserver/website/Search.aspx&#034;</span>);</p>
<p style="margin: 0px; padding-left: 60px;">request7.ThinkTime = 20;</p>
<p style="margin: 0px; padding-left: 60px;">request7.Method = <span style="color: #a31515;">&#034;POST&#034;</span>;</p>
<p style="margin: 0px; padding-left: 60px;">FormPostHttpBody request7Body = <span style="color: blue;">new</span> FormPostHttpBody();</p>
<p style="margin: 0px; padding-left: 60px;">request7Body.FormPostParameters.Add(<span style="color: #a31515;">&#034;txtSearch&#034;</span>, <span style="color: #a31515;">&#034;Microsoft&#034;</span>);</p>
<p style="margin: 0px; padding-left: 60px;">request7.Body = request7Body;</p>
<p style="margin: 0px; padding-left: 60px;"><span style="color: blue;">yield</span> <span style="color: blue;">return</span> request7;</p>
<p style="margin: 0px; padding-left: 60px;"><span style="color: green;">// Loop through each anchor tag in the search result and issue a request to each tag&#039;s target url (href)</span></p>
<p style="margin: 0px; padding-left: 60px;"><span style="color: blue;">foreach</span> (HtmlTag tag <span style="color: blue;">in</span> <span style="color: blue;">this</span>.LastResponse.HtmlDocument.GetFilteredHtmlTags(<span style="color: #a31515;">&#034;a&#034;</span>))</p>
<p style="margin: 0px; padding-left: 60px;">{</p>
<p style="margin: 0px; padding-left: 90px;">WebTestRequest loopRequest = <span style="color: blue;">new</span> WebTestRequest(tag.GetAttributeValueAsString(<span style="color: #a31515;">&#034;href&#034;</span>));</p>
<p style="margin: 0px; padding-left: 90px;"><span style="color: blue;">yield</span> <span style="color: blue;">return</span> loopRequest;</p>
<p style="margin: 0px; padding-left: 60px;">}</p>
<p style="margin: 0px; padding-left: 30px;">}</p>
<p style="margin: 0px;">}</p>
</div>
<p><code><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://hamang.net/2006/09/06/working-with-webtests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
