<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>WatirMelon &#187; Watir</title>
	<atom:link href="http://watirmelon.com/category/Watir/feed/" rel="self" type="application/rss+xml" />
	<link>http://watirmelon.com</link>
	<description>A 93% Watir Based Blog by Alister Scott</description>
	<lastBuildDate>Tue, 07 Feb 2012 04:55:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='watirmelon.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/c9de640b304257bb2361e16d95fec265?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>WatirMelon &#187; Watir</title>
		<link>http://watirmelon.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://watirmelon.com/osd.xml" title="WatirMelon" />
	<atom:link rel='hub' href='http://watirmelon.com/?pushpress=hub'/>
		<item>
		<title>A tale of three ruby automated testing APIs (redux)</title>
		<link>http://watirmelon.com/2011/12/03/a-tale-of-three-ruby-automated-testing-apis-redux/</link>
		<comments>http://watirmelon.com/2011/12/03/a-tale-of-three-ruby-automated-testing-apis-redux/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 02:17:55 +0000</pubDate>
		<dc:creator>Alister Scott</dc:creator>
				<category><![CDATA[ATDD]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[Specification by Example]]></category>
		<category><![CDATA[Watir]]></category>
		<category><![CDATA[Watir-WebDriver]]></category>
		<category><![CDATA[capybara]]></category>
		<category><![CDATA[selenium-webdriver]]></category>
		<category><![CDATA[watir-webdriver]]></category>

		<guid isPermaLink="false">http://watirmelon.com/?p=1171</guid>
		<description><![CDATA[Redux Note: I originally wrote a similar article to this before going on parental leave about six weeks ago. Whilst I didn&#8217;t intend to offend, it seemed that a few people took my article the wrong way. I understand that &#8230; <a href="http://watirmelon.com/2011/12/03/a-tale-of-three-ruby-automated-testing-apis-redux/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=1171&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Redux Note:</strong> I originally wrote a similar article to this before going on parental leave about six weeks ago. Whilst I didn&#8217;t intend to offend, it seemed that a few people took my article the wrong way. I understand that a lot of effort goes into creating a web testing API, but that doesn&#8217;t mean that everyone will agree with what you&#8217;ve made.</p>
<p>Sadly, an <a href="http://en.wikipedia.org/wiki/Anonymous_post">anonymous coward</a> attacked myself and the company who I work (even though I don&#8217;t mention that company on this blog), so for the first time in this blog&#8217;s history, I have had to turn comment moderation on. I am sorry to the other genuine commenters whose comments have been lost in transition, and now have to wait for their new comments to be approved.</p>
<p>Since then I have received numerous emails asking where my article went, and commenting that people found it interesting and worthwhile. So I have decided to repost this article, hopefully with a little less contention this time around, making it clear, this is my <em>opinion</em> and experience: <a href="http://en.wiktionary.org/wiki/your_mileage_may_vary">YMMV</a>.</p>
<p><strong>Intro</strong></p>
<p>As a consultant I get to see and work on a lot of automated testing solutions using different automated web testing APIs. Lately I&#8217;ve been thinking about how these APIs are different and what makes them so.</p>
<p>My main interest is in ruby, and fortunately ruby has three solid examples of three different kinds of web testing APIs, two of which extend the lowest level API: selenium-webdriver.</p>
<p>I&#8217;ll (try to) explain here what I consider to be three kinds of automated web testing APIs and where I consider the sweet spot to be and and why.</p>
<p><strong>A meaty example</strong></p>
<p>As a carnivore, I thought I would explain my concept in terms I can relate to. If you&#8217;re a beef eater, there are many different kinds of beef that you can use to make some tasty food to eat. I&#8217;ll use three different kinds of beef for my example. The first (rawest) kind would involve getting a beef carcass and filleting it yourself to eventually make some edible food. The second kind of beef you could use is beef that is already in a slightly usable form, but you can then use yourself to make some edible food. For example, you can buy minced beef at a butcher, and then make your own hamburger patties, taco fillings etc from it. The final type of beef you could use is beef that has already been prepared so you can directly consume it, for example, sausages which can be cooked and consumed as is.</p>
<p>I consider these three examples of different kinds of beef to roughly correlate to automated web testing APIs, of which I also consider to be three kinds of.</p>
<p>The first is a <strong>Web Driver API</strong>, which is the rawest form of an API, its job is to drive a browser by issuing it commands. It provides a high level of user control, but like filleting a beef carcass it&#8217;s more &#8216;work&#8217;. An example in ruby of this API is the <a href="http://code.google.com/p/selenium/wiki/RubyBindings">selenium-webdriver API</a>, which controls the browser using the webdriver drivers.</p>
<p>The second kind of automated web testing API is the <strong>Browser API</strong>, which is a higher level API but still provides user control. This is the minced beef of APIs, as whilst it&#8217;s in a more usable form than a carcass, you still have a lot of control (and potential to what you can do with it). An example in ruby of this API is the <a title="Watir-WebDriver tests on Firefox 7: getting rid of the send data to Mozilla message" href="http://watirwebdriver.com/">watir-webdriver API</a>, which uses the underlying selenium-webdriver carcass to control the browser.</p>
<p>The final kind of automated web testing API is the <strong>Web Form DSL</strong> (Domain Specific Language) which is a very high level API that provides users with specific methods to automate web forms and their elements. This is the beef sausages of APIs as sometimes you feel like eating something else besides sausages, but it&#8217;s difficult to make anything else edible <em>but</em> sausages<em> from</em> sausages. An example in ruby of this Web Form DSL is the <a href="http://rubydoc.info/github/jnicklas/capybara/master/Capybara/DSL">Capybara DSL</a>.</p>
<p>Visually, this looks something like this:</p>
<p><a href="http://watirmelon.files.wordpress.com/2011/12/threekindsofautomatedwebtestingapis.png"><img class="alignnone size-full wp-image-1172" title="ThreekindsofautomatedwebtestingAPIs" src="http://watirmelon.files.wordpress.com/2011/12/threekindsofautomatedwebtestingapis.png?w=584&#038;h=344" alt="" width="584" height="344" /></a></p>
<p><strong>Show me the code™</strong></p>
<p>So exactly what do these APIs look like?</p>
<p>I knew you&#8217;d ask, that&#8217;s why I came prepared.</p>
<p>Say I want to accomplish a fairly basic scenario on my <a href="http://bit.ly/watir-webdriver-demo">example Google Doc form</a>:</p>
<ul>
<li>Start a browser</li>
<li>Navigate to the watir-webdriver-demo form</li>
<li>Check whether text field with id &#8216;entry_0&#8242; exists (this <strong>should</strong> exist)</li>
<li>Check whether text field with id &#8216;entry_99&#8242; exists (this <strong>shouldn&#8217;t</strong> exist)</li>
<li>Set a text field with id &#8216;entry_0&#8242; to &#8217;1&#8242;</li>
<li>Set a text field with id &#8216;entry_0&#8242; to &#8217;2&#8242;</li>
<li>Select &#8216;Ruby&#8217; from select list with id &#8216;entry_1&#8242;</li>
<li>Click the Submit button</li>
</ul>
<p>This is how <em>I would do it</em> in the three different APIs:</p>
<p><pre class="brush: ruby;">
# * Start browser
# * Navigate to watir-webdriver-demo form
# * Check whether text field with id 'entry_0' exists
# * Check whether text field with id 'entry_99' exists
# * Set text field with id 'entry_0' to '1'
# * Set text field with id 'entry_0' to '2'
# * Select 'Ruby' from select list with id 'entry_1'
# * Click the Submit button

require 'bench'

benchmark 'selenium-webdriver' do
  require 'selenium-webdriver'

  driver = Selenium::WebDriver.for :firefox
  driver.navigate.to 'http://bit.ly/watir-webdriver-demo'
  begin
    driver.find_element(:id, 'entry_0')
  rescue Selenium::WebDriver::Error::NoSuchElementError
    # doesn't exist
  end
  begin
    driver.find_element(:id, 'entry_99').displayed?
  rescue Selenium::WebDriver::Error::NoSuchElementError
    # doesn't exist
  end
  driver.find_element(:id, 'entry_0').clear
  driver.find_element(:id, 'entry_0').send_keys '1'
  driver.find_element(:id, 'entry_0').clear
  driver.find_element(:id, 'entry_0').send_keys '2'
  driver.find_element(:id, 'entry_1').find_element(:tag_name =&gt; 'option', :value =&gt; 'Ruby').click
  driver.find_element(:name, 'submit').click
  driver.quit
end

benchmark 'watir-webdriver' do
  require 'watir-webdriver'
  b = Watir::Browser.start 'bit.ly/watir-webdriver-demo', :firefox
  b.text_field(:id =&gt; 'entry_0').exists?
  b.text_field(:id =&gt; 'entry_99').exists?
  b.text_field(:id =&gt; 'entry_0').set '1'
  b.text_field(:id =&gt; 'entry_0').set '2'
  b.select_list(:id =&gt; 'entry_1').select 'Ruby'
  b.button(:name =&gt; 'submit').click
  b.close
end

benchmark 'capybara' do
  require 'capybara'
  session = Capybara::Session.new(:selenium)
  session.visit('http://bit.ly/watir-webdriver-demo')
  session.has_field?('entry_0') # =&gt; true
  session.has_no_field?('entry_99') # =&gt; true
  session.fill_in('entry_0', :with =&gt; '1')
  session.fill_in('entry_0', :with =&gt; '2')
  session.select('Ruby', :from =&gt; 'entry_1')
  session.click_button 'Submit'
  session.driver.quit
end

run 10
</pre></p>
<p>This is how long they took for me to run:</p>
<pre>                        user     system      total        real
selenium-webdriver  1.810000   0.840000  22.130000 ( 73.123340)
watir-webdriver     1.940000   0.870000  24.380000 ( 79.388494)
capybara            1.950000   0.890000  24.080000 ( 79.920051)</pre>
<p><strong>Note:</strong> Capybara doesn&#8217;t always require a &#8216;session&#8217;, it&#8217;s only for non <a href="http://en.wikipedia.org/wiki/Rack_%28web_server_interface%29">ruby rack applications</a>, but since my example (Google) is not a rack application, as are most of the applications I test, my example must use the session.</p>
<p><strong>When using ruby, why Watir-WebDriver is <em>my</em> sweet spot</strong></p>
<p>I <em>personally</em> find Watir-WebDriver to be the most elegant solution, as the API is high enough for me to be highly readable/usable, but low enough to be powerful and for me to feel like <em>I&#8217;m</em> in control.</p>
<p>For example, being able to select an element by a explicit identifier (name, class name, id, anything) is a huge deal to me. I personally don&#8217;t like relying on the API to determine which selector to use: for example Capybara only supports <em>name, id</em> and <em>label</em>, but you can&#8217;t tell <em>fill_in</em> which specific one to choose: it appears to try each selector one by one until it finds it.</p>
<p>I have found that Watir-WebDriver also also provides lots of flexibility/neatness. For example: it&#8217;s the only API shown here that allows URLs to not have a &#8216;http://&#8217; prefix (how many people do you know who type in http:// into a browser?).</p>
<p>In my opinion, the high level APIs like Capybara don&#8217;t provide enough <em>control</em> (for example &#8211; being able to specify the explicit selector), but the low level APIs like webdriver don&#8217;t provide enough <em>functionality</em>. This is evident when I am using a language other than ruby (like C#) when I find myself writing a large number of web element extension methods because webdriver doesn&#8217;t provide any of them. A <strong>.set</strong> method is a classic example, even Simon Stewart writes a <a href="http://code.google.com/p/selenium/wiki/LoadableComponent"><em>clearAndType</em></a> method in his examples even though he wrote webdriver which sadly misses it (you must call .clear, <strong>and</strong> .send_keys).</p>
<p><strong>My biggest concern about high level field APIs</strong></p>
<p>But my biggest issue with the high level APIs is that I&#8217;ve frequently seen them used to write test <strong>scripts</strong> that are step by step interactions with a web form. Instead of thinking of a business application as that, people see it as a series of forms that you &#8216;fill in&#8217;. This means people create scenarios like Aslak Hellesøy included in his <a href="http://aslakhellesoy.com/post/11055981222/the-training-wheels-came-off">recent post</a> about cucumber web steps (which uses Capybara) and the problems it has created.</p>
<pre>Scenario: Successful login
  Given a user "Aslak" with password "xyz"
  And I am on the login page
  And I fill in "User name" with "Aslak"
  And I fill in "Password" with "xyz"
  When I press "Log in"
  Then I should see "Welcome, Aslak"</pre>
<p>I&#8217;m not saying it&#8217;s not possible to end up with something as ugly as above using other APIs, but I am saying the web form DSL style naturally relates to this: as the APIs look so similar to this style because that&#8217;s what the DSL was designed for: filling in forms. I&#8217;ve seen people frequently write generic, reusable cucumber steps to match the web form DSL like:</p>
<p><pre class="brush: ruby;">
When /^I fill in &quot;(.+)&quot; with &quot;(.+)&quot;$/ do |value, field|
  fill_in field, :with =&gt; value
end
</pre></p>
<p>But this means you end up with less readable, less maintainable <a href="http://concordion.org/Technique.html"><strong>test scripts</strong></a> rather than business readable executable <strong>specifications</strong>.<br />
<strong></strong></p>
<p><strong>Summary</strong></p>
<p>Ultimately what I am looking for in an automated web testing API is simplicity <strong>and</strong> full control. I personally find browser APIs like Watir-WebDriver and Watir give me this, and this is why I love them so. Your mileage may vary, you may like different styles of APIs better, but I&#8217;ve seen other APIs so badly abused by people not even thinking about it, so it makes sense to think about what you&#8217;re trying to achieve and whether what you&#8217;re doing is the right way.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/watirmelon.wordpress.com/1171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/watirmelon.wordpress.com/1171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/watirmelon.wordpress.com/1171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/watirmelon.wordpress.com/1171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/watirmelon.wordpress.com/1171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/watirmelon.wordpress.com/1171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/watirmelon.wordpress.com/1171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/watirmelon.wordpress.com/1171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/watirmelon.wordpress.com/1171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/watirmelon.wordpress.com/1171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/watirmelon.wordpress.com/1171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/watirmelon.wordpress.com/1171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/watirmelon.wordpress.com/1171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/watirmelon.wordpress.com/1171/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=1171&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://watirmelon.com/2011/12/03/a-tale-of-three-ruby-automated-testing-apis-redux/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344eed26ff913de38b45620d18eed695?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">alisterscott</media:title>
		</media:content>

		<media:content url="http://watirmelon.files.wordpress.com/2011/12/threekindsofautomatedwebtestingapis.png" medium="image">
			<media:title type="html">ThreekindsofautomatedwebtestingAPIs</media:title>
		</media:content>
	</item>
		<item>
		<title>Introducing watirwebdriver.com: the most elegant way to use webdriver with ruby</title>
		<link>http://watirmelon.com/2011/08/18/introducing-watirwebdriver-com-the-most-elegant-way-to-use-webdriver-with-ruby/</link>
		<comments>http://watirmelon.com/2011/08/18/introducing-watirwebdriver-com-the-most-elegant-way-to-use-webdriver-with-ruby/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 10:11:47 +0000</pubDate>
		<dc:creator>Alister Scott</dc:creator>
				<category><![CDATA[Watir]]></category>
		<category><![CDATA[Watir-WebDriver]]></category>

		<guid isPermaLink="false">http://watirmelon.com/?p=1066</guid>
		<description><![CDATA[I have recently launched watirwebdriver.com: the most elegant way to use webdriver with ruby. It&#8217;s a collection of succinct examples of how to use watir-webdriver. I found it very enjoyable piecing together this information from various blog posts I have &#8230; <a href="http://watirmelon.com/2011/08/18/introducing-watirwebdriver-com-the-most-elegant-way-to-use-webdriver-with-ruby/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=1066&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have recently launched <a href="http://watirwebdriver.com">watirwebdriver.com</a>: the most elegant way to use webdriver with ruby. It&#8217;s a collection of succinct examples of how to use watir-webdriver. I found it very enjoyable piecing together this information from various blog posts I have written, and organizing it in a structured, logical manner. I hope you find it useful.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/watirmelon.wordpress.com/1066/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/watirmelon.wordpress.com/1066/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/watirmelon.wordpress.com/1066/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/watirmelon.wordpress.com/1066/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/watirmelon.wordpress.com/1066/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/watirmelon.wordpress.com/1066/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/watirmelon.wordpress.com/1066/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/watirmelon.wordpress.com/1066/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/watirmelon.wordpress.com/1066/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/watirmelon.wordpress.com/1066/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/watirmelon.wordpress.com/1066/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/watirmelon.wordpress.com/1066/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/watirmelon.wordpress.com/1066/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/watirmelon.wordpress.com/1066/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=1066&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://watirmelon.com/2011/08/18/introducing-watirwebdriver-com-the-most-elegant-way-to-use-webdriver-with-ruby/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344eed26ff913de38b45620d18eed695?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">alisterscott</media:title>
		</media:content>
	</item>
		<item>
		<title>Telling Watir-WebDriver to always locate elements upon use</title>
		<link>http://watirmelon.com/2011/08/14/telling-watir-webdriver-to-always-locate-elements-upon-use/</link>
		<comments>http://watirmelon.com/2011/08/14/telling-watir-webdriver-to-always-locate-elements-upon-use/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 04:42:53 +0000</pubDate>
		<dc:creator>Alister Scott</dc:creator>
				<category><![CDATA[Watir]]></category>
		<category><![CDATA[Watir-WebDriver]]></category>
		<category><![CDATA[WebDriver]]></category>

		<guid isPermaLink="false">http://watirmelon.com/?p=1059</guid>
		<description><![CDATA[One of the differences between Watir and Watir-WebDriver is how elements are located. Watir-WebDriver was designe to store references to DOM elements previously used, and this can cause the stale ObseleteElementError exception, as I explained previously. Watir-WebDriver 0.3.1 has recently &#8230; <a href="http://watirmelon.com/2011/08/14/telling-watir-webdriver-to-always-locate-elements-upon-use/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=1059&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the differences between Watir and Watir-WebDriver is how elements are located. Watir-WebDriver was designe to store references to DOM elements previously used, and this can cause the stale ObseleteElementError exception, as I <a title="Avoiding the dreaded Watir-WebDriver error: ObsoleteElementError: Element is no longer attached to the DOM" href="http://watirmelon.com/2011/08/02/watir-webdriver-obselete-element-error/">explained previously</a>.</p>
<p><a href="http://rubygems.org/gems/watir-webdriver">Watir-WebDriver 0.3.1</a> has recently been released, and now there is a configurable option to specify that you always want to create a fresh reference when using an element.</p>
<pre><code> Watir::always_locate = true b = Watir::Browser.new </code></pre>
<p>This will result in a performance hit, but in my experience, it isn&#8217;t too bad. Jari Bakken ran WatirSpec using this config which resulted in a 10 second increase in running time (from 145 seconds to 155 seconds) which in my opinion is worth it to have more reliable test results.</p>
<p>Thanks to Jari for working on this. Hope you enjoy.</p>
<p><strong>Update: 15 August 2011:</strong> I only just realized this is enabled by default, so you&#8217;ll get it automatically when you update your gem. Neat.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/watirmelon.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/watirmelon.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/watirmelon.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/watirmelon.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/watirmelon.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/watirmelon.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/watirmelon.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/watirmelon.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/watirmelon.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/watirmelon.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/watirmelon.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/watirmelon.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/watirmelon.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/watirmelon.wordpress.com/1059/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=1059&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://watirmelon.com/2011/08/14/telling-watir-webdriver-to-always-locate-elements-upon-use/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344eed26ff913de38b45620d18eed695?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">alisterscott</media:title>
		</media:content>
	</item>
		<item>
		<title>Avoiding the dreaded Watir-WebDriver error: ObsoleteElementError: Element is no longer attached to the DOM</title>
		<link>http://watirmelon.com/2011/08/02/watir-webdriver-obselete-element-error/</link>
		<comments>http://watirmelon.com/2011/08/02/watir-webdriver-obselete-element-error/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 12:13:14 +0000</pubDate>
		<dc:creator>Alister Scott</dc:creator>
				<category><![CDATA[Watir]]></category>
		<category><![CDATA[Watir-WebDriver]]></category>
		<category><![CDATA[Element is no longer attached to the DOM]]></category>
		<category><![CDATA[ObseleteElementError]]></category>
		<category><![CDATA[Selenium::WebDriver::Error::ObsoleteElementError]]></category>
		<category><![CDATA[Selenium::WebDriver::Error::ObsoleteElementError: Element is no longer attached to the DOM]]></category>

		<guid isPermaLink="false">http://watirmelon.com/?p=1019</guid>
		<description><![CDATA[I&#8217;ve been using Watir-WebDriver to create a a number of large suites of automated tests, and I&#8217;ve found that as others start to contribute tests, I am seeing the following exception happening quite frequently: Now, it&#8217;s quite annoying when this &#8230; <a href="http://watirmelon.com/2011/08/02/watir-webdriver-obselete-element-error/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=1019&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://watirmelon.com/2010/12/14/watir-webdriver-a-detailed-introduction/">Watir-WebDriver</a> to create a a number of large suites of automated tests, and I&#8217;ve found that as others start to contribute tests, I am seeing the following exception happening quite frequently:</p>
<p><pre class="brush: plain; light: true;">
Selenium::WebDriver::Error::ObsoleteElementError: Element is no longer attached to the DOM
</pre></p>
<p>Now, it&#8217;s quite annoying when this happens, and it&#8217;s not consistent, but I will try to explain what is happening and how you can try to avoid it.</p>
<p>As Jari Bakken <a href="https://groups.google.com/d/topic/watir-general/WhwpPvzHWmM/discussion">explains</a> on the Watir mailing list, in vanilla Watir, when you define an element, the details of <strong>how</strong> to locate an element are stored, and the actual finding is done when you need to use the element.</p>
<p>This is dramatically different to Watir-WebDriver that stores an <strong>reference to the actual DOM element</strong>, so if this changes (the page refreshes or JavaScript updates the DOM for example) then the exception above is raised.</p>
<p>I&#8217;ve found there&#8217;s a couple of ways to reduce, but not entirely eliminate, the chance of these exceptions being raised. The main idea is to avoid looping over DOM elements, especially when the pages you are testing have a lot of heavy JavaScript.</p>
<p>Instead of looping over the elements like this:</p>
<p><pre class="brush: ruby; light: true;">
browser.links.each do |link|
  link.click
  browser.goto home
end
</pre></p>
<p>I have found it&#8217;s better to collect the hrefs of each, and use these collected values:</p>
<p><pre class="brush: ruby; light: true;">
links = browser.links.collect { |link| link.href }
links.each do |link|
  browser.goto link
  browser.goto home
end
</pre></p>
<p>Instead of looping through a element collection to find some element value:</p>
<p><pre class="brush: ruby; light: true;">
def error_exists? text
  errors = browser.spans(:class =&gt; 'error').collect

  errors.each do |span|
    return true if span.text == text
  end
  false
end
</pre></p>
<p>I have found it is better to directly find the element itself</p>
<p><pre class="brush: ruby; light: true;">
def error_exists? text
  browser.span(:class =&gt; 'error', :text =&gt; text).when_present.exists?
end
</pre></p>
<p><strong>Summary<br />
</strong></p>
<p>The <em>ObseleteElementError</em> is a definitely a pain, but unless the entire approach to locating elements in Watir-Webdriver is changed, there is at least some way I have shown to minimize the pain.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/watirmelon.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/watirmelon.wordpress.com/1019/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/watirmelon.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/watirmelon.wordpress.com/1019/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/watirmelon.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/watirmelon.wordpress.com/1019/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/watirmelon.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/watirmelon.wordpress.com/1019/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/watirmelon.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/watirmelon.wordpress.com/1019/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/watirmelon.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/watirmelon.wordpress.com/1019/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/watirmelon.wordpress.com/1019/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/watirmelon.wordpress.com/1019/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=1019&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://watirmelon.com/2011/08/02/watir-webdriver-obselete-element-error/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344eed26ff913de38b45620d18eed695?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">alisterscott</media:title>
		</media:content>
	</item>
		<item>
		<title>Sending special keys to Watir-WebDriver</title>
		<link>http://watirmelon.com/2011/07/19/sending-special-keys-to-watir-webdriver/</link>
		<comments>http://watirmelon.com/2011/07/19/sending-special-keys-to-watir-webdriver/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 05:13:35 +0000</pubDate>
		<dc:creator>Alister Scott</dc:creator>
				<category><![CDATA[Watir]]></category>
		<category><![CDATA[Watir-WebDriver]]></category>
		<category><![CDATA[send_keys]]></category>
		<category><![CDATA[special_keys]]></category>

		<guid isPermaLink="false">http://watirmelon.com/?p=998</guid>
		<description><![CDATA[In vanilla Watir, if you wanted to send an enter key to a Watir browser, you&#8217;d do something like this: browser.send_keys("{ENTER}") To do the same thing in Watir-WebDriver, you do this: browser.send_keys :enter You can also do things like this: &#8230; <a href="http://watirmelon.com/2011/07/19/sending-special-keys-to-watir-webdriver/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=998&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In vanilla Watir, if you wanted to send an enter key to a Watir browser, you&#8217;d do something like this:</p>
<pre><code> browser.send_keys("{ENTER}") </code></pre>
<p>To do the same thing in Watir-WebDriver, you do this:</p>
<pre><code> browser.send_keys :enter </code></pre>
<p>You can also do things like this:</p>
<pre><code>browser.element.send_keys [:control, 'a'], :backspace</code></pre>
<p>The full list of keys are available from <a href="http://code.google.com/p/selenium/source/browse/trunk/rb/lib/selenium/webdriver/common/keys.rb">here</a>:</p>
<ul>
<li>:null</li>
<li>:cancel</li>
<li>:help</li>
<li>:backspace</li>
<li>:tab</li>
<li>:clear</li>
<li>:return</li>
<li>:enter</li>
<li>:shift</li>
<li>:left_shift</li>
<li>:control</li>
<li>:left_control</li>
<li>:alt</li>
<li>:left_alt</li>
<li>:pause</li>
<li>:escape</li>
<li>:space</li>
<li>:page_up</li>
<li>:page_down</li>
<li>:end</li>
<li>:home</li>
<li>:left</li>
<li>:arrow_left</li>
<li>:up</li>
<li>:arrow_up</li>
<li>:right</li>
<li>:arrow_right</li>
<li>:down</li>
<li>:arrow_down</li>
<li>:insert</li>
<li>:delete</li>
<li>:semicolon</li>
<li>:equals</li>
<li>:numpad0</li>
<li>:numpad1</li>
<li>:numpad2</li>
<li>:numpad3</li>
<li>:numpad4</li>
<li>:numpad5</li>
<li>:numpad6</li>
<li>:numpad7</li>
<li>:numpad8</li>
<li>:numpad9</li>
<li>:multiply</li>
<li>:add</li>
<li>:separator</li>
<li>:subtract</li>
<li>:decimal</li>
<li>:divide</li>
<li>:f1</li>
<li>:f2</li>
<li>:f3</li>
<li>:f4</li>
<li>:f5</li>
<li>:f6</li>
<li>:f7</li>
<li>:f8</li>
<li>:f9</li>
<li>:f10</li>
<li>:f11</li>
<li>:f12</li>
<li>:meta</li>
<li>:command</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/watirmelon.wordpress.com/998/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/watirmelon.wordpress.com/998/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/watirmelon.wordpress.com/998/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/watirmelon.wordpress.com/998/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/watirmelon.wordpress.com/998/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/watirmelon.wordpress.com/998/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/watirmelon.wordpress.com/998/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/watirmelon.wordpress.com/998/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/watirmelon.wordpress.com/998/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/watirmelon.wordpress.com/998/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/watirmelon.wordpress.com/998/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/watirmelon.wordpress.com/998/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/watirmelon.wordpress.com/998/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/watirmelon.wordpress.com/998/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=998&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://watirmelon.com/2011/07/19/sending-special-keys-to-watir-webdriver/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344eed26ff913de38b45620d18eed695?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">alisterscott</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the super-duper ChromeDriver with Watir-WebDriver (updated)</title>
		<link>http://watirmelon.com/2011/07/08/using-the-super-duper-chromedriver-with-watir-webdriver/</link>
		<comments>http://watirmelon.com/2011/07/08/using-the-super-duper-chromedriver-with-watir-webdriver/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 11:30:48 +0000</pubDate>
		<dc:creator>Alister Scott</dc:creator>
				<category><![CDATA[Watir]]></category>
		<category><![CDATA[Watir-WebDriver]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[chromedriver]]></category>
		<category><![CDATA[Google Chrome]]></category>
		<category><![CDATA[webdriver]]></category>

		<guid isPermaLink="false">http://watirmelon.com/?p=889</guid>
		<description><![CDATA[Updated 8 July with new information about the new ChromeDriver from the Chromium Site Anyone who has used Watir-WebDriver (or WebDriver for that matter) to test Google Chrome will know that it&#8217;s been pretty unreliable, and pretty much unusable in &#8230; <a href="http://watirmelon.com/2011/07/08/using-the-super-duper-chromedriver-with-watir-webdriver/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=889&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Updated 8 July with new information about the new ChromeDriver from the <a href="http://code.google.com/p/chromium/downloads/list">Chromium Site</a></strong></p>
<p>Anyone who has used Watir-WebDriver (or WebDriver for that matter) to test Google Chrome will know that it&#8217;s been pretty unreliable, and pretty much unusable in the past&#8230; until now.</p>
<p>The ChromeDriver executable was released recently which enables WebDriver to control Google Chrome <em>natively</em> using the Wire protocol. This means your Watir-WebDriver tests will run super fast, and super reliably.</p>
<p><strong>For Mac OSX:</strong></p>
<ol>
<li>Get the latest Watir-WebDriver gem
<pre><code>gem update watir-webdriver</code></pre>
</li>
<li>Download the ChromeDriver binary from the <a href="http://code.google.com/p/chromium/downloads/list">Chromium site</a>, and copy it to your path (such as /usr/local/bin/)</li>
<li>This will work with any current version of Chrome</li>
<li>Change your Watir-WebDriver script to use <strong><code>Watir::Browser.new :chrome</code></strong> and voila, super fast Chrome, with no weird first tab opened in the background. This is the key to tell if you&#8217;re doing it right, your app should appear in the <em>first</em> tab of Chrome, not the second.</li>
</ol>
<p>I haven&#8217;t done this on Windows yet, so your mileage may vary, but I imagine it wouldn&#8217;t be too different.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/watirmelon.wordpress.com/889/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/watirmelon.wordpress.com/889/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/watirmelon.wordpress.com/889/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/watirmelon.wordpress.com/889/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/watirmelon.wordpress.com/889/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/watirmelon.wordpress.com/889/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/watirmelon.wordpress.com/889/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/watirmelon.wordpress.com/889/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/watirmelon.wordpress.com/889/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/watirmelon.wordpress.com/889/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/watirmelon.wordpress.com/889/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/watirmelon.wordpress.com/889/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/watirmelon.wordpress.com/889/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/watirmelon.wordpress.com/889/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=889&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://watirmelon.com/2011/07/08/using-the-super-duper-chromedriver-with-watir-webdriver/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344eed26ff913de38b45620d18eed695?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">alisterscott</media:title>
		</media:content>
	</item>
		<item>
		<title>Removing local page references from Cucumber steps</title>
		<link>http://watirmelon.com/2011/06/07/removing-local-page-references-from-cucumber-steps/</link>
		<comments>http://watirmelon.com/2011/06/07/removing-local-page-references-from-cucumber-steps/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 07:18:49 +0000</pubDate>
		<dc:creator>Alister Scott</dc:creator>
				<category><![CDATA[Automated Testing]]></category>
		<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Test Automation]]></category>
		<category><![CDATA[Watir]]></category>
		<category><![CDATA[Watir-WebDriver]]></category>
		<category><![CDATA[page objects]]></category>
		<category><![CDATA[page object models]]></category>

		<guid isPermaLink="false">http://watirmelon.com/?p=931</guid>
		<description><![CDATA[I&#8217;ve been giving some thought about the maintainability of having local page object model references in Cucumber steps. To explain what I mean, here&#8217;s some code of mine from an Etsy page model step: Here I am using instance variables &#8230; <a href="http://watirmelon.com/2011/06/07/removing-local-page-references-from-cucumber-steps/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=931&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been giving some thought about the maintainability of having local page object model references in Cucumber steps. To explain what I mean, here&#8217;s some code of mine from an Etsy page model step:</p>
<p><pre class="brush: ruby;">
When /^an item is added to the cart$/ do
  @advanced_search_page = EtsyAdvancedSearchPage.new @browser, true
  @search_results_page = @advanced_search_page.search_for 'hat'
  @etsy_item_page = @search_results_page.click_first_result
  @item_title = @etsy_item_page.item_title
  @etsy_cart_page = @etsy_item_page.click_add_to_cart
end
</pre></p>
<p>Here I am using instance variables in Cucumber steps to store references to pages that I am interacting with. As you can see, it&#8217;s quite easy to lose track of which page is which.</p>
<p>If I want to use one of these pages in another step, I have to refer to the same variable name. The key to this concept is having pages return pages, so you don&#8217;t have to initialize pages in your steps (except for the first visit, which normally happens only once per scenario).</p>
<p>A <a href="http://mark.ryall.name/blog/">colleague and good friend of mine</a> has been showing me some alternatives. One alternative to this is to actually dynamically refer to pages only when you need them. This means you don&#8217;t need to return a page from a page, as they are always initialized when needed. The above method would look like:</p>
<p><pre class="brush: ruby;">
When /^an item is added to the cart$/ do
  visit EtsyAdvancedSearchPage do |page| page.search_for 'hat' end
  on EtsySearchResultsPage do |page| page.click_first_result end
  on EtsyItemPage do |page|
    @item_title = page.item_title
    page.click_add_to_cart
  end
end
</pre></p>
<p>This introduces two new methods at the Cucumber step level that need to be created: <em>on</em>, and <em>visit</em>. The <em>on</em> method simply creates a new page object so you can call methods from it. As each page initialize checks expected title and expected element, it will raise an error automatically if either are incorrect. The <em>visit</em> method is an extension of on, which actually initalizes the page and visits it.</p>
<p>These are defined as a module in our Cucumber <em>env.rb</em> file, and then mixed into the Cucumber World, so that steps <em>automatically</em> have access to these.</p>
<p><pre class="brush: ruby;">
module Browser
  BROWSER = Watir::Browser.new ENV['WEB_DRIVER'] ||:firefox

  def visit page_class, &amp;block
    on page_class, true, &amp;block
  end

  def on page_class, visit=false, &amp;block
    page = page_class.new BROWSER, visit
    block.call page if block
    page
  end
end

World Browser
</pre></p>
<p><strong>Summary</strong></p>
<p>By introducing the on and visit methods, it means that we no longer need to have instance variables for page classes in our Cucumber steps. We also no longer need to worry about state transformations in pages, as these can be done in a modular way in the steps themselves. It means that when an error occurs initializing a page, it is more likely to to occur in the correct place. I find the steps more readible, as you only have to initialize the page once using the <em>on</em> block, and then can refer to <em>page</em>.</p>
<p>I have updated my set of Etsy Watir-WebDriver steps if you&#8217;d like to <a href="https://github.com/alisterscott/EtsyWatirWebDriver/blob/master/features/step_definitions/etsy_steps.rb">take a look</a>.</p>
<p>What do you think? How will this scale?</p>
<p><strong>Update:</strong> I have <a href="https://github.com/alisterscott/WatirMelonCucumber/commit/47f6d611057faa1106026ea2d22ce89f7483026c">updated</a> the <a href="https://github.com/alisterscott/WatirMelonCucumber">WatirMelonCucumber</a> project to use this style. It&#8217;s slightly different in that it supports two sites, and therefore the <em>on</em> method dynamically switches between these.</p>
<p>Cucumber Steps:</p>
<p><pre class="brush: ruby;">
When /^I search for a? ?&quot;([^&quot;]*)&quot;$/ do |term|
  on :home do |page|
    page.search_for term
  end
end
</pre></p>
<p>The <em>on</em> method:</p>
<p><pre class="brush: ruby;">
def on page, visit=false, &amp;block
  page_class = Object.const_get &quot;#{@site}#{page.capitalize}Page&quot;
  page = page_class.new BROWSER, visit
  block.call page if block
  page
end
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/watirmelon.wordpress.com/931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/watirmelon.wordpress.com/931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/watirmelon.wordpress.com/931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/watirmelon.wordpress.com/931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/watirmelon.wordpress.com/931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/watirmelon.wordpress.com/931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/watirmelon.wordpress.com/931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/watirmelon.wordpress.com/931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/watirmelon.wordpress.com/931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/watirmelon.wordpress.com/931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/watirmelon.wordpress.com/931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/watirmelon.wordpress.com/931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/watirmelon.wordpress.com/931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/watirmelon.wordpress.com/931/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=931&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://watirmelon.com/2011/06/07/removing-local-page-references-from-cucumber-steps/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344eed26ff913de38b45620d18eed695?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">alisterscott</media:title>
		</media:content>
	</item>
		<item>
		<title>Introducing the Watir Page Helper gem</title>
		<link>http://watirmelon.com/2011/05/05/introducing-the-watir-page-helper-gem/</link>
		<comments>http://watirmelon.com/2011/05/05/introducing-the-watir-page-helper-gem/#comments</comments>
		<pubDate>Thu, 05 May 2011 12:28:07 +0000</pubDate>
		<dc:creator>Alister Scott</dc:creator>
				<category><![CDATA[ATDD]]></category>
		<category><![CDATA[Automated Testing]]></category>
		<category><![CDATA[Watir]]></category>
		<category><![CDATA[Watir-WebDriver]]></category>
		<category><![CDATA[page objects]]></category>
		<category><![CDATA[watir helper]]></category>
		<category><![CDATA[watir-page-helper]]></category>

		<guid isPermaLink="false">http://watirmelon.com/?p=912</guid>
		<description><![CDATA[I&#8217;ve very recently released a watir-page-helper gem that provides some useful helper methods when creating page models when using Watir-WebDriver (I chose not to support Watir as it doesn&#8217;t work on Firefox 4, therefore not on non-Windows machines). This is &#8230; <a href="http://watirmelon.com/2011/05/05/introducing-the-watir-page-helper-gem/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=912&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve very recently released a watir-page-helper gem that provides some useful helper methods when creating page models when using Watir-WebDriver (I chose not to support Watir as it doesn&#8217;t work on Firefox 4, therefore not on non-Windows machines).</p>
<p>This is loosely based upon the great work that Jeff Morgan did in his series of <a href="http://www.cheezyworld.com/2010/12/16/ui-tests-putting-it-all-together/">UI testing blog posts</a>, but takes the concept a lot further IMO.</p>
<p>I wanted it to be solid before I released it as a gem, so I wrote unit tests for every method, and wrote yard tagged documentation for each method also. You can see the documentation automatically generated on <a href="http://rdoc.info/gems/watir-page-helper/0.1.0/frames">rdoc.info</a>.</p>
<p><strong>Installation</strong></p>
<pre><code>gem install watir-page-helper</code></pre>
<p><strong>Example</strong></p>
<p><pre class="brush: ruby;">
require 'watir-webdriver'
require 'watir-page-helper'

class MyPage
  include WatirPageHelper

  direct_url &quot;http://www.google.com&quot;
  expected_element :text_field, :name =&gt; &quot;q&quot;
  expected_title &quot;Google&quot;
  text_field :search_box, :name =&gt; &quot;q&quot;
  button :search, :name =&gt; &quot;btnG&quot;

  def initialize browser, visit = false
    @browser = browser
    goto if visit

    expected_element if respond_to? :expected_element
    has_expected_title? if respond_to? :has_expected_title?
  end
end

browser = Watir::Browser.new :chrome
page = MyPage.new browser, true
page.search_box = &quot;Watirmelon&quot; #This method is created by WatirPageHelper
page.search #This method is created by WatirPageHelper also
browser.close
</pre></p>
<p>The above example is very basic, but shows the concept well. You&#8217;re much better off putting the initialize method into a base page class so you don&#8217;t need to call the same methods for every page.</p>
<p><strong>What you get</strong></p>
<p><strong>Page Methods</strong></p>
<ul>
<li><strong>direct_url:</strong> allows you to navigate to a page upon initialization, if visit is set to true</li>
<li><strong>expected_title:</strong> allows you to automatically assert the expected title of the page when it is initialized</li>
<li><strong>expected_element:</strong> allows you to initialize the page by looking for a certain element. This is useful for pages that load dynamic content.</li>
</ul>
<p><strong>Element Methods</strong></p>
<p>Element methods for a majority of the Watir-WebDriver supported elements which generate useful helper methods.<br />
For example: text_field, select_list, radio_button, form, div, span, h1..h6 etc.</p>
<p><strong>Summary</strong></p>
<p>I&#8217;ve been using a watir page helper on a few different projects now and I&#8217;m sick of copy-and-pasting the code each time, so I thought it&#8217;d be nice to package it as a gem.</p>
<p>I also think it&#8217;s important to have unit tests for this kind of stuff, so it was a good opportunity to write unit tests for every method in these classes. The documentation was an added bonus too.</p>
<p>I hope you find this useful, please let me know if anything doesn&#8217;t make any sense.</p>
<p><strong>Links/Further Info<br />
</strong></p>
<ul>
<li>The <a href="https://github.com/alisterscott/watir-page-helper">source code</a> on github</li>
<li>The <a href="https://rubygems.org/gems/watir-page-helper">gem</a> on rubygems.org.</li>
<li>The <a href="http://rdoc.info/gems/watir-page-helper/0.1.0/frames">rdoc documentation</a> for each method on rdoc.info.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/watirmelon.wordpress.com/912/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/watirmelon.wordpress.com/912/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/watirmelon.wordpress.com/912/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/watirmelon.wordpress.com/912/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/watirmelon.wordpress.com/912/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/watirmelon.wordpress.com/912/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/watirmelon.wordpress.com/912/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/watirmelon.wordpress.com/912/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/watirmelon.wordpress.com/912/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/watirmelon.wordpress.com/912/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/watirmelon.wordpress.com/912/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/watirmelon.wordpress.com/912/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/watirmelon.wordpress.com/912/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/watirmelon.wordpress.com/912/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=912&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://watirmelon.com/2011/05/05/introducing-the-watir-page-helper-gem/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344eed26ff913de38b45620d18eed695?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">alisterscott</media:title>
		</media:content>
	</item>
		<item>
		<title>Watir-WebDriver &amp; Cucumber Examples for Etsy.com</title>
		<link>http://watirmelon.com/2011/04/23/watir-webdriver-etsy/</link>
		<comments>http://watirmelon.com/2011/04/23/watir-webdriver-etsy/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 12:37:52 +0000</pubDate>
		<dc:creator>Alister Scott</dc:creator>
				<category><![CDATA[ATDD]]></category>
		<category><![CDATA[Automated Testing]]></category>
		<category><![CDATA[Watir]]></category>
		<category><![CDATA[Watir-WebDriver]]></category>
		<category><![CDATA[WebDriver]]></category>
		<category><![CDATA[etsy]]></category>
		<category><![CDATA[Etsy.com]]></category>
		<category><![CDATA[watir-webdriver]]></category>

		<guid isPermaLink="false">http://watirmelon.com/?p=884</guid>
		<description><![CDATA[I&#8217;ve had a go at implementing my Etsy.com gherkin scenarios using Watir-WebDriver in Ruby rather than C#. I like the flexibility of dynamic languages like Ruby, but I tend to make more silly mistakes that are picked up straight away &#8230; <a href="http://watirmelon.com/2011/04/23/watir-webdriver-etsy/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=884&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve  had a go at implementing my <a href="http://watirmelon.com/2011/04/21/specdriver-now-includes-etsy-com-examples/">Etsy.com gherkin scenarios</a> using Watir-WebDriver in Ruby rather than C#. I like the flexibility of dynamic languages like Ruby, but I tend to make more silly mistakes that are picked up straight away when I am writing static typed code like C#, but I guess that&#8217;s the downside to dynamic languages, less error checking built into IDEs due to the flexibility the language offers.</p>
<p>You can check out and download my ruby code on my <a href="https://github.com/alisterscott/EtsyWatirWebDriver">Github project page</a>.</p>
<p><img src="http://watirmelon.files.wordpress.com/2011/04/etsywatirwebdriverresults.png?w=584" alt="" title="etsywatirwebdriverresults"   class="alignnone size-full wp-image-885" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/watirmelon.wordpress.com/884/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/watirmelon.wordpress.com/884/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/watirmelon.wordpress.com/884/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/watirmelon.wordpress.com/884/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/watirmelon.wordpress.com/884/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/watirmelon.wordpress.com/884/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/watirmelon.wordpress.com/884/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/watirmelon.wordpress.com/884/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/watirmelon.wordpress.com/884/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/watirmelon.wordpress.com/884/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/watirmelon.wordpress.com/884/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/watirmelon.wordpress.com/884/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/watirmelon.wordpress.com/884/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/watirmelon.wordpress.com/884/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=884&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://watirmelon.com/2011/04/23/watir-webdriver-etsy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:thumbnail url="http://watirmelon.files.wordpress.com/2011/04/etsy-automated-test-results.png?w=150" />
		<media:content url="http://watirmelon.files.wordpress.com/2011/04/etsy-automated-test-results.png?w=150" medium="image">
			<media:title type="html">Etsy Automated Test Results</media:title>
		</media:content>

		<media:content url="http://1.gravatar.com/avatar/344eed26ff913de38b45620d18eed695?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">alisterscott</media:title>
		</media:content>

		<media:content url="http://watirmelon.files.wordpress.com/2011/04/etsywatirwebdriverresults.png" medium="image">
			<media:title type="html">etsywatirwebdriverresults</media:title>
		</media:content>
	</item>
		<item>
		<title>Watir Day 2011 San Francisco: My Takeaways</title>
		<link>http://watirmelon.com/2011/04/07/watir-day-2011-san-francisco-my-takeaways/</link>
		<comments>http://watirmelon.com/2011/04/07/watir-day-2011-san-francisco-my-takeaways/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 18:24:45 +0000</pubDate>
		<dc:creator>Alister Scott</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Watir]]></category>
		<category><![CDATA[san francisco]]></category>
		<category><![CDATA[Selenium Conference]]></category>
		<category><![CDATA[watir day]]></category>
		<category><![CDATA[Watir Day 2011]]></category>

		<guid isPermaLink="false">http://watirmelon.com/?p=855</guid>
		<description><![CDATA[Watir Day 2011 in San Francisco was a great success. I personally took a lot away from the day including: We organized and promoted Watir Day in a very lightweight way, but managed to attract over 60 attendees and 10 &#8230; <a href="http://watirmelon.com/2011/04/07/watir-day-2011-san-francisco-my-takeaways/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=855&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://watir.com/watir-day">Watir Day 2011</a> in San Francisco was a great success. I personally took a lot away from the day including:</p>
<ul>
<li>We organized and promoted Watir Day in a very lightweight way, but managed to attract over 60 attendees and 10 sponsors!</li>
<li>The key to Watir&#8217;s success has been its community, focus on building a tool for testers, and not trying to be everything to everyone.</li>
<li>Watir is seen as a secret sauce for a lot of web companies &#8211; they are very hesitant to talk about it publically in case their competitors copy them. But we managed to hear a few of those stories for the first time on the day:
<ul>
<li>Watir is a key part of Facebook&#8217;s engineering culture: they have been extremely successful with Watir, after failing with Selenium.</li>
<li>Convio has been so successful with in house open source test automation using Watir that they have phased out outsourced testing altogether, and are hiring more automated test engineers than ever.</li>
</ul>
</li>
<li>An individual&#8217;s involvement in an open source project can be inversely proportional to how happy they are in their job &#8211; not happy at work = less commits, more happy at work = less commits (via Bret Pettichord)</li>
<li>The future is bright for Watir. Using WebDriver technology will enable us to deliver a tool designed for testers to testers, but an increasing range of browser and device support.</li>
</ul>
<p>The <a href="http://watir.com/2011/04/06/watir-day-2011-questionnaire-results/">questionnaire results</a> speak for themselves:</p>
<p><img class="alignnone size-full wp-image-860" title="Watir Day Fun" src="http://watirmelon.files.wordpress.com/2011/04/watir-day-fun.png?w=584" alt="Watir Day Fun"   /></p>
<p>The slides <a href="http://wiki.openqa.org/display/WTR/Watir+Day+Presentations">are available online</a>.</p>
<p><img class="alignnone size-full wp-image-856" title="MarekJ at Watir Day" src="http://watirmelon.files.wordpress.com/2011/04/marekj-at-watir-day.jpg?w=584" alt="MarekJ at Watir Day"   /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/watirmelon.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/watirmelon.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/watirmelon.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/watirmelon.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/watirmelon.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/watirmelon.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/watirmelon.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/watirmelon.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/watirmelon.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/watirmelon.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/watirmelon.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/watirmelon.wordpress.com/855/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/watirmelon.wordpress.com/855/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/watirmelon.wordpress.com/855/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=watirmelon.com&amp;blog=2177915&amp;post=855&amp;subd=watirmelon&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://watirmelon.com/2011/04/07/watir-day-2011-san-francisco-my-takeaways/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/344eed26ff913de38b45620d18eed695?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">alisterscott</media:title>
		</media:content>

		<media:content url="http://watirmelon.files.wordpress.com/2011/04/watir-day-fun.png" medium="image">
			<media:title type="html">Watir Day Fun</media:title>
		</media:content>

		<media:content url="http://watirmelon.files.wordpress.com/2011/04/marekj-at-watir-day.jpg" medium="image">
			<media:title type="html">MarekJ at Watir Day</media:title>
		</media:content>
	</item>
	</channel>
</rss>
