<?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>Selenium Testing? Do Cross Browser Testing with Sauce Labs &#187; rspec</title>
	<atom:link href="http://saucelabs.com/blog/index.php/tag/rspec/feed/" rel="self" type="application/rss+xml" />
	<link>http://saucelabs.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 10 May 2012 17:20:37 +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>Video Demo: RSpec + Selenium + Sauce OnDemand</title>
		<link>http://saucelabs.com/blog/index.php/2010/10/video-demo-rspec-selenium-sauce-ondemand/</link>
		<comments>http://saucelabs.com/blog/index.php/2010/10/video-demo-rspec-selenium-sauce-ondemand/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 18:14:53 +0000</pubDate>
		<dc:creator>Ashley Wilson</dc:creator>
				<category><![CDATA[Webinars]]></category>
		<category><![CDATA[Cross Browser]]></category>
		<category><![CDATA[parallel testing]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Sauce Labs]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://saucelabs.com/blog/?p=2026</guid>
		<description><![CDATA[Thanks to all who tuned in to our live web demo last week, Using RSpec + Selenium to Test Your Ruby Builds Faster. Sauce Labs Developer Sean Grove walked attendees through the steps of writing an RSpec test and using it with Selenium, and then showed how to run that test across multiple browsers in [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to all who tuned in to our live web demo last week, <strong>Using RSpec + Selenium to Test Your Ruby Builds Faster</strong>. <a href="http://saucelabs.com">Sauce Labs</a> Developer Sean Grove walked attendees through the steps of writing an RSpec test and using it with Selenium, and then showed how to run that test across multiple browsers in the cloud using <a href="http://saucelabs.com/ondemand">Sauce OnDemand</a>.</p>
<p>For those of you who missed it, check out Sean&#8217;s sample code on Github (<a href="http://github.com/sgrove/rspec_sauce_webinar">http://github.com/sgrove/rspec_sauce_webinar</a>), and then follow along with the video below. We&#8217;re planning another Ruby-based webinar in the future, so make sure to subscribe to our blog&#8217;s <a href="http://saucelabs.com/blog/index.php/feed/">RSS feed</a> to stay up to date!</p>
<p><iframe src="http://www.youtube.com/embed/cN1gBjrKy3U" frameborder="0" width="475" height="375"></iframe></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsaucelabs.com%2Fblog%2Findex.php%2F2010%2F10%2Fvideo-demo-rspec-selenium-sauce-ondemand%2F&amp;title=Video%20Demo%3A%20RSpec%20%2B%20Selenium%20%2B%20Sauce%20OnDemand" id="wpa2a_2"><img src="http://saucelabs.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://saucelabs.com/blog/index.php/2010/10/video-demo-rspec-selenium-sauce-ondemand/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSpec + Selenium Demonstration 9/30 at 11 am PST</title>
		<link>http://saucelabs.com/blog/index.php/2010/09/rspec-selenium-demonstration-930-at-11-am-pst/</link>
		<comments>http://saucelabs.com/blog/index.php/2010/09/rspec-selenium-demonstration-930-at-11-am-pst/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 18:55:37 +0000</pubDate>
		<dc:creator>Ashley Wilson</dc:creator>
				<category><![CDATA[Webinars]]></category>
		<category><![CDATA[Cloud]]></category>
		<category><![CDATA[Cross Browser]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://saucelabs.com/blog/?p=1880</guid>
		<description><![CDATA[Join Sean Grove, senior developer at Sauce Labs, as he shows you how to take your RSpec tests and pit &#8216;em against the real world. RSpec is a Ruby framework that provides a Domain Specific Language that expresses executable examples of the expected behavior of your code. Learn how to launch and control real browsers [...]]]></description>
			<content:encoded><![CDATA[<p>Join Sean Grove, senior developer at <a href="http://saucelabs.com">Sauce Labs</a>, as he shows you how to take your RSpec tests and pit &#8216;em against the real world. RSpec is a Ruby framework that provides a Domain Specific Language that expresses executable examples of the expected behavior of your code.</p>
<p>Learn how to launch and control real browsers directly from RSpec tests using Selenium and <a href="http://saucelabs.com/ondemand">Sauce OnDemand</a>. In this<a href="https://www1.gotomeeting.com/register/330418728"> live video demontration</a> on Sept. 30 at 11 am PST, he&#8217;ll demonstrate and discuss:</p>
<p>    * Writing your first RSpec test<br />
    * Configuring it to use Selenium<br />
    * Cross-browser testing and spec parallelization</p>
<p>Be sure to stick around for the Q&#038;A following the presentation. <a href="https://www1.gotomeeting.com/register/330418728">Register Here!</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsaucelabs.com%2Fblog%2Findex.php%2F2010%2F09%2Frspec-selenium-demonstration-930-at-11-am-pst%2F&amp;title=RSpec%20%2B%20Selenium%20Demonstration%209%2F30%20at%2011%20am%20PST" id="wpa2a_4"><img src="http://saucelabs.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://saucelabs.com/blog/index.php/2010/09/rspec-selenium-demonstration-930-at-11-am-pst/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running Selenium RSpec tests for Rails 2.3.5</title>
		<link>http://saucelabs.com/blog/index.php/2010/02/running-selenium-tests-for-rails/</link>
		<comments>http://saucelabs.com/blog/index.php/2010/02/running-selenium-tests-for-rails/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 20:03:24 +0000</pubDate>
		<dc:creator>The Sauce Labs Team</dc:creator>
				<category><![CDATA[Selenium Knowledge]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[rspec-rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://saucelabs.com/blog/?p=349</guid>
		<description><![CDATA[This article will get you setup with the bare-minimum environment to run Selenium tests with RSpec, for automated, full-stack testing of Rails apps. Once that&#8217;s done, we&#8217;ll work on polishing it for a nicer experience. In this post you find amalgamations of mostly outdated articles from around the internet updated to work with a modern [...]]]></description>
			<content:encoded><![CDATA[<p>This article will get you setup with the bare-minimum environment to run Selenium tests with RSpec, for automated, full-stack testing of Rails apps. Once that&#8217;s done, we&#8217;ll work on polishing it for a nicer experience. In this post you find amalgamations of mostly outdated articles from around the internet updated to work with a modern rails system.</p>
<p>It&#8217;s written on a clean environment courtesy of <a href="http://rvm.beginrescueend.com/">rvm</a>, so you may have some of the gems already setup.</p>
<h3>A new Rails app, RSpec, and rspec-rails</h3>
<p>First off, we&#8217;ll start with a new rails project:</p>
<pre class="brush:bash">gem install rails --no-ri --no-rdoc
rails rspec_saucerc
gem install rspec
gem install rspec-rails</pre>
<p>Edit config/environment.rb and add:</p>
<pre class="brush:ruby">  config.gem "rspec", :lib =&gt; false, :version =&gt; "&gt;= 1.2.9"
  config.gem "rspec-rails", :lib =&gt; false, :version =&gt; "&gt;= 1.2.9"</pre>
<p>This sets up all the required files for RSpec to get off the ground, but we need to integrate it into Rails:</p>
<pre class="brush:bash">script/generate rspec</pre>
<p>That will add the rake tasks, create the appropriate directories, and basic files. Now let&#8217;s get Selenium up and running!</p>
<h3>Selenium</h3>
<p>We&#8217;ll need to create a separate selenium database. in config/database.yml, let&#8217;s add:</p>
<pre class="brush:plain">selenium:
  adapter: sqlite3
  database: db/selenium.sqlite3
  encoding: utf8
  timeout: 5000</pre>
<p>To get Selenium running under our RSpec stories, we&#8217;ll need the Selenium gem (note the capital &#8220;S&#8221; — it&#8217;s case-sensitive). Let&#8217;s also make sure we have the sqlite3 gem installed, and then prepare an appropriate environment for our selenium tests:</p>
<pre class="brush:bash">gem install Selenium
gem install sqlite3-ruby
cp config/environments/test.rb config/environments/selenium.rb</pre>
<p>Open config/environments/selenium.rb and remove the last line that reads:</p>
<pre class="brush:ruby">config.gem 'rspec-rails', :version =&gt; '&gt;= 1.3.2', :lib =&gt; false unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))</pre>
<h3>Sauce RC and Selenium RC</h3>
<p>Sauce RC will broker all communication between rails and any browsers you might be driving. Get it from our <a href="http://saucelabs.com/products/downloads">downloads</a> page for Windows or Mac, or use <a href="http://seleniumhq.org/projects/remote-control/">Selenium RC</a> for Linux, and start it up so we can run our tests.</p>
<h3>Testables</h3>
<p>We&#8217;ll need some fodder to test. Use the RSpec generator, then create and migrate the database:</p>
<pre class="brush:bash">script/generate rspec_scaffold person name:string age:string language:string
rake RAILS_ENV=selenium db:create
rake RAILS_ENV=selenium db:migrate</pre>
<h3>Startup our test server</h3>
<p>Rails tests do not normally bind to a webserver, so there is no way for Selenium to access the frontend. As a temporary workaround, we&#8217;ll manually invoke a Rails server using the selenium environment:</p>
<pre class="brush:bash">script/server -e selenium</pre>
<h3>Our spec helper</h3>
<p>We will be using the Selenium gem, so let&#8217;s add it to the spec helper:</p>
<pre class="brush:ruby">gem "selenium-client"
require "selenium/client"
require "selenium/rspec/spec_helper"</pre>
<h3>Example story</h3>
<p>We&#8217;ll gloss over which types of tests should include selenium front-end testing for now, and just say it belongs in integration tests. Let&#8217;s run an example story that will fail the first time through, and we&#8217;ll then fix it.</p>
<p>Put the following in spec/integration/people_spec.rb:</p>
<pre class="brush:ruby">require 'spec_helper'
describe "People" do
  before(:all) do
    @verification_errors = []

    @browser = Selenium::Client::Driver.new(
      :host =&gt; "localhost",
      :port =&gt; 4444,
      :browser =&gt; "*firefox"
      :url =&gt; "http://localhost:3000",
      :timeout_in_second =&gt; 90)

    @browser.start
  end

  before(:each) do
    @browser.start_new_browser_session
  end

  append_after(:each) do
    @browser.close_current_browser_session
    @verification_errors.should == []
  end

  it "should create a new Person with valid input" do
    @browser.open "/people"
    @browser.click "link=New person"
    @browser.wait_for_page_to_load "2000"
    @browser.type "person_name", "Jason Huggins"
    @browser.type "person_age", "26"
    @browser.type "person_language", "Albanian"
    @browser.click "person_submit"
    @browser.wait_for_page_to_load "30000"
    @browser.is_alert_present.should be_true
  end
end</pre>
<p>Let&#8217;s try it out:</p>
<pre class="brush:bash">rake spec:integration
F
1) 'People should create a new Person with valid input' FAILED
expected false to be true
./spec/integration/people_spec.rb:22:

Finished in 7.443904 seconds

1 example, 1 failure</pre>
<p>It&#8217;s failing as we expected it to (there shouldn&#8217;t be a javascript alert on submit). Let&#8217;s change the last line:</p>
<pre class="brush:ruby">    @browser.is_alert_present.should be_false</pre>
<p>&#8230; and try our test again:</p>
<pre class="brush:bash">rake spec:integration
.

Finished in 7.079062 seconds

1 example, 0 failures</pre>
<p>Looks good! We finally have a working rails project with rspec runners and Selenium.</p>
<h3>Weaknesses</h3>
<p>Although we&#8217;ve got Rails, RSpec, and Selenium all working together, the relationship is not harmonious.</p>
<p>Automated tests in rails are not meant to serve the outside world, and as such they don&#8217;t bind to a webserver/port. Tests are run within the same process, which makes them quite fast, but prevents us from using browser-based frontend tools such as Selenium. To get around that, we manually fired up a rails server instance with the selenium environment, but this is messy for a number of reasons:</p>
<ul>
<li>We have to manually start/stop the test server that selenium wants to access</li>
<li>We have to manually create the selenium environment&#8217;s database</li>
<li>We have to manually migrate the selenium environment each time there&#8217;s a schema change</li>
<li>Worse, we have to manually reset the database after each run</li>
<li>Running Selenium tests in serial is <em>slow</em></li>
</ul>
<p>We‘ve developed a plugin to automate some of these issues, called <a href="http://github.com/sgrove/spec_storm">SpecStorm</a>. We&#8217;ll go over installing it to get the most out of your tests (including running them in parallel) in the next post.</p>
<p>Notes:</p>
<p>Selenium matchers are case-sensitive: @browser.click &#8220;link=New Person&#8221; won&#8217;t match a link with &#8220;New person&#8221;</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fsaucelabs.com%2Fblog%2Findex.php%2F2010%2F02%2Frunning-selenium-tests-for-rails%2F&amp;title=Running%20Selenium%20RSpec%20tests%20for%20Rails%202.3.5" id="wpa2a_6"><img src="http://saucelabs.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://saucelabs.com/blog/index.php/2010/02/running-selenium-tests-for-rails/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

