Your SlideShare is downloading. ×
0
Ruby Acceptance Testing for Web Applications



   Webrat                                                              bry...
Bryan Helmkamp




   Webrat                                                             brynary.com
                     ...
Beer Disclaimer




   Webrat                                                             brynary.com
                    ...
Webrat                                                             brynary.com
                         http://bit.ly/wbrt...
class
RepositoryTest
<
ActionController::IntegrationTest
   

test
quot;create
a
new
repositoryquot;
do
   



get_via_red...
class
RepositoryTest
<
ActionController::IntegrationTest
   

test
quot;create
a
new
repositoryquot;
do
   



get_via_red...
class
RepositoryTest
<
ActionController::IntegrationTest
   

test
quot;create
a
new
repositoryquot;
do
   



get_via_red...
class
RepositoryTest
<
ActionController::IntegrationTest
   

test
quot;create
a
new
repositoryquot;
do
   



get_via_red...
Webrat
 class
RepositoryTest
<
ActionController::IntegrationTest
 

test
quot;create
a
new
repositoryquot;
do
 



visit
r...
Webrat
 class
RepositoryTest
<
ActionController::IntegrationTest
 

test
quot;create
a
new
repositoryquot;
do
 



visit
r...
Webrat
 class
RepositoryTest
<
ActionController::IntegrationTest
 

test
quot;create
a
new
repositoryquot;
do
 



visit
r...
Webrat
 class
RepositoryTest
<
ActionController::IntegrationTest
 

test
quot;create
a
new
repositoryquot;
do
 



visit
r...
Webrat
 class
RepositoryTest
<
ActionController::IntegrationTest
 

test
quot;create
a
new
repositoryquot;
do
 



visit
r...
Getting started
      #
config/environments/test.rb
      config.gem
quot;webratquot;,
:version
=>
quot;>=0.4.4quot;

    ...
Webrat’s Core API
                          #visit
                          #click_link
                          #fill_i...
Works with RSpec
            describe
quot;repository
managementquot;
do
            

it
quot;should
create
a
repository
...
Works with Shoulda
 class
RepositoryTest
<
ActionController::IntegrationTest
 

context
quot;repository
managementquot;
do...
Works with Cucumber

            Feature:
Manage
repositories

            

Scenario:
Create
repository
with
name

      ...
Works with Cucumber
               When
/^I
create
a
repository$/
do
               

visit
repositories_path
            ...
Sinatra
                            Application
                            Frameworks


   Webrat                        ...
Matches labels to fields

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


    <label
for=qu...
Matches labels to fields

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


    <label
for=qu...
Matches labels to fields
                         <label>
                         

<input
type=quot;checkboxquot;
name=qu...
Matches labels to fields
                         <label>
                         

<input
type=quot;checkboxquot;
name=qu...
Webrat verifies web app behaviour




   Webrat                                                             brynary.com
   ...
Verifies HTTP status codes

 

1)
Error:
 test_create_a_new_repository(RepositoryTest):
 Webrat::PageLoadError:
Page
load
w...
Verifies form fields

 

1)
Error:
 test_create_a_new_repository(RepositoryTest):
 Webrat::NotFoundError:
Could
not
find
fie...
Verify HTML content

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

   response.should
have_selector(quot;liquot;,
:...
Verify HTML content

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

   

li.should
have_selec...
save_and_open_page
   Webrat                                                                brynary.com
                  ...
Webrat adapters

                     • Rails
                     • Merb
                     • Sinatra
                 ...
WWW::Mechanize
   require
quot;webratquot;
   require
quot;webrat/mechanizequot;

   session
=
Webrat::MechanizeSession.ne...
Selenium

   Webrat                                                             brynary.com
                         http:...
#
test/test_helper.rb
                class
ActiveSupport::TestCase
                

#
...
                

self.use_tra...
$
rake
test:integration
   Started
   ==>
Waiting
for
Selenium
RC
server
on
port
4444...
Ready!
   ==>
Waiting
for
Rails
a...
$
rake
test:integration
   Started
   ==>
Waiting
for
Selenium
RC
server
on
port
4444...
Ready!
   ==>
Waiting
for
Rails
a...
$
rake
test:integration
   Started
   ==>
Waiting
for
Selenium
RC
server
on
port
4444...
Ready!
   ==>
Waiting
for
Rails
a...
Webrat::Selenium




                                        Selenium RC Server




   Webrat                             ...
One method, two modes
   def
upload_photo
   

webrat.simulate
do
   



simulate_uploads
   

end

   

webrat.automate
d...
One method, two modes
   def
upload_photo
   

webrat.simulate
do
   



simulate_uploads
   

end

   

webrat.automate
d...
One method, two modes
   def
upload_photo
   

webrat.simulate
do
   



simulate_uploads
   

end

   

webrat.automate
d...
class
MediaTest
<
ActionController::IntegrationTest
 

test
quot;drag
and
drop
mediaquot;
do
 



album


=
create_album
:...
class
MediaTest
<
ActionController::IntegrationTest
 

test
quot;drag
and
drop
mediaquot;
do
 



album


=
create_album
:...
class
MediaTest
<
ActionController::IntegrationTest
 

test
quot;drag
and
drop
mediaquot;
do
 



album


=
create_album
:...
Automating a real web browser is slow


   Webrat                                                              brynary.com...
Quick demo



   Webrat                                                             brynary.com
                         h...
One More Thing...




   Webrat                                                              brynary.com
                 ...
Webrat                                                             brynary.com
                         http://bit.ly/wbrt...
Rack::Test
            require
quot;rack/testquot;

            class
HomepageTest
<
Test::Unit::TestCase
            

in...
Rack::Test API
                         #get(uri,
params
=
{},
env
=
{})
                         #post,
#put,
#delete,
an...
Webrat adapters

                     • Rails
                     • Merb
                     • Sinatra
                 ...
Webrat adapters

                     • Rack::Test
                     • Selenium
                     • Mechanize

   We...
Webrat                                                             brynary.com
                         http://bit.ly/wbrt...
Thanks
                          http://www.flickr.com/photos/tambako/2908186658/
                          http://www.flick...
Upcoming SlideShare
Loading in...5
×

Webrat: Rails Acceptance Testing Evolved

6,959

Published on

Webrat slides from GoGaRuCo 2009 in San Francisco.

Published in: Technology
2 Comments
20 Likes
Statistics
Notes
No Downloads
Views
Total Views
6,959
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
104
Comments
2
Likes
20
Embeds 0
No embeds

No notes for slide

Transcript of "Webrat: Rails Acceptance Testing Evolved"

  1. 1. Ruby Acceptance Testing for Web Applications Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  2. 2. Bryan Helmkamp Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  3. 3. Beer Disclaimer Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  4. 4. Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  5. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 20. Sinatra Application Frameworks Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  21. 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. 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. 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. 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. 25. Webrat verifies web app behaviour Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  26. 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. 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. 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. 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. 30. save_and_open_page Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  31. 31. Webrat adapters • Rails • Merb • Sinatra • Selenium • Mechanize Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  32. 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. 33. Selenium Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  34. 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. 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. 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. 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. 38. Webrat::Selenium Selenium RC Server Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  39. 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. 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. 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. 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. 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. 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. 45. Automating a real web browser is slow Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  46. 46. Quick demo Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  47. 47. One More Thing... Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  48. 48. Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  49. 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. 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. 51. Webrat adapters • Rails • Merb • Sinatra • Selenium • Mechanize Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  52. 52. Webrat adapters • Rack::Test • Selenium • Mechanize Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  53. 53. Webrat brynary.com http://bit.ly/wbrt-ggrc @brynary #webrat Sunday, April 19, 2009
  54. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×