<?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>Altentee &#187; Performance &#38; Test Automation Experts &#187; watir</title>
	<atom:link href="http://altentee.com/tag/watir/feed/" rel="self" type="application/rss+xml" />
	<link>http://altentee.com</link>
	<description>Performance and Test Automation Experts</description>
	<lastBuildDate>Sat, 12 Jun 2010 00:35:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Authenticating Proxy with Webdriver and Watir</title>
		<link>http://altentee.com/2010/authenticating-proxy-with-webdriver-and-watir/</link>
		<comments>http://altentee.com/2010/authenticating-proxy-with-webdriver-and-watir/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 00:31:43 +0000</pubDate>
		<dc:creator>Tim Koopmans</dc:creator>
				<category><![CDATA[Altentee]]></category>
		<category><![CDATA[watir]]></category>
		<category><![CDATA[webdriver]]></category>

		<guid isPermaLink="false">http://altentee.com/?p=927</guid>
		<description><![CDATA[<p>A question came up on stack overflow about how to route Watir through an authenticating proxy within your script.</p>
<p>The problem here is that you cannot auto authenticate to a proxy server using Chrome &#8211;proxy-server=my.proxy.com:3128 or using Firefox.</p>
<p>Chrome will always prompt you for a user name and password on an authenticating proxy when it starts up [...]]]></description>
			<content:encoded><![CDATA[<p>A question came up on stack overflow about how to <a href="http://stackoverflow.com/questions/2970777/how-do-i-route-watir-through-a-proxy-pragmatically">route Watir through an authenticating proxy within your script</a>.</p>
<p>The problem here is that you cannot auto authenticate to a proxy server using Chrome &#8211;proxy-server=my.proxy.com:3128 or using Firefox.</p>
<p>Chrome will always prompt you for a user name and password on an authenticating proxy when it starts up (via Webdriver or manually). Firefox will not prompt (when launched via WebDriver) and will silently fail.</p>
<p>I *almost* got this to work by modifying headers on the fly with a Firefox add on (<a href="https://addons.mozilla.org/en-US/firefox/addon/967/">Modify Headers</a>). Basic authentication is just base-64 encoded so you can force each request to authorize itself by modifying the Proxy-Authorization request header e.g.:<br />
<code>Proxy-Authorization	Basic asHJksaKHs87akhkjah7</code></p>
<p>However whilst this works for manually launched instances of Firefox, Webdriver launched instances would complain that the add on is not compatible with FF3.6.3 and so once again would fail. The other problem with this approach is that I couldn&#8217;t find a similar plugin for Chrome.</p>
<p>Eventually I gave in and went with a slightly more complicated workaround. That is, chaining an authenticated proxy (with squid) running on localhost with a cache_peer relationship to the authenticated proxy running out there  on the &#8216;tubes&#8217;. I had thought about using Webrick as a proxy (<a href="http://90kts.com/2008/httpwatch-a-free-alternative-using-ruby/">as per previous posts</a>) but lack of SSL support is a gotcha for me. Squid seemed most appropriate in this case:</p>
<p>To install squid from source:<br />
<code>cd /opt/src<br />
sudo curl -O http://www.squid-cache.org/Versions/v2/2.7/squid-2.7.STABLE9.tar.gz<br />
sudo tar xjf squid-2.7.STABLE9.tar.gz<br />
cd squid-2.7.STABLE9<br />
# I wanted SSL support for this<br />
./configure --enable-ssl<br />
make<br />
sudo make install</code></p>
<p>Edit the squid.conf (location is normally /etc/squid/squid.conf on linux):<br />
<code>sudo vim /usr/local/squid/etc/squid.conf</code></p>
<p><code># Don't want to run squid as root<br />
#  TAG: cache_effective_user<br />
cache_effective_user nobody<br />
#  TAG: cache_effective_group<br />
cache_effective_group wheel<br />
# Point this proxy to a peer cache, and provide the logon credentials<br />
#  TAG: cache_peer<br />
cache_peer proxy.altentee.com parent 3128 0 default no-query login=username:mypassword<br />
never_direct allow all<br />
# Allow access from my local private network<br />
#  TAG: cache_peer<br />
acl localnet src 10.0.0.0/0</code></p>
<p>Save changes and change ownership as appropriate:<br />
<code>sudo chown -R nobody:wheel /usr/local/squid</code></p>
<p>Initialize the cache and startup squid:<br />
<code>sudo /usr/local/squid/sbin/squid -z<br />
sudo /usr/local/squid/sbin/squid -D</code></p>
<p>Now you can configure firefox (using -ProfileManager) or chrome (using &#8211;proxy-server=127.0.0.1) to point to your local proxy server. This proxy will then authenticate on your behalf and peer all requests via the original parent.</p>
<p>A little long winded but achieves the outcome. Added side benefit is you&#8217;ve now got a local proxy (with access logs) that you can start doing interesting things with in your automation / performance tests like modifying headers and so forth.</p>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://altentee.com/2010/authenticating-proxy-with-webdriver-and-watir/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Going Parallel &#8230;  distributed testing across a grid network using Watir</title>
		<link>http://altentee.com/2009/going-parallel-distributed-testing-across-a-grid-network-using-watir/</link>
		<comments>http://altentee.com/2009/going-parallel-distributed-testing-across-a-grid-network-using-watir/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 20:28:08 +0000</pubDate>
		<dc:creator>Tim Koopmans</dc:creator>
				<category><![CDATA[90kts]]></category>
		<category><![CDATA[Altentee]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://90kts.com/blog/2009/going-parallel-distributed-testing-across-a-grid-network-using-watir/</guid>
		<description><![CDATA[<p>In my last post I made a tongue-in-cheek observation that load testing really doesn&#8217;t work by today&#8217;s perceived standards for web automation and testing.</p>
<p>Part of my grievance for that was based on frustration in dealing with different load testing platforms. Not frustration born out of incompetence, more the frustration born out writing tests for increasingly [...]]]></description>
			<content:encoded><![CDATA[<p>In my last <a href="http://90kts.com/blog/2009/why-load-testing-does-not-work-for-the-web-datetoday-36/"><strong>post</strong></a> I made a tongue-in-cheek observation that load testing really doesn&#8217;t work by today&#8217;s perceived standards for web automation and testing.</p>
<p>Part of my grievance for that was based on frustration in dealing with different load testing platforms. Not frustration born out of incompetence, more the frustration born out writing tests for increasingly complex browsers with an antiquated toolset.</p>
<p>That&#8217;s not to say that protocol based application load testing (or the languages they sit on) aren&#8217;t powerful in their own right. LoadRunner, JMeter et al. has their place in the load testing world. But I would like to relegate them to the background as useful, sometimes expensive tools to spin up the wheels so to speak. Nothing like a bit of JMeter infused fun to get the wheels smoking on your system under test. But for the real part,  measuring user experience on the web platform?<br />
<span id="more-292"></span><br />
<em>If you can&#8217;t wait to get started then I&#8217;d like to introduce <a href="http://browsermob.com"><strong>BrowserMob.com</strong></a>. Been around since mid 2008 and offers real browser testing using Selenium scripts distributed across a grid of EC2 computers. Reasonably priced, well documented and supported by the legendary Patrick Lightbody, founder of things like OpenQA and Selenium Remote Control.</em></p>
<p>But hang on a second, you don&#8217;t like Selenium right? Have zero budget? <strong>Love <a href="http://watir.com">Watir</a>?</strong> Well I&#8217;m working on a similar construct aptly called WatirGrid which also allows for distributed testing across a grid network using Watir. The engine (gem) itself is open source and you can get it as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">gem install watirgrid</pre></div></div>

<p>If you&#8217;d like to contribute please follow the <a href="http://github.com/90kts/watirgrid"><strong>WatirGrid</strong></a> project on github.</p>
<p><strong>The Basics</strong><br />
WatirGrid is built on Rinda which implements the Linda distributed computing paradigm in Ruby. According to Wikipedia: â€œLinda is a model of coordination and communication among several parallel processes operating upon objects stored in and retrieved from shared, virtual, associative memory.â€</p>
<p>In other words, WatirGrid allows multiple parallel processes to provide remote Watir objects in the form of tuple spaces across a grid network. This grid network is controlled by a ring server and looks a bit like this:</p>
<p><a href="http://altentee.com/wp-content/uploads/watirgrid_overview.png"><img class="alignnone size-full wp-image-543" title="watirgrid_overview" src="http://altentee.com/wp-content/uploads/watirgrid_overview.png" alt="" width="788" height="507" /></a></p>
<p><strong>Key Terminology</strong><br />
The <strong>controller</strong> implements a repository of tuples (tuple space) that can be accessed concurrently. The controller hosts the ring server which advertises these tuples across a grid network. Typically you will host one controller on a central machine.</p>
<p>The <strong>providers</strong> make remote Watir objects available to the tuple space hosted by the ring server. Typically you will host one or many providers on your grid network, for example, each PC may become a single provider of a Watir tuple in the form of an Internet Explorer, Firefox or Safari browser object.</p>
<p><strong>Simple Example</strong><br />
Pick a server to host the <em>controller</em> for the ring server and execute the following:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">  $ controller</pre></div></div>

<p>This should find your external facing IP and start the corresponding DRb and Ring Servers:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">  DRb server started on : druby://143.238.105.61:11235
  Ring server started on: druby://143.238.105.61:12358</pre></div></div>

<p>On each client PC, host the <em>provider</em> for the distributed (DRb) Watir objects</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">  $  provider</pre></div></div>

<p>This should find the recently started Ring Server and register a tuple for the Watir object:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">  DRb server started on : druby://143.238.105.61:11236
  Ring server found on  : druby://143.238.105.61:12358
  New tuple registered  : druby://143.238.105.61:12358</pre></div></div>

<p>You will now be able to execute commands across remote browsers on your grid network.<br />
e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  grid = <span style="color:#6666ff; font-weight:bold;">Watir::Grid</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:ring_server_port</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">12358</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  grid.<span style="color:#9900CC;">start</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:quantity</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:read_all</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  threads = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  grid.<span style="color:#9900CC;">browsers</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>browser<span style="color:#006600; font-weight:bold;">|</span>
    threads <span style="color:#006600; font-weight:bold;">&amp;</span>lt;<span style="color:#006600; font-weight:bold;">&amp;</span>lt; <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      b = browser<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:object</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">new_browser</span>
      b.<span style="color:#9900CC;">goto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://www.google.com&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      b.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">'q'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;watirgrid&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      b.<span style="color:#9900CC;">button</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;btnI&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  threads.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>thread<span style="color:#006600; font-weight:bold;">|</span> thread.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>You may wish to host the controller and providers on different machines in a real scenario. You can specify things like server hostnames, ports and access control lists for each of the different types of servers. For more help see:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">  $  controller --help
  Usage: controller [options]
  Specific options:
      -H, --drb-server-host HOST       Specify DRb Server interface to host on
      -d, --drb-server-port PORT       Specify DRb Server port to listen on
      -h, --ring-server-host HOST      Specify Ring Server interface to host on
      -r, --ring-server-port PORT      Specify Ring Server port to listen on
      -a, --access-control-list ACLS   Specify a comma separated Access Control List
      -l, --log-level LEVEL            Specify log level {DEBUG|INFO|ERROR}
          --help                       Show this message
&nbsp;
  $  provider --help
  Usage: provider [options]
  Specific options:
      -H, --drb-server-host HOST       Specify DRb Server interface to host on
      -d, --drb-server-port PORT       Specify DRb Server port to listen on
      -h, --ring-server-host HOST      Specify Ring Server host to connect to
      -r, --ring-server-port PORT      Specify Ring Server port to broadcast on
      -b, --browser-type TYPE          Specify browser type to register {ie|firefox|safari}
      -a, --access-control-list ACLS   Specify a comma separated Access Control List
      -l, --log-level LEVEL            Specify log level {DEBUG|INFO|ERROR}
          --help                       Show this message</pre></div></div>

<p>Need more help?</p>
<p>Keep an eye on the <a href="http://wiki.github.com/90kts/watirgrid"><strong>wiki</strong></a> and the <a href="http://github.com/90kts/watirgrid/tree/master/spec/"><strong>rspec</strong></a> test cases!</p>
]]></content:encoded>
			<wfw:commentRss>http://altentee.com/2009/going-parallel-distributed-testing-across-a-grid-network-using-watir/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Watir Powered LoadRunner Scripts</title>
		<link>http://altentee.com/2009/watir-powered-loadrunner-scripts/</link>
		<comments>http://altentee.com/2009/watir-powered-loadrunner-scripts/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 09:16:31 +0000</pubDate>
		<dc:creator>Tim Koopmans</dc:creator>
				<category><![CDATA[90kts]]></category>
		<category><![CDATA[Altentee]]></category>
		<category><![CDATA[loadrunner]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://90kts.com/blog/2009/watir-powered-loadrunner-scripts/</guid>
		<description><![CDATA[<p>Here&#8217;s an idea&#8230; Ever been in a LoadRunner contract where you&#8217;ve got a ton of scripts to write for business transactions that have many many design steps?</p>
<p>Even worse, have you had to write those scripts against a development environment with an unstable code base and shocking performance? Sound familiar? Ever felt the frustration of re-recording [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an idea&#8230; Ever been in a LoadRunner contract where you&#8217;ve got a ton of scripts to write for business transactions that have many many design steps?</p>
<p>Even worse, have you had to write those scripts against a development environment with an unstable code base and shocking performance? Sound familiar? Ever felt the frustration of re-recording manual test cases back into LoadRunner in said environments. Why wouldn&#8217;t you just automate the script recording process?</p>
<p><span id="more-254"></span><br />
Well if you&#8217;re in a LoadRunner shop there&#8217;s probably a QTP license floating around. However there&#8217;s a great alternative with Ruby, specifically <a href="http://watir.com"><strong>Web Application Testing In Ruby</strong></a>.</p>
<p>The gist is that you setup your manual test case using a watir script, then re-record your LoadRunner scripts using those watir scripts as the driver. The benefits are many:</p>
<p>1. Reduce user input errors when recording the LoadRunner scripts.<br />
2. Have a consistent way of re-recording LoadRunner scripts based on the same input delivered by the watir script.<br />
3. Diffing for correlation becomes easier because of consistency between multiple recordings of the same script.<br />
4. Watir scripts are easier to maintain than LoadRunner scripts.<br />
5. You can incorporate other Ruby gems into your watir scripts to assist with repetitive tasks during recording. For example, I copy transaction names to the clipboard between each step so I can easily paste them into transaction start timers.<br />
6. Watir scripts can double as a smoke test which you can run in parallel with load tests that use only virtual users.<br />
7. Watir scripts (and sampling response time from a real browser) will incorporate other factors such as client render time. Something which vusers really can&#8217;t do.</p>
<p>Downside is that you need to do a little more preparation than you might have to if you&#8217;re just following a manual test case. Once you have a framework for creating your watir script, this becomes easier. I figure it takes me about 1 hour to script up an end to end transaction that might have around 30 sub transactions (or design steps).</p>
<p>So what do you need to get started?</p>
<p>Firstly to install watir, follow these instructions <a href="http://watir.com/installation/"><strong>here</strong></a>.</p>
<p>Come up with a framework for driving your manual test cases. There&#8217;s plenty of examples out there on how to make bullet proof frameworks driven from a variety of sources. Alister shares some good tips <a href="http://watirmelon.com/2009/09/08/creating-a-watir-framework-using-test-unit-and-roo/"><strong>here</strong></a>.</p>
<p>Here&#8217;s a simple framework to get you started.</p>
<p>I have a helpers class that fires up the browser (attaches to the window that LoadRunner spawns) and some common methods for starting/stopping transaction timers and writing out information to a logfile. It looks like this.<br />
<strong>helpers.rb</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'watir'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'logger'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'win32/clipboard'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'dl'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'win32/sound'</span>
<span style="color:#9966CC; font-weight:bold;">include</span> Win32
&nbsp;
logfile = <span style="color:#996600;">'C:<span style="color:#000099;">\t</span>emp<span style="color:#000099;">\o</span>utput.log'</span>
<span style="color:#0066ff; font-weight:bold;">@log</span> = <span style="color:#CC00FF; font-weight:bold;">Logger</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>logfile, <span style="color:#996600;">'daily'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#0066ff; font-weight:bold;">@log</span>.<span style="color:#9900CC;">info</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>New test started at &quot;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#0066ff; font-weight:bold;">@log</span>.<span style="color:#9900CC;">datetime_format</span> = <span style="color:#996600;">&quot;%H:%M:%S&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># if I want each step to start on the minute</span>
<span style="color:#008000; font-style:italic;"># useful when tracing back through profile logs</span>
<span style="color:#008000; font-style:italic;"># on the target server</span>
<span style="color:#0066ff; font-weight:bold;">@staggered</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># pause after each step to prompt you to</span>
<span style="color:#008000; font-style:italic;"># stop a transaction time or start a new one</span>
<span style="color:#0066ff; font-weight:bold;">@pause</span> = <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># setup a clipboard object to copy transaction names to</span>
<span style="color:#0066ff; font-weight:bold;">@clipboard</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#6666ff; font-weight:bold;">Win32::Clipboard</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># setup my browser object and attach to a running browser</span>
<span style="color:#008000; font-style:italic;"># spawned by the loadrunner recording engine</span>
<span style="color:#0066ff; font-weight:bold;">@b</span> <span style="color:#006600; font-weight:bold;">||</span>=<span style="color:#6666ff; font-weight:bold;">Watir::IE</span>.<span style="color:#9900CC;">attach</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:title</span>, <span style="color:#006600; font-weight:bold;">/</span>FOOBAR<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># alternatively start a new browser</span>
<span style="color:#008000; font-style:italic;">#~ @b ||=Watir::Browser.new</span>
<span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">visible</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">speed</span> = <span style="color:#ff3333; font-weight:bold;">:fast</span>
<span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">bring_to_front</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># display a simple message box with a dodgy sound</span>
<span style="color:#008000; font-style:italic;"># to grab your attention</span>
<span style="color:#9966CC; font-weight:bold;">def</span> message_box<span style="color:#006600; font-weight:bold;">&#40;</span>txt, title=APP_TITLE, buttons=<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  5.<span style="color:#9900CC;">upto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> Sound.<span style="color:#9900CC;">beep</span><span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006666;">1000</span>,<span style="color:#006666;">30</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  user32 = DL.<span style="color:#9900CC;">dlopen</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'user32'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  msgbox = user32<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'MessageBoxA'</span>, <span style="color:#996600;">'ILSSI'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  r, rs = msgbox.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span>, txt, title, buttons<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#0000FF; font-weight:bold;">return</span> r
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># a start timer method</span>
<span style="color:#9966CC; font-weight:bold;">def</span> timer_start
&nbsp;
  <span style="color:#008000; font-style:italic;"># figure out how long to sleep if staggered start is true</span>
  now = <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">now</span>
  diff = <span style="color:#006666;">60</span> <span style="color:#006600; font-weight:bold;">-</span> now.<span style="color:#9900CC;">sec</span>
  <span style="color:#CC0066; font-weight:bold;">sleep</span> diff <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@staggered</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># empty clipboard and copy current transaction name to it</span>
  <span style="color:#0066ff; font-weight:bold;">@clipboard</span>.<span style="color:#9900CC;">empty</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#0066ff; font-weight:bold;">@clipboard</span>.<span style="color:#9900CC;">set_data</span><span style="color:#006600; font-weight:bold;">&#40;</span>@t<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># prompt you to start a new transaction if pause is true</span>
  message_box<span style="color:#006600; font-weight:bold;">&#40;</span>@t, <span style="color:#996600;">&quot;Start Transaction&quot;</span>, <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@pause</span>
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@start_time</span> = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># end timer method</span>
<span style="color:#9966CC; font-weight:bold;">def</span> timer_end
  <span style="color:#0066ff; font-weight:bold;">@end_time</span> = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># prompt you to stpo end a transaction if pause is true</span>
  message_box<span style="color:#006600; font-weight:bold;">&#40;</span>@t, <span style="color:#996600;">&quot;End Transaction&quot;</span>, <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@pause</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># figure out elapsed time</span>
  <span style="color:#0066ff; font-weight:bold;">@elapsed_time</span> = <span style="color:#006600; font-weight:bold;">&#40;</span>@end_time <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#0066ff; font-weight:bold;">@start_time</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">1000</span>
  tab = <span style="color:#996600;">&quot;<span style="color:#000099;">\t</span>&quot;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># write it all to you logger</span>
  <span style="color:#0066ff; font-weight:bold;">@log</span>.<span style="color:#9900CC;">info</span><span style="color:#006600; font-weight:bold;">&#40;</span>@start_time.<span style="color:#9900CC;">to_f</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> tab <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#0066ff; font-weight:bold;">@end_time</span>.<span style="color:#9900CC;">to_f</span>.<span style="color:#9900CC;">to_s</span>  <span style="color:#006600; font-weight:bold;">+</span> tab \
  <span style="color:#006600; font-weight:bold;">+</span> tab <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#0066ff; font-weight:bold;">@start_time</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> tab <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC0066; font-weight:bold;">sprintf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'%-60s'</span>, <span style="color:#0066ff; font-weight:bold;">@t</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> tab <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC0066; font-weight:bold;">sprintf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'%10s'</span>, <span style="color:#0066ff; font-weight:bold;">@elapsed_time</span>.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># a simple sync method to wait for text on a scren</span>
<span style="color:#9966CC; font-weight:bold;">def</span> sync<span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#6666ff; font-weight:bold;">Watir::Waiter</span>.<span style="color:#9900CC;">wait_until</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">text</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>text<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Now your manual test case in ruby should look pretty simple. I typically rely on things like the :name, :text or :id attributes of html elements depending on how the application was written by the developers. The manual test case will look something like this.<br />
<strong>001_test_case.rb</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'helpers.rb'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">begin</span>
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@t</span> = <span style="color:#996600;">&quot;INIT&quot;</span>
  timer_start
  <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">goto</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'https://foobar/wps/myportal'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  timer_end
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@t</span> = <span style="color:#996600;">&quot;LOGIN&quot;</span>
  timer_start
  <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;username&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;yoohoo&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;password&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;foobar&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">button</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:index</span>, <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span>
  timer_end
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@t</span> = <span style="color:#996600;">&quot;FOOBAR_03a_03_Tab&quot;</span>
  timer_start
  <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">link</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:text</span>, <span style="color:#006600; font-weight:bold;">/</span>FOOBAR<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span>
  timer_end
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@t</span> = <span style="color:#996600;">&quot;FOOBAR_03a_04_FOOBAR_Tab&quot;</span>
  timer_start
  <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">link</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:text</span>, <span style="color:#006600; font-weight:bold;">/</span>FOOBAR<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span>
  sync<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;New FOOBAR&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  timer_end
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@t</span> = <span style="color:#996600;">&quot;FOOBAR_03a_27_Record_Notes&quot;</span>
  <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:id</span>, <span style="color:#996600;">&quot;PC_7_C5L40JR2001F002J5MT98S28H6__L_8_0_1_0_14_1_1&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Justification&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  timer_start
  <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">button</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:text</span>, <span style="color:#006600; font-weight:bold;">/</span>Save<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span>
  timer_end
&nbsp;
  <span style="color:#0066ff; font-weight:bold;">@t</span> = <span style="color:#996600;">&quot;FOOBAR_03a_28_Save_And_Foobaz&quot;</span>
  timer_start
  <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">link</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:text</span>, <span style="color:#006600; font-weight:bold;">/</span>Save <span style="color:#006600; font-weight:bold;">&amp;</span> Foobaz<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span>
  timer_end
&nbsp;
  <span style="color:#008000; font-style:italic;"># etc ...</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
  <span style="color:#0066ff; font-weight:bold;">@log</span>.<span style="color:#9900CC;">error</span><span style="color:#006600; font-weight:bold;">&#40;</span>@start_time.<span style="color:#9900CC;">to_i</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\t</span>&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#CC0066; font-weight:bold;">sprintf</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'%-60s'</span>, <span style="color:#0066ff; font-weight:bold;">@trans</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;<span style="color:#000099;">\t</span>Error<span style="color:#000099;">\n</span>&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> e<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Running this test case will output a log file to C:\temp\output.log that looks like this.</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">New test started at Thu Oct 08 20:37:48 +1100 2009
1254994670.936  1254994671.576          Thu Oct 08 20:37:50 +1100 2009  INIT                                                                 640.0
1254994671.576  1254994678.233          Thu Oct 08 20:37:51 +1100 2009  LOGIN                                                               6657.0
1254994678.233  1254994694.123          Thu Oct 08 20:37:58 +1100 2009  FOOBAR_03a_03_Tab                                          15890.0
1254994694.123  1254994696.014          Thu Oct 08 20:38:14 +1100 2009  FOOBAR_03a_04_FOOBAR_Tab                                      1891.0
1254994717.171  1254994727.608          Thu Oct 08 20:38:37 +1100 2009  FOOBAR_03a_05_Enter_FOOBAR_Type                              10437.0
1254994729.28   1254994743.499          Thu Oct 08 20:38:49 +1100 2009  FOOBAR_03a_06_Search_for_Primary_Person                      14219.0
1254994748.093  1254994767.265          Thu Oct 08 20:39:08 +1100 2009  FOOBAR_03a_07_Associate_Primary_Person                       19172.0
1254994767.265  1254994780.796          Thu Oct 08 20:39:27 +1100 2009  FOOBAR_03a_08_Enter_Primary_Person_Address_Details           13531.0
1254994780.796  1254994818.765          Thu Oct 08 20:39:40 +1100 2009  FOOBAR_03a_09_Enter_Primary_Person_Doc_Details        37969.0
1254994818.765  1254994835.906          Thu Oct 08 20:40:18 +1100 2009  FOOBAR_03a_16_Add_PoC _Link                                     17141.0
1254994838.828  1254994843.515          Thu Oct 08 20:40:38 +1100 2009  FOOBAR_03a_17_Add_PoC                                            4687.0
1254994852.078  1254994855.469          Thu Oct 08 20:40:52 +1100 2009  FOOBAR_03a_18_Search_Agent                                       3391.0
1254994855.469  1254994859.203          Thu Oct 08 20:40:55 +1100 2009  FOOBAR_03a_19_View_Agent                                         3734.0
1254994863.953  1254994876.203          Thu Oct 08 20:41:03 +1100 2009  FOOBAR_03a_20_Associate_Agent                                   12250.0
1254994876.203  1254994879.484          Thu Oct 08 20:41:16 +1100 2009  FOOBAR_03a_21_Add_Payment_Link                                   3281.0
1254994894.094  1254994894.703          Thu Oct 08 20:41:34 +1100 2009  FOOBAR_03a_22_Record_Payment_Details                              609.0
1254995196.611  1254995196.611          Thu Oct 08 20:46:36 +1100 2009  SAP                                                                    0.0
1254995202.486  1254995258.517          Thu Oct 08 20:46:42 +1100 2009  FOOBAR_03a_25_ Run Validity Assessment                          56031.0
1254995267.736  1254995280.017          Thu Oct 08 20:47:47 +1100 2009  FOOBAR_03a_27_Record_Notes                                      12281.0
1254995280.017  1254995346.579          Thu Oct 08 20:48:00 +1100 2009  FOOBAR_03a_28_Save_And_Foobaz                                    66562.0</pre></div></div>

<p>Which gives you things like start and stop times, elapsed times and action names to help you debug things further down the track.</p>
<p>All up I think it&#8217;s a pretty neat solution for re-re-re-recording LoadRunner scripts (or your tool of choice) you inevitably face in fast changing environments. Whilst writing this post I had a script ticking away in the background recording some 3000+ LoadRunner events. YMMV.</p>
]]></content:encoded>
			<wfw:commentRss>http://altentee.com/2009/watir-powered-loadrunner-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determining Network Time in Watir Scripts</title>
		<link>http://altentee.com/2009/determining-network-time-in-watir-scripts/</link>
		<comments>http://altentee.com/2009/determining-network-time-in-watir-scripts/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 01:35:08 +0000</pubDate>
		<dc:creator>Tim Koopmans</dc:creator>
				<category><![CDATA[90kts]]></category>
		<category><![CDATA[Altentee]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://90kts.com/blog/2009/determining-network-time-in-watir-scripts/</guid>
		<description><![CDATA[<p>By this I mean I wanted to determine how much network and server time was spent processing a request initiated by a Watir script. Server time as defined by time to first buffer and network time as time to last buffer (minus the first).</p>
<p>I couldn&#8217;t really do this from Ruby itself, so I installed Fiddler. [...]]]></description>
			<content:encoded><![CDATA[<p>By this I mean I wanted to determine how much network and server time was spent processing a request initiated by a Watir script. Server time as defined by time to first buffer and network time as time to last buffer (minus the first).</p>
<p>I couldn&#8217;t really do this from Ruby itself, so I installed <strong><a href="http://www.fiddler2.com/fiddler2/">Fiddler</a></strong>. Fiddler lets you capture traffic in much the same way as ethereal / wireshark but with a nice GUI. There are some <strong><a href="http://www.fiddler2.com/Fiddler/Dev/ScriptSamples.asp">Fiddler customization scripts</a></strong> which let you display this info in the Custom column i.e.<br />
<code>oSession["ui-customcolumn"] = "FB: " + oSession["X-TTFB"] + "; LB: " + oSession["X-TTLB"];</code></p>
<p>But if you&#8217;re a neat freak like me and want them in separate columns then do this:<br />
<code><br />
public  static  BindUIColumn("Time")<br />
  function  CalcMethodCol1(oS:  Session){<br />
    if (null != oS.oRequest) return DateTime.Now.ToString("dd/MM/yy HH:mm:ss.ffff");<br />
    else return String.Empty;<br />
  }</p>
<p>  public  static  BindUIColumn("AbbreviatedUrl")<br />
  function  CalcMethodCol2(oS:  Session){<br />
    if (null != oS.oRequest) return oS.url.substring(oS.url.lastIndexOf("/"));<br />
    else return String.Empty;<br />
  }</p>
<p>  public  static  BindUIColumn("TTFBuffer")<br />
  function  CalcMethodCol3(oS:  Session){<br />
    if (null != oS.oResponse) return oS["X-TTFB"];<br />
    else return String.Empty;<br />
  }</p>
<p>  public  static  BindUIColumn("TTLBuffer")<br />
  function  CalcMethodCol4(oS:  Session){<br />
    if (null != oS.oResponse) return oS["X-TTLB"];<br />
    else return String.Empty;<br />
  }<br />
</code></p>
<p>You place them before you declare the <strong>static function OnBeforeRequest</strong>. The time stamp used above ends up being the &#8216;end&#8217; timestamp, not the &#8217;start&#8217; so you just need to subtract time to last buffer to determine that. You end up with this in your summary view:<br />
<a href='http://90kts.com/blog/wp-content/uploads/2009/03/ttfb.png' title='ttfb.png'><img src='http://90kts.com/blog/wp-content/uploads/2009/03/ttfb.png' alt='ttfb.png' /></a></p>
<p>Once this is done you can pretty up the results by copying the &#8216;Full Summary&#8217; for your selected sessions in Fiddler and pasting them into Excel. This was the main reason for doing this. If you&#8217;re happy with the Fiddler &#8216;timeline&#8217; view then you don&#8217;t need to bother. I just wanted the data so I could merge/correlate with other data sources.<br />
<a href='http://90kts.com/blog/wp-content/uploads/2009/03/gantt.png' title='gantt.png'><img src='http://90kts.com/blog/wp-content/uploads/2009/03/gantt.png' alt='gantt.png' /></a></p>
<p>Would be interested to know if anyone has achieved this in ruby itself. I was thinking of using the <strong><a href="http://90kts.com/blog/2008/httpwatch-a-free-alternative-using-ruby/">webrick/httpproxy</a></strong> but would have come short if testing a HTTPS web app.</p>
]]></content:encoded>
			<wfw:commentRss>http://altentee.com/2009/determining-network-time-in-watir-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FireWatir 1.2.1 is released</title>
		<link>http://altentee.com/2008/firewatir-121-is-released/</link>
		<comments>http://altentee.com/2008/firewatir-121-is-released/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 23:03:37 +0000</pubDate>
		<dc:creator>Tim Koopmans</dc:creator>
				<category><![CDATA[90kts]]></category>
		<category><![CDATA[Altentee]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://90kts.com/blog/2008/firewatir-121-is-released/</guid>
		<description><![CDATA[<p>A new version of FireWatir has been released. This includes some fixes related to Firefox 3 but more importantly, it marks the merger of FireWatir and Watir projects, allowing for tighter coupling of methods and functionality between the two, allowing you to write less code =)</p>
<p>To use FireWatir, you will have to install a Firefox [...]]]></description>
			<content:encoded><![CDATA[<p>A new version of FireWatir has been released. This includes some fixes related to Firefox 3 but more importantly, it <strong>marks the merger of FireWatir and Watir</strong> projects, allowing for tighter coupling of methods and functionality between the two, allowing you to write less code =)</p>
<p>To use FireWatir, you will have to install a Firefox plugin that enables use of a JavaScript Shell (jssh). FireWatir works on Windows, Mac and Linux.<br />
Install FireWatir: <code>[sudo] gem install FireWatir</code><br />
Install Plugin: <a href="http://wiki.openqa.org/display/WTR/FireWatir">http://wiki.openqa.org/display/WTR/FireWatir</a></p>
<p>I will be using FireWatir on my mac for impromptu testing, since more recently I&#8217;ve found it beneficial to write automated test cases to provide consistent input when recording load test scenarios in JMeter or LoadRunner. For those interested in even more x-browser support, check out SafariWatir as well: <a href="http://safariwatir.rubyforge.org/">http://safariwatir.rubyforge.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://altentee.com/2008/firewatir-121-is-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A New Project: just_add_watir</title>
		<link>http://altentee.com/2008/a-new-project-just_add_watir/</link>
		<comments>http://altentee.com/2008/a-new-project-just_add_watir/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 22:19:31 +0000</pubDate>
		<dc:creator>Tim Koopmans</dc:creator>
				<category><![CDATA[90kts]]></category>
		<category><![CDATA[Altentee]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://90kts.com/blog/2008/a-new-project-just_add_watir/</guid>
		<description><![CDATA[<p>In an effort to get more actively involved with the open source community, I&#8217;ve recently starting working with another colleague on a new site called justaddwatir.com. This is an exciting collaboration of examples for web application testing in ruby (watir &#8211; pronounced &#8220;water&#8221;).</p>
<p>Watir is a simple open-source library for automating web browsers. It allows you [...]]]></description>
			<content:encoded><![CDATA[<p>In an effort to get more actively involved with the open source community, I&#8217;ve recently starting working with another colleague on a new site called <a href="http://justaddwatir.com"><strong>justaddwatir.com</strong></a>. This is an exciting collaboration of examples for web application testing in ruby (watir &#8211; pronounced &#8220;water&#8221;).</p>
<blockquote><p>Watir is a simple open-source library for automating web browsers. It allows you to write tests that are easy to read and easy to maintain. It is optimized for simplicity and flexibility. Watir drives browsers the same way people do. It clicks links, fills in forms, presses buttons. Watir also checks results, such as whether expected text appears on the page.</p></blockquote>
<p>Its main purpose will be to serve as a working repository of examples that answer questions newcomers have when scripting in watir. Its secondary purpose is to act as an extended regression suite of more applied test cases, which with the blessing of the lead developers of watir (<a href="http://www.pettichord.com/">Brett Pettichord</a>) will help test future releases of watir. A working code base of unit tests is being maintained at <a href="http://code.google.com/p/justaddwatir/">http://code.google.com/p/justaddwatir/</a></p>
<p>If you&#8217;d like to get involved in the project or you have a blog about watir which you&#8217;d like to be aggregated, please send an email to tim.koops at gmail.com</p>
]]></content:encoded>
			<wfw:commentRss>http://altentee.com/2008/a-new-project-just_add_watir/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Just Another Framework &#8211; for developing watir test cases</title>
		<link>http://altentee.com/2008/just-another-framework-for-developing-watir-test-cases/</link>
		<comments>http://altentee.com/2008/just-another-framework-for-developing-watir-test-cases/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 10:19:19 +0000</pubDate>
		<dc:creator>Tim Koopmans</dc:creator>
				<category><![CDATA[90kts]]></category>
		<category><![CDATA[Altentee]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://90kts.com/blog/2008/just-another-framework-for-developing-watir-test-cases/</guid>
		<description><![CDATA[<p>Recently I attended Railscamp 08 in Sydney Australia for a weekend of code, beer and bzflag. For my &#8216;project&#8217; I decided on brushing up my my Ruby skills and constructing a simple framework from which I could structure watir test cases.</p>
<p>Specifically I wanted to achieve the following:</p>
Create some form of script that could &#8216;learn&#8217; objects [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I attended Railscamp 08 in Sydney Australia for a weekend of code, beer and bzflag. For my &#8216;project&#8217; I decided on brushing up my my Ruby skills and constructing a simple framework from which I could structure watir test cases.</p>
<p>Specifically I wanted to achieve the following:</p>
<li>Create some form of script that could &#8216;learn&#8217; objects from the application under test, minimizing the amount of code I would have to write for tests (using reflection) and providing a mechanism to compare application changes between code releases.
</li>
<li>Pick a test framework to use as my test runner, for this I had two options in mind using TestUnit or RSpec.</li>
<li>Provide test set dynamic data using something *other* than Microsoft Excel.</li>
<p>To that end I was reasonably successful. The only limitation was that I only had my macbookpro with me and probably would have been shunned even if I attempted to load a windows XP virtual machine at a rails camp full of mac and linux geeks. So I chose FireWatir as my test platform running on my Mac, but am reasonably comfortable you can easily port this framework for use with Watir.</p>
<p>Now on with the framework contents &#8230;<br />
<span id="more-168"></span><br />
In the <a href='http://altentee.com/wp-content/uploads/jaf.zip' title='JAF'><strong>attached zip file</strong></a> file you will find the following directory/file structure, with the following explanation provided for each.</p>
<p>./run.rb : this is the controller, with the general intent to be able to set global options here, such as run Firefox in the background, or specify an iteration count for test cases.<br />
./setup.rb : setup is called by run.rb, and is the orchestration layer for running the test cases. This file also dynamically loads required libraries as well as the object Modules from my object repository for each page in the application under test.<br />
./results.html : this is an example output when the test suite is run using rspec with the &#8211;format html parameter argument.<br />
./data/test_data.yaml : an example of a small data set using a yaml format<br />
./objects : an example of the objects in my &#8216;object repository&#8217; dynamically created<br />
customerloginsubstruct.rb<br />
homesubstruct.rb<br />
storesubstruct.rb<br />
./tests : a couple of examples of test cases using rspec and testunit.<br />
rspecdemo_test.rb<br />
testunitdemo_test.rb<br />
./util/discoverobjects.rb : a utility script which &#8216;learns&#8217; objects on a page, which using reflection you can then later re-use in a DSL&#8217;ish kind of fashion. Should cut down on the amount of code you have to write when constructing test cases and implements a standard for naming objects on a page.</p>
<p><strong>How to use the framework &#8230;</strong><br />
The path to using this framework is to first utilize the DiscoverObjects class. The purpose of this script is to scan a page for common watir objects such as links, text_fields and buttons and create a list of &#8216;objects&#8217; in a new Module. Modules in Ruby allow you to incorporate methods in other classes. So for example, if you open up the AUT to a certain page, for example the logon page, then you can run the script to learn those objects on that page:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">ruby discoverobjects.<span style="color:#9900CC;">rb</span></pre></div></div>

<p>The script output will be a suggested structure for your Module. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> Customerloginsubstruct
<span style="color:#008000; font-style:italic;"># Objects learned from: http://localhost:3000/customers/login</span>
<span style="color:#008000; font-style:italic;"># Sun Jun 22 11:22:30 +1000 2008</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> text_field_name_login
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0066ff; font-weight:bold;">@b</span>.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;login&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>You can see some example objects created from a demo application (<a href="http://code.google.com/p/substruct/">Substruct</a>) in the objects subdirectory.</p>
<p><strong>Why am I taking this approach?</strong><br />
In the first instance I was sick of using FireBug or the IE Developer toolbar to individually pick elements on a page and learn their attributes when writing test cases. This process does it for me automatically.<br />
Secondly, it now gives me a form of version control between developer code release. So if elements change on a page, for example developer removes or adds attributes, I should be able to easily diff my object repositories.<br />
It also gives me a more generalized naming standard, or more predictable. For example a text link can be called by writing link_text_shopping_cart.click instead of @b.link(:text &#8216;Shopping Cart&#8217;). I&#8217;m hoping this format is more user friendly for the non-developer type testers who want to write test cases quickly. Obviously people&#8217;s opinion might differ on this <img src='http://altentee.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Running the RSpec tests &#8230;</strong><br />
I found the following options useful to run from the command line using rspec:<br />
<code><br />
spec run.rb --format specdoc -c<br />
spec run.rb --format html > ./results.html<br />
spec run.rb --format profile -c<br />
</code></p>
<p>Have a play around and see what you think. I found the html format to be most useful. As it is updated progressively, you could output this to your common web server so that people can easily check progress of long running automation test suites. This is all just food for thought. Let me know what you think and if there are any improvements you can offer.</p>
]]></content:encoded>
			<wfw:commentRss>http://altentee.com/2008/just-another-framework-for-developing-watir-test-cases/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Installing Firewatir on Mac OSX</title>
		<link>http://altentee.com/2008/installing-firewatir-on-mac-osx/</link>
		<comments>http://altentee.com/2008/installing-firewatir-on-mac-osx/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 07:14:50 +0000</pubDate>
		<dc:creator>Tim Koopmans</dc:creator>
				<category><![CDATA[90kts]]></category>
		<category><![CDATA[Altentee]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://90kts.com/blog/2008/installing-firewatir-on-mac-osx/</guid>
		<description><![CDATA[<p>By now you&#8217;ve probably heard of watir or Web Application Testing In Ruby, a great automation framework which supports Microsoft Internet Explorer, and recently came in at number 3 as a popular oss tool on this blog.</p>
<p>I&#8217;ve been using this tool mostly from a windows box, and knew of the firefox equivalent, aptly named &#8216;Firewatir&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>By now you&#8217;ve probably heard of <a href="http://wtr.rubyforge.org/">watir</a> or Web Application Testing In Ruby, a great automation framework which supports Microsoft Internet Explorer, and recently came in at number 3 as a popular oss tool on this <a href="http://www.opensourcetesting.org/survey.php">blog</a>.</p>
<p>I&#8217;ve been using this tool mostly from a windows box, and knew of the firefox equivalent, aptly named &#8216;Firewatir&#8217; which is currently a Google code <a href="http://code.google.com/p/firewatir/">project</a>. The beauty of this version, is that it allows you as a tester to explore functionality on your favourite platform for development, as I like to leave windows at work, and take OSX with me on the train.</p>
<p>Read on for some simple instructions in getting this running on your Macbook Pro &#8230;<br />
<span id="more-155"></span></p>
<p>Install the latest gem for firewatir using terminal<br />
<code>sudo gem install firewatir</code></p>
<p>Download the latest browser extension (XPI) for JSSh from here:<br />
<a href="http://firewatir.googlecode.com/files/jssh-darwin-0.94.xpi">http://firewatir.googlecode.com/files/jssh-darwin-0.94.xpi</a></p>
<p>I found the easiest way to install it on a Mac is to open up Firefox, then just drag the .xpi file across to the browser. You&#8217;ll then be prompted with the usual in order to install the extension. You can also check for updates at the main Google code page.</p>
<p>Once installed, restart Firefox and enable the JSSh plugin from the Tools->JSSh configuration<br />
<a href='http://90kts.com/blog/wp-content/uploads/2008/06/jssh.png' title='jssh'><img src='http://90kts.com/blog/wp-content/uploads/2008/06/jssh.png' alt='jssh' /></a><br />
You need to tick the checkbox that enables JSSh to listen in on port 9997</p>
<p>You should now be able to telnet to that port from a terminal<br />
<code>telnet 127.0.0.1 9997</code></p>
<p><code>ctrl-]</code> to quit the shell and type <code>quit</code> to exit telnet</p>
<p>Allow popups for firefox by setting preferences->content as follows<br />
<a href='http://90kts.com/blog/wp-content/uploads/2008/06/exceptions.png' title='pop up excpetions'><img src='http://90kts.com/blog/wp-content/uploads/2008/06/exceptions.png' alt='pop up excpetions' /></a></p>
<p>Run the unit tests that come with your firewatir gem, typically:<br />
<code>cd /Library/Ruby/Gems/1.8/gems/firewatir-1.1.1/unittests/<br />
ruby mozilla_all_tests.rb</code></p>
<p>This will take a couple of minutes after which you should get something similar to the following:<br />
<code>251 tests, 1414 assertions, 0 failures, 2 errors</code></p>
<p>Note: I get a couple of errors in attaching to new windows as per the following<br />
<code><br />
  1) Error:<br />
test_simply_attach_to_new_window_using_title(TC_NewWindow):<br />
FireWatir::Exception::NoMatchingWindowFoundException: Unable to locate window, using title and Pass Page<br />
    ./../firewatir.rb:410:in `attach'<br />
    ./unittests/attach_to_new_window_test.rb:16:in `test_simply_attach_to_new_window_using_title'</p>
<p>  2) Error:<br />
test_simply_attach_to_new_window_using_url(TC_NewWindow):<br />
FireWatir::Exception::NoMatchingWindowFoundException: Unable to locate window, using url and (?-mix:pass\.html)<br />
    ./../firewatir.rb:410:in `attach'<br />
    ./unittests/attach_to_new_window_test.rb:24:in `test_simply_attach_to_new_window_using_url'<br />
</code><br />
which at this stage I&#8217;m not overly concerned with as I&#8217;m not using that functionality. I&#8217;ll post an update if I resolve that for my system.</p>
]]></content:encoded>
			<wfw:commentRss>http://altentee.com/2008/installing-firewatir-on-mac-osx/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Capturing Screenshots in Watir</title>
		<link>http://altentee.com/2008/capturing-screenshots-in-watir/</link>
		<comments>http://altentee.com/2008/capturing-screenshots-in-watir/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 06:27:01 +0000</pubDate>
		<dc:creator>Tim Koopmans</dc:creator>
				<category><![CDATA[90kts]]></category>
		<category><![CDATA[Altentee]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://90kts.com/blog/2008/capturing-screenshots-in-watir/</guid>
		<description><![CDATA[<p>Recently I noticed some discussion in the watir user group about trying to capture screenshots when running automated tests.</p>
<p>For such a simple requirement, it&#8217;s frustrating that solutions available either cost money (such as the purchase of SnagIt) or are a tad complicated in implementation requiring the installation of some out of date gems and dependencies. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I noticed some <a href="http://groups.google.com/group/watir-general/browse_thread/thread/e6d656a04303a2df?hl=en">discussion </a>in the watir user group about trying to capture screenshots when running automated tests.</p>
<p>For such a simple requirement, it&#8217;s frustrating that solutions available either cost money (such as the purchase of SnagIt) or are a tad complicated in implementation requiring the installation of some out of date gems and dependencies. I&#8217;ve also come across this requirement in other automation tools such as QTP, so I thought it&#8217;s about time I rolled up my sleeves and hack together a simple solution with C#.NET 2.0.<br />
<span id="more-149"></span></p>
<p>First thing I did was created a small app called <strong>snapit.exe</strong> which you can download <a href='http://90kts.com/blog/wp-content/uploads/2008/06/snapit.exe' title='snapIt.exe by 90kts'>here</a>. If anyone is interested in improving the code, you&#8217;re welcome to get a copy of my source code <a href='http://90kts.com/blog/wp-content/uploads/2008/06/snapit.zip' title='snapIt Source Code'>here</a>. In short, all this app does is take a screenshot of the entire screen, and save it to a default location (currently C:\snapit.png). Repeated use of the app will increment the filename by 1 i.e. snapit1.png, snapit2.png &#8230;</p>
<p>You can change the default file path by passing it a parameter at runtime<br />
e.g. <code>D:\\snapit.exe D:\\images\\testcase.png</code></p>
<p>Next thing to do is call it from your watir code. In Ruby, this is as simple as:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">cmd = <span style="color:#996600;">'D:<span style="color:#000099;">\\</span>snapit.exe'</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#008000; font-style:italic;">#{cmd}}</span></pre></td></tr></table></div>

<p>Putting it all together with some watir as an example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">&quot;watir&quot;</span>
test_site = <span style="color:#996600;">&quot;http://www.90kts.com&quot;</span>
ie = <span style="color:#6666ff; font-weight:bold;">Watir::IE</span>.<span style="color:#9900CC;">new</span>
ie.<span style="color:#9900CC;">goto</span> test_site
ie.<span style="color:#9900CC;">link</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:text</span>, <span style="color:#996600;">&quot;Contact&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span>
cmd = <span style="color:#996600;">'D:<span style="color:#000099;">\\</span>snapit.exe D:<span style="color:#000099;">\\</span>images<span style="color:#000099;">\\</span>testsuite.png'</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#008000; font-style:italic;">#{cmd}}</span></pre></td></tr></table></div>

<p>Hopefully someone finds that useful. You can use this in any automation suite really, up to you. It&#8217;s free of course, unless you want to donate some money towards my appreciation for beer&#8230;  <img src='http://altentee.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://altentee.com/2008/capturing-screenshots-in-watir/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
