SlideShare una empresa de Scribd logo
1 de 54
Descargar para leer sin conexión
Ruby Acceptance Testing for Web Applications



   Webrat                                                              brynary.com
                          http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Bryan Helmkamp




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Beer Disclaimer




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
class
RepositoryTest
<
ActionController::IntegrationTest
   

test
quot;create
a
new
repositoryquot;
do
   



get_via_redirect
repositories_path
   



assert_response
:success
   



assert_select
quot;a[href=?]quot;,
new_repository_path,
quot;Create
a
new
repoquot;
   




   



get_via_redirect
new_repository_path
   



assert_response
:success
   




   



assert_select
quot;form[action=?][method=post]quot;,
repositories_path
do
   





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[name]quot;
   





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[description]quot;
   





assert_select
quot;input[name=?][type=radio]quot;,
quot;repository[public]quot;
   



end
   




   



post_via_redirect
repositories_path,
:repository
=>
{
   





:name
=>
quot;rack‐testquot;,
:public
=>
quot;truequot;
   



}
   



assert_response
:success
   



assert_select
quot;Repository
created.quot;
   

end
   end


   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
class
RepositoryTest
<
ActionController::IntegrationTest
   

test
quot;create
a
new
repositoryquot;
do
   



get_via_redirect
repositories_path
   



assert_response
:success
   



assert_select
quot;a[href=?]quot;,
new_repository_path,
quot;Create
a
new
repoquot;

   



get_via_redirect
new_repository_path
   



assert_response
:success

   



assert_select
quot;form[action=?][method=post]quot;,
repositories_path
do
   





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[name]quot;
   





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[description]quot;
   





assert_select
quot;input[name=?][type=radio]quot;,
quot;repository[public]quot;
   



end


   



post_via_redirect
repositories_path,
:repository
=>
{
   





:name
=>
quot;rack‐testquot;,
:public
=>
quot;truequot;
   



}
   



assert_response
:success
   



assert_select
quot;Repository
created.quot;
   

end
   end


   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
class
RepositoryTest
<
ActionController::IntegrationTest
   

test
quot;create
a
new
repositoryquot;
do
   



get_via_redirect
repositories_path
   



assert_response
:success
   



assert_select
quot;a[href=?]quot;,
new_repository_path,
quot;Create
a
new
repoquot;

   



get_via_redirect
new_repository_path
   



assert_response
:success

   



assert_select
quot;form[action=?][method=post]quot;,
repositories_path
do
   





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[name]quot;
   





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[description]quot;
   





assert_select
quot;input[name=?][type=radio]quot;,
quot;repository[public]quot;
   



end


   



post_via_redirect
repositories_path,
:repository
=>
{
   





:name
=>
quot;rack‐testquot;,
:public
=>
quot;truequot;
   



}
   



assert_response
:success
   



assert_select
quot;Repository
created.quot;
   

end
   end


   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
class
RepositoryTest
<
ActionController::IntegrationTest
   

test
quot;create
a
new
repositoryquot;
do
   



get_via_redirect
repositories_path
   



assert_response
:success
   



assert_select
quot;a[href=?]quot;,
new_repository_path,
quot;Create
a
new
repoquot;

   



get_via_redirect
new_repository_path
   



assert_response
:success

   



assert_select
quot;form[action=?][method=post]quot;,
repositories_path
do
   





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[name]quot;
   





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[description]quot;
   





assert_select
quot;input[name=?][type=radio]quot;,
quot;repository[public]quot;
   



end


   



post_via_redirect
repositories_path,
:repository
=>
{
   





:name
=>
quot;rack‐testquot;,
:public
=>
quot;truequot;
   



}
   



assert_response
:success
   



assert_select
quot;Repository
created.quot;
   

end
   end


   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat
 class
RepositoryTest
<
ActionController::IntegrationTest
 

test
quot;create
a
new
repositoryquot;
do
 



visit
repositories_path
 



click_link
quot;Create
a
new
repoquot;
 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot;
 



click_button
quot;Createquot;
 



assert_contain
quot;Repository
created.quot;
 

end
 end




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat
 class
RepositoryTest
<
ActionController::IntegrationTest
 

test
quot;create
a
new
repositoryquot;
do
 



visit
repositories_path
 



click_link
quot;Create
a
new
repoquot;
 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot;
 



click_button
quot;Createquot;
 



assert_contain
quot;Repository
created.quot;
 

end
 end




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat
 class
RepositoryTest
<
ActionController::IntegrationTest
 

test
quot;create
a
new
repositoryquot;
do
 



visit
repositories_path
 



click_link
quot;Create
a
new
repoquot;
 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot;
 



click_button
quot;Createquot;
 



assert_contain
quot;Repository
created.quot;
 

end
 end




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat
 class
RepositoryTest
<
ActionController::IntegrationTest
 

test
quot;create
a
new
repositoryquot;
do
 



visit
repositories_path
 



click_link
quot;Create
a
new
repoquot;
 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot;
 



click_button
quot;Createquot;
 



assert_contain
quot;Repository
created.quot;
 

end
 end




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat
 class
RepositoryTest
<
ActionController::IntegrationTest
 

test
quot;create
a
new
repositoryquot;
do
 



visit
repositories_path
 



click_link
quot;Create
a
new
repoquot;
 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot;
 



click_button
quot;Createquot;
 



assert_contain
quot;Repository
created.quot;
 

end
 end




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Getting started
      #
config/environments/test.rb
      config.gem
quot;webratquot;,
:version
=>
quot;>=0.4.4quot;

      #
test/test_helper.rb
      Webrat.configure
do
|config|
      

config.mode
=
:rails
      end

      #
sudo
rake
gems:install
RAILS_ENV=test

   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat’s Core API
                          #visit
                          #click_link
                          #fill_in
                          #check
and
#uncheck
                          #choose
                          #select
                          #attach_file
                          #click_button
   Webrat                                                               brynary.com
                           http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Works with RSpec
            describe
quot;repository
managementquot;
do
            

it
quot;should
create
a
repository
with
a
namequot;
do
            



visit
repositories_path
            



click_link
quot;Create
a
new
repoquot;
            



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot;
            



click_button
quot;Createquot;
            



response.should
contain(quot;Repository
created.quot;)
            

end
            end




   Webrat                                                               brynary.com
                           http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Works with Shoulda
 class
RepositoryTest
<
ActionController::IntegrationTest
 

context
quot;repository
managementquot;
do
 



should
quot;create
a
repositoryquot;
do
 





visit
repositories_path
 





click_link
quot;Create
a
new
repoquot;
 





fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot;
 





click_button
quot;Createquot;
 





assert_contain
quot;Repository
created.quot;
 



end
 

end
 end


   Webrat                                                               brynary.com
                           http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Works with Cucumber

            Feature:
Manage
repositories

            

Scenario:
Create
repository
with
name

            



When
I
create
a
repository
            



Then
I
should
see
quot;Repository
created.quot;




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Works with Cucumber
               When
/^I
create
a
repository$/
do
               

visit
repositories_path
               

click_link
quot;Create
a
new
repoquot;
               

fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot;
               

click_button
quot;Createquot;
               end

               When
/^I
should
see
quot;([^quot;]*)quot;$/
do
|text|
               

response.should
contain(text)
               end


   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Sinatra
                            Application
                            Frameworks


   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Matches labels to fields

                         fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot;


    <label
for=quot;repository_namequot;>Name</label>
    <input
id=quot;repository_namequot;
name=quot;repository[name]quot;
/>




   Webrat                                                                 brynary.com
                             http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Matches labels to fields

                         fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot;


    <label
for=quot;repository_namequot;>Name</label>
    <input
id=quot;repository_namequot;
name=quot;repository[name]quot;
/>




   Webrat                                                                 brynary.com
                             http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Matches labels to fields
                         <label>
                         

<input
type=quot;checkboxquot;
name=quot;tosquot;
/>
                         

I
accept
the
Terms
of
Service
                         </label>



                         check
quot;I
accept
the
Terms
of
Servicequot;




   Webrat                                                                  brynary.com
                              http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Matches labels to fields
                         <label>
                         

<input
type=quot;checkboxquot;
name=quot;tosquot;
/>
                         

I
accept
the
Terms
of
Service
                         </label>



                         check
quot;I
accept
the
Terms
of
Servicequot;




   Webrat                                                                  brynary.com
                              http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat verifies web app behaviour




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Verifies HTTP status codes

 

1)
Error:
 test_create_a_new_repository(RepositoryTest):
 Webrat::PageLoadError:
Page
load
was
not
successful
(Code:
500):
 <snip>
 



webrat
(0.4.4)
lib/webrat/core/session.rb:110:in
`request_page'
 



webrat
(0.4.4)
lib/webrat/core/session.rb:205:in
`visit'
 



(eval):2:in
`visit'
 



/test/integration/repository_test.rb:5:in
`test_create_a_new_repository'




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Verifies form fields

 

1)
Error:
 test_create_a_new_repository(RepositoryTest):
 Webrat::NotFoundError:
Could
not
find
field:
quot;Namequot;
 



webrat
(0.4.4)
lib/webrat/core/locators/locator.rb:14:in
`locate!'
 



webrat
(0.4.4)
lib/webrat/core/locators/field_locator.rb:21:in
`field'
 



webrat
(0.4.4)
lib/webrat/core/scope.rb:327:in
`locate_field'
 



webrat
(0.4.4)
lib/webrat/core/scope.rb:50:in
`fill_in'
 



(eval):2:in
`fill_in'
 



/test/integration/repository_test.rb:8:in
`test_create_a_new_repository'




   Webrat                                                               brynary.com
                           http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Verify HTML content

   response.should
contain(quot;Hello,
world!quot;)

   response.should
have_selector(quot;liquot;,
:class
=>
quot;newquot;,
   

:count
=>
2)

   response.should_not
have_xpath(quot;.//meta[@name
=
'robots']quot;)




   Webrat                                                                brynary.com
                            http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Verify HTML content

   response.should
have_selector(quot;#album
li:nth‐child(3)quot;)
do
|li|

   

li.should
have_selector(quot;imgquot;,
:src
=>
photo_path(@photo))

   

li.should
contain(quot;Vacation
Photoquot;)

   end





   Webrat                                                                brynary.com
                            http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
save_and_open_page
   Webrat                                                                brynary.com
                            http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat adapters

                     • Rails
                     • Merb
                     • Sinatra
                     • Selenium
                     • Mechanize
   Webrat                                                                brynary.com
                            http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
WWW::Mechanize
   require
quot;webratquot;
   require
quot;webrat/mechanizequot;

   session
=
Webrat::MechanizeSession.new
   session.visit
quot;http://google.com/quot;
   session.fill_in
quot;qquot;,
:with
=>
quot;GoGaRuCoquot;
   session.click_button
quot;Google
Searchquot;

   session.dom.search(quot;h3
aquot;).each_with_index
do
|link,
i|
   

puts
quot;#{i+1})
#{link[quot;hrefquot;]}quot;
   end



   Webrat                                                              brynary.com
                          http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Selenium

   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
#
test/test_helper.rb
                class
ActiveSupport::TestCase
                

#
...
                

self.use_transactional_fixtures
=
false

                

#
...

                

setup
do
|session|
                



session.host!
quot;localhost:3001quot;
                

end
                end
                


                Webrat.configure
do
|config|
                

config.mode
=
:selenium
                end

   Webrat                                                              brynary.com
                          http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
$
rake
test:integration
   Started
   ==>
Waiting
for
Selenium
RC
server
on
port
4444...
Ready!
   ==>
Waiting
for
Rails
application
server
on
port
3001...
Ready!
   ..
   Finished
in
23.54011
seconds.

   2
tests,
2
assertions,
0
failures,
0
errors




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
$
rake
test:integration
   Started
   ==>
Waiting
for
Selenium
RC
server
on
port
4444...
Ready!
   ==>
Waiting
for
Rails
application
server
on
port
3001...
Ready!
   ..
   Finished
in
23.54011
seconds.

   2
tests,
2
assertions,
0
failures,
0
errors




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
$
rake
test:integration
   Started
   ==>
Waiting
for
Selenium
RC
server
on
port
4444...
Ready!
   ==>
Waiting
for
Rails
application
server
on
port
3001...
Ready!
   ..
   Finished
in
23.54011
seconds.

   2
tests,
2
assertions,
0
failures,
0
errors




   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat::Selenium




                                        Selenium RC Server




   Webrat                                                                brynary.com
                         http://bit.ly/wbrt-ggrc      @brynary #webrat
Sunday, April 19, 2009
One method, two modes
   def
upload_photo
   

webrat.simulate
do
   



simulate_uploads
   

end

   

webrat.automate
do
   



simulate_upload_via_javascript(quot;avatarquot;,
quot;foo.jpgquot;)
   



response.should
contain(quot;Uploading
imagequot;)
   



response.should
contain(quot;successfully
uploadedquot;)
   



click_link
quot;Continuequot;
   

end
   end


   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
One method, two modes
   def
upload_photo
   

webrat.simulate
do
   



simulate_uploads
   

end

   

webrat.automate
do
   



simulate_upload_via_javascript(quot;avatarquot;,
quot;foo.jpgquot;)
   



response.should
contain(quot;Uploading
imagequot;)
   



response.should
contain(quot;successfully
uploadedquot;)
   



click_link
quot;Continuequot;
   

end
   end


   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
One method, two modes
   def
upload_photo
   

webrat.simulate
do
   



simulate_uploads
   

end

   

webrat.automate
do
   



simulate_upload_via_javascript(quot;avatarquot;,
quot;foo.jpgquot;)
   



response.should
contain(quot;Uploading
imagequot;)
   



response.should
contain(quot;successfully
uploadedquot;)
   



click_link
quot;Continuequot;
   

end
   end


   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
class
MediaTest
<
ActionController::IntegrationTest
 

test
quot;drag
and
drop
mediaquot;
do
 



album


=
create_album
:title
=>
quot;Vacationquot;
 



photo1

=
create_photo
:album
=>
album
 



photo2

=
create_photo
:album
=>
album
 




 



visit
album_path(album)
 



click_link
quot;Order
mediaquot;
 




 



selenium.dragdrop(quot;id=#{dom_id(photo1)}quot;,
quot;+350,
0quot;)
 



wait_for
do
 





assert
selenium.is_ordered(
 







quot;id=#{dom_id(photo1)}quot;,
 







quot;id=#{dom_id(photo2)}quot;)
 



end
 

end
 end

   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
class
MediaTest
<
ActionController::IntegrationTest
 

test
quot;drag
and
drop
mediaquot;
do
 



album


=
create_album
:title
=>
quot;Vacationquot;
 



photo1

=
create_photo
:album
=>
album
 



photo2

=
create_photo
:album
=>
album
 




 



visit
album_path(album)
 



click_link
quot;Order
mediaquot;
 




 



selenium.dragdrop(quot;id=#{dom_id(photo1)}quot;,
quot;+350,
0quot;)
 



wait_for
do
 





assert
selenium.is_ordered(
 







quot;id=#{dom_id(photo1)}quot;,
 







quot;id=#{dom_id(photo2)}quot;)
 



end
 

end
 end

   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
class
MediaTest
<
ActionController::IntegrationTest
 

test
quot;drag
and
drop
mediaquot;
do
 



album


=
create_album
:title
=>
quot;Vacationquot;
 



photo1

=
create_photo
:album
=>
album
 



photo2

=
create_photo
:album
=>
album
 




 



visit
album_path(album)
 



click_link
quot;Order
mediaquot;
 




 



selenium.dragdrop(quot;id=#{dom_id(photo1)}quot;,
quot;+350,
0quot;)
 



wait_for
do
 





assert
selenium.is_ordered(
 







quot;id=#{dom_id(photo1)}quot;,
 







quot;id=#{dom_id(photo2)}quot;)
 



end
 

end
 end

   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Automating a real web browser is slow


   Webrat                                                              brynary.com
                          http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Quick demo



   Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
One More Thing...




   Webrat                                                              brynary.com
                          http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Rack::Test
            require
quot;rack/testquot;

            class
HomepageTest
<
Test::Unit::TestCase
            

include
Rack::Test::Methods
            


            

def
app
            



MyApp.new
            

end
            


            

def
test_redirect_logged_in_users_to_dashboard
            



authorize
quot;bryanquot;,
quot;secretquot;
            



get
quot;/quot;
            



follow_redirect!
            




            



assert_equal
quot;http://example.org/redirectedquot;,
last_request.url
            



assert
last_response.ok?
            

end
            end

   Webrat                                                               brynary.com
                           http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Rack::Test API
                         #get(uri,
params
=
{},
env
=
{})
                         #post,
#put,
#delete,
and
#head

                         #request(uri,
env
=
{})

                         #follow_redirect!

                         #header(name,
value)
                         #authorize(username,
password)

                         #last_request
                         #last_response
   Webrat                                                                 brynary.com
                             http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat adapters

                     • Rails
                     • Merb
                     • Sinatra
                     • Selenium
                     • Mechanize
   Webrat                                                                brynary.com
                            http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat adapters

                     • Rack::Test
                     • Selenium
                     • Mechanize

   Webrat                                                               brynary.com
                           http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Webrat                                                             brynary.com
                         http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009
Thanks
                          http://www.flickr.com/photos/tambako/2908186658/
                          http://www.flickr.com/photos/pkmousie/2199520904/
                         http://www.flickr.com/photos/audreyjm529/155024495/
                            http://www.flickr.com/photos/acaben/541334636/
                          http://www.flickr.com/photos/millermz/3267766667/



   Webrat                                                                     brynary.com
                                http://bit.ly/wbrt-ggrc   @brynary #webrat
Sunday, April 19, 2009

Más contenido relacionado

La actualidad más candente

Plone Interactivity
Plone InteractivityPlone Interactivity
Plone InteractivityEric Steele
 
So you want to build a Facebook app
So you want to build a Facebook appSo you want to build a Facebook app
So you want to build a Facebook appkamal.fariz
 
In some simple steps, your site can stand out from the rest. Here's how...
In some simple steps, your site can stand out from the rest. Here's how... In some simple steps, your site can stand out from the rest. Here's how...
In some simple steps, your site can stand out from the rest. Here's how... British Council
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?brynary
 
REST, the internet as a database?
REST, the internet as a database?REST, the internet as a database?
REST, the internet as a database?Andrej Koelewijn
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingViget Labs
 

La actualidad más candente (7)

Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
So you want to build a Facebook app
So you want to build a Facebook appSo you want to build a Facebook app
So you want to build a Facebook app
 
In some simple steps, your site can stand out from the rest. Here's how...
In some simple steps, your site can stand out from the rest. Here's how... In some simple steps, your site can stand out from the rest. Here's how...
In some simple steps, your site can stand out from the rest. Here's how...
 
From Work To Word
From Work To WordFrom Work To Word
From Work To Word
 
What's new in Rails 2?
What's new in Rails 2?What's new in Rails 2?
What's new in Rails 2?
 
REST, the internet as a database?
REST, the internet as a database?REST, the internet as a database?
REST, the internet as a database?
 
Make Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance TestingMake Everyone a Tester: Natural Language Acceptance Testing
Make Everyone a Tester: Natural Language Acceptance Testing
 

Similar a Webrat: Rails Acceptance Testing Evolved

WWW:::Mechanize YAPC::BR 2008
WWW:::Mechanize YAPC::BR 2008WWW:::Mechanize YAPC::BR 2008
WWW:::Mechanize YAPC::BR 2008mvitor
 
Agilebuddy Users Guide
Agilebuddy Users GuideAgilebuddy Users Guide
Agilebuddy Users Guideagilebuddy
 
Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2Byrne Reese
 
UW ADC - Course 3 - Class 1 - User Stories And Acceptance Testing
UW ADC - Course 3 - Class 1 - User Stories And Acceptance TestingUW ADC - Course 3 - Class 1 - User Stories And Acceptance Testing
UW ADC - Course 3 - Class 1 - User Stories And Acceptance TestingChris Sterling
 
Yakov Fain - Design Patterns a Deep Dive
Yakov Fain - Design Patterns a Deep DiveYakov Fain - Design Patterns a Deep Dive
Yakov Fain - Design Patterns a Deep Dive360|Conferences
 
Roll-out of the NYU HSL Website and Drupal CMS
Roll-out of the NYU HSL Website and Drupal CMSRoll-out of the NYU HSL Website and Drupal CMS
Roll-out of the NYU HSL Website and Drupal CMSChris Evjy
 
The Yahoo Open Stack
The Yahoo Open StackThe Yahoo Open Stack
The Yahoo Open StackMegan Eskey
 
How To Create An Interactive Keynote
How To Create An Interactive KeynoteHow To Create An Interactive Keynote
How To Create An Interactive KeynoteJacqui Sharp
 
A Guide To Blogging For The Uninitiated
A Guide To Blogging For The UninitiatedA Guide To Blogging For The Uninitiated
A Guide To Blogging For The UninitiatedMatt Machell
 
Building


















 Terrier by
 Open
 Collaboration
Building


















 Terrier by
 Open
 CollaborationBuilding


















 Terrier by
 Open
 Collaboration
Building


















 Terrier by
 Open
 CollaborationCrai Macdonald
 
Web 2.0 架站工具—AJAX By Examples-馮彥文(Tempo)
Web 2.0 架站工具—AJAX By Examples-馮彥文(Tempo)Web 2.0 架站工具—AJAX By Examples-馮彥文(Tempo)
Web 2.0 架站工具—AJAX By Examples-馮彥文(Tempo)taiwanweb20
 
GIPA
GIPAGIPA
GIPAESUG
 
High Performance Kick Ass Web Apps (JavaScript edition)
High Performance Kick Ass Web Apps (JavaScript edition)High Performance Kick Ass Web Apps (JavaScript edition)
High Performance Kick Ass Web Apps (JavaScript edition)Stoyan Stefanov
 
Spring基础教程
Spring基础教程Spring基础教程
Spring基础教程Shilong Sang
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentationrailsconf
 
Ajax On S2 Odp
Ajax On S2 OdpAjax On S2 Odp
Ajax On S2 Odpghessler
 

Similar a Webrat: Rails Acceptance Testing Evolved (20)

WWW:::Mechanize YAPC::BR 2008
WWW:::Mechanize YAPC::BR 2008WWW:::Mechanize YAPC::BR 2008
WWW:::Mechanize YAPC::BR 2008
 
Agilebuddy Users Guide
Agilebuddy Users GuideAgilebuddy Users Guide
Agilebuddy Users Guide
 
Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2Hacking Movable Type Training - Day 2
Hacking Movable Type Training - Day 2
 
UW ADC - Course 3 - Class 1 - User Stories And Acceptance Testing
UW ADC - Course 3 - Class 1 - User Stories And Acceptance TestingUW ADC - Course 3 - Class 1 - User Stories And Acceptance Testing
UW ADC - Course 3 - Class 1 - User Stories And Acceptance Testing
 
Yakov Fain - Design Patterns a Deep Dive
Yakov Fain - Design Patterns a Deep DiveYakov Fain - Design Patterns a Deep Dive
Yakov Fain - Design Patterns a Deep Dive
 
Blogging Slides
Blogging SlidesBlogging Slides
Blogging Slides
 
Roll-out of the NYU HSL Website and Drupal CMS
Roll-out of the NYU HSL Website and Drupal CMSRoll-out of the NYU HSL Website and Drupal CMS
Roll-out of the NYU HSL Website and Drupal CMS
 
The Yahoo Open Stack
The Yahoo Open StackThe Yahoo Open Stack
The Yahoo Open Stack
 
How To Create An Interactive Keynote
How To Create An Interactive KeynoteHow To Create An Interactive Keynote
How To Create An Interactive Keynote
 
A Guide To Blogging For The Uninitiated
A Guide To Blogging For The UninitiatedA Guide To Blogging For The Uninitiated
A Guide To Blogging For The Uninitiated
 
Building


















 Terrier by
 Open
 Collaboration
Building


















 Terrier by
 Open
 CollaborationBuilding


















 Terrier by
 Open
 Collaboration
Building


















 Terrier by
 Open
 Collaboration
 
HTML Parsing With Hpricot
HTML Parsing With HpricotHTML Parsing With Hpricot
HTML Parsing With Hpricot
 
Web 2.0 架站工具—AJAX By Examples-馮彥文(Tempo)
Web 2.0 架站工具—AJAX By Examples-馮彥文(Tempo)Web 2.0 架站工具—AJAX By Examples-馮彥文(Tempo)
Web 2.0 架站工具—AJAX By Examples-馮彥文(Tempo)
 
GIPA
GIPAGIPA
GIPA
 
High Performance Kick Ass Web Apps (JavaScript edition)
High Performance Kick Ass Web Apps (JavaScript edition)High Performance Kick Ass Web Apps (JavaScript edition)
High Performance Kick Ass Web Apps (JavaScript edition)
 
Spring基础教程
Spring基础教程Spring基础教程
Spring基础教程
 
Gpl 과 Ccl
Gpl 과  CclGpl 과  Ccl
Gpl 과 Ccl
 
Mobile Marketing Forum - MOOGA
Mobile Marketing Forum - MOOGAMobile Marketing Forum - MOOGA
Mobile Marketing Forum - MOOGA
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
 
Ajax On S2 Odp
Ajax On S2 OdpAjax On S2 Odp
Ajax On S2 Odp
 

Último

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Último (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Webrat: Rails Acceptance Testing Evolved

  • 1. Ruby Acceptance Testing for Web Applications Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 2. Bryan Helmkamp Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 3. Beer Disclaimer Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 4. Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 5. class
RepositoryTest
<
ActionController::IntegrationTest 

test
quot;create
a
new
repositoryquot;
do 



get_via_redirect
repositories_path 



assert_response
:success 



assert_select
quot;a[href=?]quot;,
new_repository_path,
quot;Create
a
new
repoquot; 



 



get_via_redirect
new_repository_path 



assert_response
:success 



 



assert_select
quot;form[action=?][method=post]quot;,
repositories_path
do 





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[name]quot; 





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[description]quot; 





assert_select
quot;input[name=?][type=radio]quot;,
quot;repository[public]quot; 



end 



 



post_via_redirect
repositories_path,
:repository
=>
{ 





:name
=>
quot;rack‐testquot;,
:public
=>
quot;truequot; 



} 



assert_response
:success 



assert_select
quot;Repository
created.quot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 6. class
RepositoryTest
<
ActionController::IntegrationTest 

test
quot;create
a
new
repositoryquot;
do 



get_via_redirect
repositories_path 



assert_response
:success 



assert_select
quot;a[href=?]quot;,
new_repository_path,
quot;Create
a
new
repoquot; 



get_via_redirect
new_repository_path 



assert_response
:success 



assert_select
quot;form[action=?][method=post]quot;,
repositories_path
do 





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[name]quot; 





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[description]quot; 





assert_select
quot;input[name=?][type=radio]quot;,
quot;repository[public]quot; 



end
 



post_via_redirect
repositories_path,
:repository
=>
{ 





:name
=>
quot;rack‐testquot;,
:public
=>
quot;truequot; 



} 



assert_response
:success 



assert_select
quot;Repository
created.quot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 7. class
RepositoryTest
<
ActionController::IntegrationTest 

test
quot;create
a
new
repositoryquot;
do 



get_via_redirect
repositories_path 



assert_response
:success 



assert_select
quot;a[href=?]quot;,
new_repository_path,
quot;Create
a
new
repoquot; 



get_via_redirect
new_repository_path 



assert_response
:success 



assert_select
quot;form[action=?][method=post]quot;,
repositories_path
do 





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[name]quot; 





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[description]quot; 





assert_select
quot;input[name=?][type=radio]quot;,
quot;repository[public]quot; 



end
 



post_via_redirect
repositories_path,
:repository
=>
{ 





:name
=>
quot;rack‐testquot;,
:public
=>
quot;truequot; 



} 



assert_response
:success 



assert_select
quot;Repository
created.quot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 8. class
RepositoryTest
<
ActionController::IntegrationTest 

test
quot;create
a
new
repositoryquot;
do 



get_via_redirect
repositories_path 



assert_response
:success 



assert_select
quot;a[href=?]quot;,
new_repository_path,
quot;Create
a
new
repoquot; 



get_via_redirect
new_repository_path 



assert_response
:success 



assert_select
quot;form[action=?][method=post]quot;,
repositories_path
do 





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[name]quot; 





assert_select
quot;input[name=?][type=text]quot;,
quot;repository[description]quot; 





assert_select
quot;input[name=?][type=radio]quot;,
quot;repository[public]quot; 



end
 



post_via_redirect
repositories_path,
:repository
=>
{ 





:name
=>
quot;rack‐testquot;,
:public
=>
quot;truequot; 



} 



assert_response
:success 



assert_select
quot;Repository
created.quot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 9. Webrat class
RepositoryTest
<
ActionController::IntegrationTest 

test
quot;create
a
new
repositoryquot;
do 



visit
repositories_path 



click_link
quot;Create
a
new
repoquot; 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot; 



click_button
quot;Createquot; 



assert_contain
quot;Repository
created.quot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 10. Webrat class
RepositoryTest
<
ActionController::IntegrationTest 

test
quot;create
a
new
repositoryquot;
do 



visit
repositories_path 



click_link
quot;Create
a
new
repoquot; 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot; 



click_button
quot;Createquot; 



assert_contain
quot;Repository
created.quot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 11. Webrat class
RepositoryTest
<
ActionController::IntegrationTest 

test
quot;create
a
new
repositoryquot;
do 



visit
repositories_path 



click_link
quot;Create
a
new
repoquot; 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot; 



click_button
quot;Createquot; 



assert_contain
quot;Repository
created.quot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 12. Webrat class
RepositoryTest
<
ActionController::IntegrationTest 

test
quot;create
a
new
repositoryquot;
do 



visit
repositories_path 



click_link
quot;Create
a
new
repoquot; 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot; 



click_button
quot;Createquot; 



assert_contain
quot;Repository
created.quot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 13. Webrat class
RepositoryTest
<
ActionController::IntegrationTest 

test
quot;create
a
new
repositoryquot;
do 



visit
repositories_path 



click_link
quot;Create
a
new
repoquot; 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot; 



click_button
quot;Createquot; 



assert_contain
quot;Repository
created.quot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 14. Getting started #
config/environments/test.rb config.gem
quot;webratquot;,
:version
=>
quot;>=0.4.4quot; #
test/test_helper.rb Webrat.configure
do
|config| 

config.mode
=
:rails end #
sudo
rake
gems:install
RAILS_ENV=test Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 15. Webrat’s Core API #visit #click_link #fill_in #check
and
#uncheck #choose #select #attach_file #click_button Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 16. Works with RSpec describe
quot;repository
managementquot;
do 

it
quot;should
create
a
repository
with
a
namequot;
do 



visit
repositories_path 



click_link
quot;Create
a
new
repoquot; 



fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot; 



click_button
quot;Createquot; 



response.should
contain(quot;Repository
created.quot;) 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 17. Works with Shoulda class
RepositoryTest
<
ActionController::IntegrationTest 

context
quot;repository
managementquot;
do 



should
quot;create
a
repositoryquot;
do 





visit
repositories_path 





click_link
quot;Create
a
new
repoquot; 





fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot; 





click_button
quot;Createquot; 





assert_contain
quot;Repository
created.quot; 



end 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 18. Works with Cucumber Feature:
Manage
repositories 

Scenario:
Create
repository
with
name 



When
I
create
a
repository 



Then
I
should
see
quot;Repository
created.quot; Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 19. Works with Cucumber When
/^I
create
a
repository$/
do 

visit
repositories_path 

click_link
quot;Create
a
new
repoquot; 

fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot; 

click_button
quot;Createquot; end When
/^I
should
see
quot;([^quot;]*)quot;$/
do
|text| 

response.should
contain(text) end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 20. Sinatra Application Frameworks Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 21. Matches labels to fields fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot; <label
for=quot;repository_namequot;>Name</label> <input
id=quot;repository_namequot;
name=quot;repository[name]quot;
/> Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 22. Matches labels to fields fill_in
quot;Namequot;,
:with
=>
quot;rack‐testquot; <label
for=quot;repository_namequot;>Name</label> <input
id=quot;repository_namequot;
name=quot;repository[name]quot;
/> Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 23. Matches labels to fields <label> 

<input
type=quot;checkboxquot;
name=quot;tosquot;
/> 

I
accept
the
Terms
of
Service </label> check
quot;I
accept
the
Terms
of
Servicequot; Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 24. Matches labels to fields <label> 

<input
type=quot;checkboxquot;
name=quot;tosquot;
/> 

I
accept
the
Terms
of
Service </label> check
quot;I
accept
the
Terms
of
Servicequot; Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 25. Webrat verifies web app behaviour Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 26. Verifies HTTP status codes 

1)
Error: test_create_a_new_repository(RepositoryTest): Webrat::PageLoadError:
Page
load
was
not
successful
(Code:
500): <snip> 



webrat
(0.4.4)
lib/webrat/core/session.rb:110:in
`request_page' 



webrat
(0.4.4)
lib/webrat/core/session.rb:205:in
`visit' 



(eval):2:in
`visit' 



/test/integration/repository_test.rb:5:in
`test_create_a_new_repository' Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 27. Verifies form fields 

1)
Error: test_create_a_new_repository(RepositoryTest): Webrat::NotFoundError:
Could
not
find
field:
quot;Namequot; 



webrat
(0.4.4)
lib/webrat/core/locators/locator.rb:14:in
`locate!' 



webrat
(0.4.4)
lib/webrat/core/locators/field_locator.rb:21:in
`field' 



webrat
(0.4.4)
lib/webrat/core/scope.rb:327:in
`locate_field' 



webrat
(0.4.4)
lib/webrat/core/scope.rb:50:in
`fill_in' 



(eval):2:in
`fill_in' 



/test/integration/repository_test.rb:8:in
`test_create_a_new_repository' Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 28. Verify HTML content response.should
contain(quot;Hello,
world!quot;) response.should
have_selector(quot;liquot;,
:class
=>
quot;newquot;, 

:count
=>
2) response.should_not
have_xpath(quot;.//meta[@name
=
'robots']quot;) Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 29. Verify HTML content response.should
have_selector(quot;#album
li:nth‐child(3)quot;)
do
|li|
 

li.should
have_selector(quot;imgquot;,
:src
=>
photo_path(@photo))
 

li.should
contain(quot;Vacation
Photoquot;)
 end
 Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 30. save_and_open_page Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 31. Webrat adapters • Rails • Merb • Sinatra • Selenium • Mechanize Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 32. WWW::Mechanize require
quot;webratquot; require
quot;webrat/mechanizequot; session
=
Webrat::MechanizeSession.new session.visit
quot;http://google.com/quot; session.fill_in
quot;qquot;,
:with
=>
quot;GoGaRuCoquot; session.click_button
quot;Google
Searchquot; session.dom.search(quot;h3
aquot;).each_with_index
do
|link,
i| 

puts
quot;#{i+1})
#{link[quot;hrefquot;]}quot; end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 33. Selenium Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 34. #
test/test_helper.rb class
ActiveSupport::TestCase 

#
... 

self.use_transactional_fixtures
=
false 

#
... 

setup
do
|session| 



session.host!
quot;localhost:3001quot; 

end end 

 Webrat.configure
do
|config| 

config.mode
=
:selenium end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 35. $
rake
test:integration Started ==>
Waiting
for
Selenium
RC
server
on
port
4444...
Ready! ==>
Waiting
for
Rails
application
server
on
port
3001...
Ready! .. Finished
in
23.54011
seconds. 2
tests,
2
assertions,
0
failures,
0
errors Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 36. $
rake
test:integration Started ==>
Waiting
for
Selenium
RC
server
on
port
4444...
Ready! ==>
Waiting
for
Rails
application
server
on
port
3001...
Ready! .. Finished
in
23.54011
seconds. 2
tests,
2
assertions,
0
failures,
0
errors Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 37. $
rake
test:integration Started ==>
Waiting
for
Selenium
RC
server
on
port
4444...
Ready! ==>
Waiting
for
Rails
application
server
on
port
3001...
Ready! .. Finished
in
23.54011
seconds. 2
tests,
2
assertions,
0
failures,
0
errors Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 38. Webrat::Selenium Selenium RC Server Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 39. One method, two modes def
upload_photo 

webrat.simulate
do 



simulate_uploads 

end 

webrat.automate
do 



simulate_upload_via_javascript(quot;avatarquot;,
quot;foo.jpgquot;) 



response.should
contain(quot;Uploading
imagequot;) 



response.should
contain(quot;successfully
uploadedquot;) 



click_link
quot;Continuequot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 40. One method, two modes def
upload_photo 

webrat.simulate
do 



simulate_uploads 

end 

webrat.automate
do 



simulate_upload_via_javascript(quot;avatarquot;,
quot;foo.jpgquot;) 



response.should
contain(quot;Uploading
imagequot;) 



response.should
contain(quot;successfully
uploadedquot;) 



click_link
quot;Continuequot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 41. One method, two modes def
upload_photo 

webrat.simulate
do 



simulate_uploads 

end 

webrat.automate
do 



simulate_upload_via_javascript(quot;avatarquot;,
quot;foo.jpgquot;) 



response.should
contain(quot;Uploading
imagequot;) 



response.should
contain(quot;successfully
uploadedquot;) 



click_link
quot;Continuequot; 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 42. class
MediaTest
<
ActionController::IntegrationTest 

test
quot;drag
and
drop
mediaquot;
do 



album


=
create_album
:title
=>
quot;Vacationquot; 



photo1

=
create_photo
:album
=>
album 



photo2

=
create_photo
:album
=>
album 



 



visit
album_path(album) 



click_link
quot;Order
mediaquot; 



 



selenium.dragdrop(quot;id=#{dom_id(photo1)}quot;,
quot;+350,
0quot;) 



wait_for
do 





assert
selenium.is_ordered( 







quot;id=#{dom_id(photo1)}quot;, 







quot;id=#{dom_id(photo2)}quot;) 



end 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 43. class
MediaTest
<
ActionController::IntegrationTest 

test
quot;drag
and
drop
mediaquot;
do 



album


=
create_album
:title
=>
quot;Vacationquot; 



photo1

=
create_photo
:album
=>
album 



photo2

=
create_photo
:album
=>
album 



 



visit
album_path(album) 



click_link
quot;Order
mediaquot; 



 



selenium.dragdrop(quot;id=#{dom_id(photo1)}quot;,
quot;+350,
0quot;) 



wait_for
do 





assert
selenium.is_ordered( 







quot;id=#{dom_id(photo1)}quot;, 







quot;id=#{dom_id(photo2)}quot;) 



end 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 44. class
MediaTest
<
ActionController::IntegrationTest 

test
quot;drag
and
drop
mediaquot;
do 



album


=
create_album
:title
=>
quot;Vacationquot; 



photo1

=
create_photo
:album
=>
album 



photo2

=
create_photo
:album
=>
album 



 



visit
album_path(album) 



click_link
quot;Order
mediaquot; 



 



selenium.dragdrop(quot;id=#{dom_id(photo1)}quot;,
quot;+350,
0quot;) 



wait_for
do 





assert
selenium.is_ordered( 







quot;id=#{dom_id(photo1)}quot;, 







quot;id=#{dom_id(photo2)}quot;) 



end 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 45. Automating a real web browser is slow Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 46. Quick demo Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 47. One More Thing... Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 48. Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 49. Rack::Test require
quot;rack/testquot; class
HomepageTest
<
Test::Unit::TestCase 

include
Rack::Test::Methods 

 

def
app 



MyApp.new 

end 

 

def
test_redirect_logged_in_users_to_dashboard 



authorize
quot;bryanquot;,
quot;secretquot; 



get
quot;/quot; 



follow_redirect! 



 



assert_equal
quot;http://example.org/redirectedquot;,
last_request.url 



assert
last_response.ok? 

end end Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 50. Rack::Test API #get(uri,
params
=
{},
env
=
{}) #post,
#put,
#delete,
and
#head #request(uri,
env
=
{}) #follow_redirect! #header(name,
value) #authorize(username,
password) #last_request #last_response Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 51. Webrat adapters • Rails • Merb • Sinatra • Selenium • Mechanize Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 52. Webrat adapters • Rack::Test • Selenium • Mechanize Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 53. Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  • 54. Thanks http://www.flickr.com/photos/tambako/2908186658/ http://www.flickr.com/photos/pkmousie/2199520904/ http://www.flickr.com/photos/audreyjm529/155024495/ http://www.flickr.com/photos/acaben/541334636/ http://www.flickr.com/photos/millermz/3267766667/ Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009