<?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>threehv &#187; watir</title>
	<atom:link href="http://www.3hv.co.uk/blog/tag/watir/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.3hv.co.uk/blog</link>
	<description>precision engineering for your website</description>
	<lastBuildDate>Fri, 13 Jan 2012 16:18:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quick Tip: make it easier to debug your full-stack acceptance tests</title>
		<link>http://www.3hv.co.uk/blog/2009/03/24/quick-tip-make-it-easier-to-debug-your-full-stack-acceptance-tests/</link>
		<comments>http://www.3hv.co.uk/blog/2009/03/24/quick-tip-make-it-easier-to-debug-your-full-stack-acceptance-tests/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 09:40:29 +0000</pubDate>
		<dc:creator>Rahoul Baruah</dc:creator>
				<category><![CDATA[Ruby on Rails and Software Development]]></category>
		<category><![CDATA[Writing Reliable, Bug-Free Code]]></category>
		<category><![CDATA[acceptance tests]]></category>
		<category><![CDATA[Bug-Free Code]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[specifying]]></category>
		<category><![CDATA[watir]]></category>
		<category><![CDATA[webrat]]></category>
		<category><![CDATA[Writing Reliable]]></category>

		<guid isPermaLink="false">http://www.3hv.co.uk/blog/?p=439</guid>
		<description><![CDATA[One of the issues when using Selenium or Watir to power your full-stack acceptance testing (apart from the time it takes for the test suite to run), is that stuff happens within your browser, fails and then Cucumber happily moves on to the next test before you get a chance to look at what went [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_443" class="wp-caption alignright" style="width: 209px"><img src="http://www.3hv.co.uk/blog/wp-content/uploads/2009/03/959622_spanners_2.jpg" alt="Spanner in the works" title="Testing" width="199" height="300" class="size-full wp-image-443" /><p class="wp-caption-text">Spanner in the works</p></div>One of the issues when using Selenium or Watir to power your full-stack acceptance testing (apart from the time it takes for the test suite to run), is that stuff happens within your browser, fails and then Cucumber happily moves on to the next test before you get a chance to look at what went wrong.  </p>
<p>If you are just using plain old Webrat you can pepper your code with <tt>puts</tt> statements so you can check the value of variables, the existence of HTML elements and the flow of code as it happens.  But with Selenium or Watir, you need to run your app separately to Cucumber, normally in a hidden, background, process, so the output of your <tt>puts</tt> statements is lost in the ether (or an empty pipe).  </p>
<p>After having a particularly annoying and hard to trace bug, that was related to an interaction between form content and javascript, I came up with an extremely simple debugging tool.  </p>
<p>Just add the following into one of your steps files: </p>
<pre><code>When /^I pause$/ do
  STDIN.gets
end
</code></pre>
<p>Then, find the feature that is causing you grief and insert a &#8220;when I pause&#8221; step at the appropriate time.  </p>
<p><code>When I do this<br />
And I do that<br />
<strong>And I pause</strong><br />
And I press "Save"<br />
Then I see my newly created object<br />
</code></p>
<p>Cucumber will power your app, poking it until it gets to the &#8220;when I pause&#8221; step.  It will then pause, waiting on STDIN for you to hit return &#8211; giving you time to open your inspector window and poke around in the form as the tests see it.  </p>
<p>In this particular case, my steps file had an incorrectly named element within it &#8211; all it took was an inspection of the element in question and I saw the error.  Hours of frustration wiped out by one of the simplest commands there is.  </p>
<p><small>Spanners by <a href="http://www.sxc.hu/photo/959622">woodsy</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.3hv.co.uk/blog/2009/03/24/quick-tip-make-it-easier-to-debug-your-full-stack-acceptance-tests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cucumber and WATIR: kick-starting your testing</title>
		<link>http://www.3hv.co.uk/blog/2009/01/16/cucumber-and-watir-kick-starting-your-testing/</link>
		<comments>http://www.3hv.co.uk/blog/2009/01/16/cucumber-and-watir-kick-starting-your-testing/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 09:52:50 +0000</pubDate>
		<dc:creator>Rahoul Baruah</dc:creator>
				<category><![CDATA[Designing Great Software]]></category>
		<category><![CDATA[Ruby on Rails and Software Development]]></category>
		<category><![CDATA[Writing Reliable, Bug-Free Code]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[watir]]></category>

		<guid isPermaLink="false">http://www.3hv.co.uk/blog/?p=360</guid>
		<description><![CDATA[I think Cucumber is fast becoming indispensable for my testing. The point of it is that you can write documentation that your client understands and then prove that the application does what it says. When coupled with WATIR you can show that it really works in an actual browser &#8211; you can even show it [...]]]></description>
			<content:encoded><![CDATA[<p>I think <a href="http://wiki.github.com/aslakhellesoy/cucumber">Cucumber</a> is fast becoming indispensable for my testing.  The point of it is that you can write documentation that your client understands and then prove that the application does what it says.  When coupled with <a href="http://wtr.rubyforge.org/">WATIR</a> you can show that it really works in an actual browser &#8211; you can even show it in Internet Explorer, Firefox and Safari.  </p>
<p>There are a number of issues with using WATIR &#8211; the main one being speed &#8211; as WATIR scripts the browser, an extensive test suite will take a long time to run.  </p>
<p>But my first hurdle was actually getting the code running.  Unlike using Cucumber with <a href="http://wiki.github.com/brynary/webrat">Webrat</a>, where your Cucumber steps have access to your Rails code (so you can play around with the response object), with WATIR you run the application in a separate process and then poke the browser in the same way a real user would.  Of course, unlike Webrat, you get to test your Javascript too.  </p>
<p>However, I didn&#8217;t want to have to remember to start my application before running the tests (and probably forgetting to put it into the test environment or running on the wrong port) &#8211; so I came up with the following for your features/support/env.rb.  </p>
<pre><code>
system 'rake db:test:clone'
system 'rm log/test.log'
system 'ruby script/server -p 3001 -e test -d'

at_exit do
  system "kill `ps aux | grep mongrel_rails | grep -e '-p 3001' | grep -v grep | awk '{ print $2 }'`"
end

Before do
  @browser = Watir::Safari.new
  @browser.set_fast_speed
  @base_url = 'http://localhost:3001'
end
</code></pre>
<p>This clones your development database, gets rid of the test log (as we&#8217;ll need to look through that to track down any errors, so we want to keep it small) and then starts your app in test mode on port 3001 (so it doesn&#8217;t clash with the version you&#8217;ve already got open in development).  The Before clause sets up WATIR and configures a base url that my steps use elsewhere.  And the at_exit hook looks for the server we started and kills it.  </p>
<p>Next step is to add a platform instruction &#8211; so you can choose to test with Safari, Firefox (if I can ever get the Firewatir plugin installed) and Internet Explorer (where I guess the kill statement will need a bit of alteration).  </p>
<p>An alternative is to tell mongrel to start and write a pidfile to a known place, and then replace the ps/grep line with: </p>
<pre><code>
  pid = File.read(File.expand_path(RAILS_ROOT + "/log/mongrel.pid")).chomp
  `kill #{pid}`
</code></pre>
<p>Thanks to <a href="http://caius.name/">Caius</a> for that version.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.3hv.co.uk/blog/2009/01/16/cucumber-and-watir-kick-starting-your-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.189 seconds -->

