Brownie
                  Masaki Nakagawa / @ikasam_a

                           Yokohama.pm #8
                 (yokohama.pm.org/2011/10/yokohamapm-8.html)




2011   11   18
YAPC::Asia Tokyo 2011
                       yapcasia.org/2011/




2011   11   18
Perl Testing
                       Consideration
                          (seen from other languages)


                               Masaki Nakagawa

                 YAPC::Asia Tokyo 2011 (yapcasia.org/2011/talk/80)



2011   11   18
Rails Testing
                 •   Perspective
                     •   UnitTest, End-to-End

                 •   Frameworks
                     •   Test::Unit (+ Shoulda), RSpec, Cucumber

                 •   Browser Integration
                     •   Capybara (rack-test, Selenium, Envjs, ...)

                 •   Test Double
                     •   rspec-mocks, rr, WebMock

2011   11   18
Weakness
                 • Expectation and Verification
                  • vs. rr, rspec-mocks, mocha, ...
                 • Browser Integration API
                  • vs. Capybara, Webrat, ...
                 • Naming of Test Double modules
                  • Test::Mock::Guard is “Stub” module
2011   11   18
Comparision
                 • Pros
                  • TAP-based Test Description
                  • Many Helpful Modules
                 • Cons
                  • Non-Uniform Browser Integration
                  • Poor Expectation and Verification
2011   11   18
Capybara
                 github.com/jnicklas/capybara




2011   11   18
Capybara simulates how a real user would
                     interact with a web application.

                 It is agnostic about the driver running your
                 tests and currently comes with Rack::Test
                         and Selenium support built in.




2011   11   18
within("#session") do
     fill_in 'Login', :with => 'user@example.com'
     fill_in 'Password', :with => 'password'
   end
   click_link 'Sign in'




2011   11   18
The DSL

2011   11   18
Drivers
                     RackTest
                     Selenium
                     HtmlUnit
                 WebKit (QtWebKit)
                       Envjs
                    Zombie.js


2011   11   18
Brownie
                 github.com/masaki/Brownie




2011   11   18
Inspired by Capybara


2011   11   18
OO Style
   my $session = Brownie::Session->new;

   $session->visit(‘http://example.com’);

   $session->fill_in(Login => 'user@example.com');
   $session->fill_in(Password => 'password');
   $session->click_link('Sign in');




2011   11   18
DSL Style (Not yet)
   use Brownie::DSL;

   visit ‘http://example.com/’;

   fill_in Login => 'user@example.com';
   fill_in Password => 'password';
   click_link 'Sign in';




2011   11   18
Drivers
                 Selenium (Selenium::Remote::Driver)
                   Mechanize (WWW::Mechanize)

                    HtmlUnit (WWW::HtmlUnit)




2011   11   18
Vocabulary
                  visit, current_url, current_path,
                 status_code, response_headers,
                       title, source, screenshot,
                 click_link, click_button, click_on,
                   fill_in, choose, check, uncheck,
                     select, unselect, attach_file,
                  execute_script, evaluate_script,
                    find_element, find_elements,

2011   11   18
DEMO

2011   11   18
Future

                 • Mechanize Driver (!!!)
                 • Scoping (within “selector” => sub { ... })
                 • Embedded Selenium Server      (Alien::SeleniumRC)

                 • HtmlUnit Driver

2011   11   18
Patches and Collaborators
                       Welcome !!!



2011   11   18
Thank you



2011   11   18

Brownie

  • 1.
    Brownie Masaki Nakagawa / @ikasam_a Yokohama.pm #8 (yokohama.pm.org/2011/10/yokohamapm-8.html) 2011 11 18
  • 2.
    YAPC::Asia Tokyo 2011 yapcasia.org/2011/ 2011 11 18
  • 3.
    Perl Testing Consideration (seen from other languages) Masaki Nakagawa YAPC::Asia Tokyo 2011 (yapcasia.org/2011/talk/80) 2011 11 18
  • 4.
    Rails Testing • Perspective • UnitTest, End-to-End • Frameworks • Test::Unit (+ Shoulda), RSpec, Cucumber • Browser Integration • Capybara (rack-test, Selenium, Envjs, ...) • Test Double • rspec-mocks, rr, WebMock 2011 11 18
  • 5.
    Weakness • Expectation and Verification • vs. rr, rspec-mocks, mocha, ... • Browser Integration API • vs. Capybara, Webrat, ... • Naming of Test Double modules • Test::Mock::Guard is “Stub” module 2011 11 18
  • 6.
    Comparision • Pros • TAP-based Test Description • Many Helpful Modules • Cons • Non-Uniform Browser Integration • Poor Expectation and Verification 2011 11 18
  • 7.
    Capybara github.com/jnicklas/capybara 2011 11 18
  • 8.
    Capybara simulates howa real user would interact with a web application. It is agnostic about the driver running your tests and currently comes with Rack::Test and Selenium support built in. 2011 11 18
  • 9.
    within("#session") do fill_in 'Login', :with => 'user@example.com' fill_in 'Password', :with => 'password' end click_link 'Sign in' 2011 11 18
  • 10.
  • 11.
    Drivers RackTest Selenium HtmlUnit WebKit (QtWebKit) Envjs Zombie.js 2011 11 18
  • 12.
    Brownie github.com/masaki/Brownie 2011 11 18
  • 13.
  • 14.
    OO Style my $session = Brownie::Session->new; $session->visit(‘http://example.com’); $session->fill_in(Login => 'user@example.com'); $session->fill_in(Password => 'password'); $session->click_link('Sign in'); 2011 11 18
  • 15.
    DSL Style (Notyet) use Brownie::DSL; visit ‘http://example.com/’; fill_in Login => 'user@example.com'; fill_in Password => 'password'; click_link 'Sign in'; 2011 11 18
  • 16.
    Drivers Selenium (Selenium::Remote::Driver) Mechanize (WWW::Mechanize) HtmlUnit (WWW::HtmlUnit) 2011 11 18
  • 17.
    Vocabulary visit, current_url, current_path, status_code, response_headers, title, source, screenshot, click_link, click_button, click_on, fill_in, choose, check, uncheck, select, unselect, attach_file, execute_script, evaluate_script, find_element, find_elements, 2011 11 18
  • 18.
  • 19.
    Future • Mechanize Driver (!!!) • Scoping (within “selector” => sub { ... }) • Embedded Selenium Server (Alien::SeleniumRC) • HtmlUnit Driver 2011 11 18
  • 20.
    Patches and Collaborators Welcome !!! 2011 11 18
  • 21.