KEMBAR78
Selenium Basics | PDF
Intro
          * I’m Dave Haeffner                                Show of hands
          * I’ve been doing QA and automated                 new to Selenium?
          web testing for 4 years                            some experience with?
          * Most of that time was spent at                   experienced?
          The Motley Fool
          * More recently I started my own                   new to programming?
          consulting company and work with                   some experience with?
          soft ware development shops to help                experienced?
          them with QA strategy and                          not sure how to answer?
          implementing automated web
          testing




                                   SELENIUM BASICS
                                      brought to you by the QA Lounge




Tuesday, September 25, 12
“WHAT IS SELENIUM? TELL
                    ME LIKE I’M 5.”
                               Selenium is a soft ware
                               robot sent from the
                               future to test our
                               soft ware.




Tuesday, September 25, 12
PREFACE

          There are many ways to implement Selenium & a framework

                            I will show you one that has worked for me

                            There will be code involved (and opinions!)

         These examples do not reflect a comprehensive QA strategy

                                       But it’s a good start


Tuesday, September 25, 12
SELENIUM IDE
                                    I debated showing you the IDE since it’s the unloved
                                    child of the Selenium community.

                                    But it is responsible for the wide spread success of
                                    Selenium.

                                    I consider it to be less of an unloved orphan and
                                    more of a gateway drug




Tuesday, September 25, 12
SELENIUM IDIOMS


    • Verify           vs. Assert

    • Location, location, location!

    • ClickAndWait, and             wait, and wait...




Tuesday, September 25, 12
LET ME EXPLAIN

    • Ruby            is approachable -- it can read like English

    • There’s                also that “standing on the shoulder of giants thing”

    • RSpec                 is an open-source testing tool built in Ruby for Ruby

         • It’s      kind of a big deal

         • Loads             of functionality out of the box

         • Quite             customizable

Tuesday, September 25, 12
“SHUT UP AND SHOW
                           ME THE CODE!”



Tuesday, September 25, 12
COMMON ACTIONS

                      Name                Action            Sub-Action
                       get             fetch a page
                     navigate          same as get        to, forward, back
                               (:id, “idtext”)
                               (:class, “classtext”)
                               (:tag_name, “tagtext”)
           find_element
                               (:name, “nametext”)           click, text
      (a.k.a. “by” strategies)
                               (:link, “linktext”)
                               (:partial_link_text, “”)
                               (:css, “csstext”)

Tuesday, September 25, 12
HONORABLE MENTION

    • Moving                between windows and frames

    • Pop-up                dialogs

    • Drag            and Drop

    • Cookies

    • Changing                the User Agent


Tuesday, September 25, 12
ASSERTIONS THRU RSPEC
                            Thing      Action         Sub-Action
                                                     include(“text”)
                                                   start_with(“text”)
                                                   end_with(“text”)
                                                    equal(expected)
                                       should         be(expected)
                            object
                                     should_not      be > expected
                                                    be >= expected
                                                    be <= expected
                                                     be < expected
                                                  match(/expression/)

Tuesday, September 25, 12
“NO REALLY,
                 SHUT UP AND SHOW ME
                      THE CODE!”



Tuesday, September 25, 12
PAGE OBJECT PATTERN
                                                         Create a class
                                                         Pass the session to it
                                                         Store and use it through an instance variable
                                                         Assertions done outside of the class
    • Relieves              many test maintenance woes

    • Keeps             things DRY rather than WET

    • Create   an object that represents a page (or component of a
        page) and test against that

    • If    the UI changes, you change just the object, not the tests

    • Also           helps you make things more readable

Tuesday, September 25, 12
“IS THAT IT?”




Tuesday, September 25, 12
robot/
                                                 DIY FRAMEWORK
                     .rspec
                     Rakefile
                     Gemfile
                     art/
                            results.html
                     brains/
                            config.rb
                            page_objects/
                              google_search.rb
                     guts/



Tuesday, September 25, 12
FRAMEWORK CONT’D

                            rake robot:run




      Code available at github.com/tourdedave/diy_framework



Tuesday, September 25, 12
RECAP

    • Selenium                IDE is cool in theory...

    • WebDriver                 is cool.

    • The          Page Object Pattern will make you happy and successful

    • Rolling               your own framework is within your grasp

    • And           it positions you for automation success!


Tuesday, September 25, 12
SOME RESOURCES
    • Selenium                HQ (SeleniumHQ.com/docs/03_webdriver.html)

    • Official               Selenium Blog (SeleniumHQ.Wordpress.com)

    • Ruby            Selenium Bindings (http://bit.ly/seruby)

    • RSpec                 (http://github.com/rspec)

    • Why             Everyone Should Be Code Literate (http://bit.ly/sauceio)

    •A        book to get you started (http://bit.ly/se2book)

    •A        self-proclaimed great resource* (QA-Lounge.com)
Tuesday, September 25, 12
Q&A

                            @TourDeDave
                            QA-Lounge.com



Tuesday, September 25, 12

Selenium Basics

  • 1.
    Intro * I’m Dave Haeffner Show of hands * I’ve been doing QA and automated new to Selenium? web testing for 4 years some experience with? * Most of that time was spent at experienced? The Motley Fool * More recently I started my own new to programming? consulting company and work with some experience with? soft ware development shops to help experienced? them with QA strategy and not sure how to answer? implementing automated web testing SELENIUM BASICS brought to you by the QA Lounge Tuesday, September 25, 12
  • 2.
    “WHAT IS SELENIUM?TELL ME LIKE I’M 5.” Selenium is a soft ware robot sent from the future to test our soft ware. Tuesday, September 25, 12
  • 3.
    PREFACE There are many ways to implement Selenium & a framework I will show you one that has worked for me There will be code involved (and opinions!) These examples do not reflect a comprehensive QA strategy But it’s a good start Tuesday, September 25, 12
  • 4.
    SELENIUM IDE I debated showing you the IDE since it’s the unloved child of the Selenium community. But it is responsible for the wide spread success of Selenium. I consider it to be less of an unloved orphan and more of a gateway drug Tuesday, September 25, 12
  • 5.
    SELENIUM IDIOMS • Verify vs. Assert • Location, location, location! • ClickAndWait, and wait, and wait... Tuesday, September 25, 12
  • 6.
    LET ME EXPLAIN • Ruby is approachable -- it can read like English • There’s also that “standing on the shoulder of giants thing” • RSpec is an open-source testing tool built in Ruby for Ruby • It’s kind of a big deal • Loads of functionality out of the box • Quite customizable Tuesday, September 25, 12
  • 7.
    “SHUT UP ANDSHOW ME THE CODE!” Tuesday, September 25, 12
  • 8.
    COMMON ACTIONS Name Action Sub-Action get fetch a page navigate same as get to, forward, back (:id, “idtext”) (:class, “classtext”) (:tag_name, “tagtext”) find_element (:name, “nametext”) click, text (a.k.a. “by” strategies) (:link, “linktext”) (:partial_link_text, “”) (:css, “csstext”) Tuesday, September 25, 12
  • 9.
    HONORABLE MENTION • Moving between windows and frames • Pop-up dialogs • Drag and Drop • Cookies • Changing the User Agent Tuesday, September 25, 12
  • 10.
    ASSERTIONS THRU RSPEC Thing Action Sub-Action include(“text”) start_with(“text”) end_with(“text”) equal(expected) should be(expected) object should_not be > expected be >= expected be <= expected be < expected match(/expression/) Tuesday, September 25, 12
  • 11.
    “NO REALLY, SHUT UP AND SHOW ME THE CODE!” Tuesday, September 25, 12
  • 12.
    PAGE OBJECT PATTERN Create a class Pass the session to it Store and use it through an instance variable Assertions done outside of the class • Relieves many test maintenance woes • Keeps things DRY rather than WET • Create an object that represents a page (or component of a page) and test against that • If the UI changes, you change just the object, not the tests • Also helps you make things more readable Tuesday, September 25, 12
  • 13.
  • 14.
    robot/ DIY FRAMEWORK .rspec Rakefile Gemfile art/ results.html brains/ config.rb page_objects/ google_search.rb guts/ Tuesday, September 25, 12
  • 15.
    FRAMEWORK CONT’D rake robot:run Code available at github.com/tourdedave/diy_framework Tuesday, September 25, 12
  • 16.
    RECAP • Selenium IDE is cool in theory... • WebDriver is cool. • The Page Object Pattern will make you happy and successful • Rolling your own framework is within your grasp • And it positions you for automation success! Tuesday, September 25, 12
  • 17.
    SOME RESOURCES • Selenium HQ (SeleniumHQ.com/docs/03_webdriver.html) • Official Selenium Blog (SeleniumHQ.Wordpress.com) • Ruby Selenium Bindings (http://bit.ly/seruby) • RSpec (http://github.com/rspec) • Why Everyone Should Be Code Literate (http://bit.ly/sauceio) •A book to get you started (http://bit.ly/se2book) •A self-proclaimed great resource* (QA-Lounge.com) Tuesday, September 25, 12
  • 18.
    Q&A @TourDeDave QA-Lounge.com Tuesday, September 25, 12