FAILING GRACEFULLY
with Selenium and T.D.D.
FAILURE
IT’S A WAY OF LIFE
OBVIOUS
FAILURE
PREDICTABLE
SURPRISE
GRACEFUL
HOW TO COPE?
DENY IT
JUST BE VAGUE
GO ON THE OFFENSIVE
STALL FOR TIME
Better strategies? maybe just ....



CLEARER INSTRUCTIONS!
FAILURE IS NATURAL.
Good, even.
Good, even.



               (fail)


              (win)
AS PROGRAMMERS
  we fail all the time.
The only way to fail less is to


ANTICIPATE FAILURE
The only way to fail less is to


ANTICIPATE FAILURE
            and then

DON’T MAKE THE SAME
  MISTAKE AGAIN
        :)
THINGS HAPPEN.
BUT THEN ...
AND THEN ...
AND, WELL ...
TESTING CAN HELP.
HUMAN Q.A. TESTING
                     is the ideal.

(Too bad humans are so much better at other things and
          ne...
SELENIUM IS

A tool for helping to automate testing.
ACTUALLY...
There are many kinds of
   automated tests




                          http://www.flickr.com/photos/60648084@...
UNIT TESTS
* For individual functions
* The cutest test.




                         http://www.flickr.com/photos/donsolo/...
INTEGRATION TESTS
* For groups of related
functionality

* More relevant and
(almost) fun to write




                   ...
ACCEPTANCE TESTS
    * Highest level
    testing.

    * Basically user
    stories.

    * “Accepted” as in
    “get fired...
don’t get confused:


REGRESSION TESTING

(Is part of all of these, not another style)
So, let’s back up a sec.
      Let me tell you a story about ...




UNIT TESTING IN RUBY
           http://www.flickr.com/...
ASSERT
svn ci -m “math library passes
         unit tests!!”
Integration testing is super cool
You can really smell the relevance.




             (seriously)
HOORAY FOR USER STORIES!




      Strive to pass good user-centered tests.


             http://www.lukeredpath.co.uk/bl...
B.D.D. = BEHAVIOR DRIVEN
      DEVELOPMENT




         in rspec
(which uh, actually runs)
WAIT: IT’S IMPORTANT HOW YOU DO IT!!
http://atlalt.net/screwturn/MTG-2008-07-23%20Pub%20Night.ashx
http://blog.briandicroce.com/2008/03/14/three-index-cards-to-easily-remember-the-essence-of-test-driven-development/
RIGHT.
 SO, ANYWAY ...
  BACK TO THIS
SELENIUM THING
SELENIUM IS INCREDIBLY...
WEIRD
why:
It’s a Firefox plugin for testing.
Turns your actions into test code.
Let’s you edit test code in the browser.
Let’s ...
FUN
why:
It’s a Firefox plugin for testing.
Turns your actions into test code.
Let’s you edit test code in the browser.
Let’s ...
POWERFUL
why:
It’s a Firefox plugin for testing.
Turns your actions into test code.
Let’s you edit test code in the browser.
Let’s ...
FIRE-FOXY AND SIMPLE




  Start here: http://seleniumhq.org/
(then go here)



HTTP://SELENIUMHQ.ORG/DOCS/
no forget about that

LETS JUST WRITE A TEST
       ALREADY!
Now: Record and Playback

•   Intelligent field selection will use IDs, names, or
    XPath as needed

•   Autocomplete for...
Watch this video:
GO RED
(WRITE MORE CODE)
THEN GO GREEN
SPEAK SELENESE

open
       opens a page using a URL.

click/clickAndWait
    performs a click operation, and
optionally w...
VERIFY PAGE ELEMENTS
                      is ...

1. an element is present somewhere on the page?
     2. specific text is...
GOTCHAS

• clickAndWait         is usually
  required

• type    usually requires you
  to click somewhere else first

• it...
HARD PART’S JUST FINDING IT
            Good thing you have so many options ...

• find    elements by name

• find    them ...
Now,

SELENIUM IDE
 is not the same as


SELENIUM RC
IDE and RC play great together!
RC                 Remote Control, that is.


• Runtests in multiple
 browsers.

• Runthem remotely (on a
 dedicated serve...
exported test to c#
exported test in java
exported test to ruby
Selenium-RC leverages the full power of
programming languages, creating tests that
can do things like


• read   and write...
RC can where IDE can’t
•   condition statements
•   iteration
•   logging and reporting of test results
•   error handling...
WAIT, WHAT ABOUT TEST-
DRIVEN DEVELOPMENT?
  If you click around the app to build a test,
 that can’t be testing before de...
RIGHT.
You actually should write them beforehand, by hand, just like
            you would unit tests. It’s not so scary.
...
PUT IT ALL TOGETHER
Put it on your SVN server
trigger it with SVN hooks
Continuous Integration
with Selenium and Criuse Control
WHAT IT MEANS

• Run    your unit tests first locally (because they’re fast).
• Checking  in your changes triggers the cont...
THANKS!

             :)
           Chris Blow
    http://unthinkingly.com
User Experience @ Meedan.net
Graceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous Integration
Graceful Failure with Selenium and Continuous Integration
Upcoming SlideShare
Loading in …5
×

Graceful Failure with Selenium and Continuous Integration

1,987 views
1,882 views

Published on

An overview of the why and how of automated software testing, with a focus on continuous integration and selenium.

Published in: Technology, Health & Medicine

Graceful Failure with Selenium and Continuous Integration

  1. 1. FAILING GRACEFULLY with Selenium and T.D.D.
  2. 2. FAILURE
  3. 3. IT’S A WAY OF LIFE
  4. 4. OBVIOUS FAILURE
  5. 5. PREDICTABLE
  6. 6. SURPRISE
  7. 7. GRACEFUL
  8. 8. HOW TO COPE?
  9. 9. DENY IT
  10. 10. JUST BE VAGUE
  11. 11. GO ON THE OFFENSIVE
  12. 12. STALL FOR TIME
  13. 13. Better strategies? maybe just .... CLEARER INSTRUCTIONS!
  14. 14. FAILURE IS NATURAL.
  15. 15. Good, even.
  16. 16. Good, even. (fail) (win)
  17. 17. AS PROGRAMMERS we fail all the time.
  18. 18. The only way to fail less is to ANTICIPATE FAILURE
  19. 19. The only way to fail less is to ANTICIPATE FAILURE and then DON’T MAKE THE SAME MISTAKE AGAIN :)
  20. 20. THINGS HAPPEN.
  21. 21. BUT THEN ...
  22. 22. AND THEN ...
  23. 23. AND, WELL ...
  24. 24. TESTING CAN HELP.
  25. 25. HUMAN Q.A. TESTING is the ideal. (Too bad humans are so much better at other things and need to eat and sleep and stuff ... )
  26. 26. SELENIUM IS A tool for helping to automate testing.
  27. 27. ACTUALLY... There are many kinds of automated tests http://www.flickr.com/photos/60648084@N00/1360619915/
  28. 28. UNIT TESTS * For individual functions * The cutest test. http://www.flickr.com/photos/donsolo/2900765675/in/set-72157594163175020/
  29. 29. INTEGRATION TESTS * For groups of related functionality * More relevant and (almost) fun to write http://www.flickr.com/photos/donsolo/399501571/in/set-72157594163175020/
  30. 30. ACCEPTANCE TESTS * Highest level testing. * Basically user stories. * “Accepted” as in “get fired if they don’t work” http://www.flickr.com/photos/donsolo
  31. 31. don’t get confused: REGRESSION TESTING (Is part of all of these, not another style)
  32. 32. So, let’s back up a sec. Let me tell you a story about ... UNIT TESTING IN RUBY http://www.flickr.com/photos/21734563@N04/2198268918/
  33. 33. ASSERT
  34. 34. svn ci -m “math library passes unit tests!!”
  35. 35. Integration testing is super cool
  36. 36. You can really smell the relevance. (seriously)
  37. 37. HOORAY FOR USER STORIES! Strive to pass good user-centered tests. http://www.lukeredpath.co.uk/blog/developing-a-rails-model-using-bdd-and-rspec-part-1.html
  38. 38. B.D.D. = BEHAVIOR DRIVEN DEVELOPMENT in rspec
  39. 39. (which uh, actually runs)
  40. 40. WAIT: IT’S IMPORTANT HOW YOU DO IT!!
  41. 41. http://atlalt.net/screwturn/MTG-2008-07-23%20Pub%20Night.ashx
  42. 42. http://blog.briandicroce.com/2008/03/14/three-index-cards-to-easily-remember-the-essence-of-test-driven-development/
  43. 43. RIGHT. SO, ANYWAY ... BACK TO THIS SELENIUM THING
  44. 44. SELENIUM IS INCREDIBLY...
  45. 45. WEIRD
  46. 46. why: It’s a Firefox plugin for testing. Turns your actions into test code. Let’s you edit test code in the browser. Let’s you export to lots of languages.
  47. 47. FUN
  48. 48. why: It’s a Firefox plugin for testing. Turns your actions into test code. Let’s you edit test code in the browser. Let’s you export to lots of languages.
  49. 49. POWERFUL
  50. 50. why: It’s a Firefox plugin for testing. Turns your actions into test code. Let’s you edit test code in the browser. Let’s you export to lots of languages.
  51. 51. FIRE-FOXY AND SIMPLE Start here: http://seleniumhq.org/
  52. 52. (then go here) HTTP://SELENIUMHQ.ORG/DOCS/
  53. 53. no forget about that LETS JUST WRITE A TEST ALREADY!
  54. 54. Now: Record and Playback • Intelligent field selection will use IDs, names, or XPath as needed • Autocomplete for all common Selenium commands • Walk through tests • Debug and set breakpoints • Save tests as HTML, Ruby scripts, or any other format Totally takes 5 seconds, man
  55. 55. Watch this video:
  56. 56. GO RED
  57. 57. (WRITE MORE CODE)
  58. 58. THEN GO GREEN
  59. 59. SPEAK SELENESE open opens a page using a URL. click/clickAndWait performs a click operation, and optionally waits for a new page to load. verifyTitle/assertTitle verifies an expected page title. verifyTextPresent verifies expected text is somewhere on the page.
  60. 60. VERIFY PAGE ELEMENTS is ... 1. an element is present somewhere on the page? 2. specific text is somewhere on the page? 3. specific text is at a specific location on the page?
  61. 61. GOTCHAS • clickAndWait is usually required • type usually requires you to click somewhere else first • it’s slow • brittle if the UI is changing rapidly
  62. 62. HARD PART’S JUST FINDING IT Good thing you have so many options ... • find elements by name • find them by id if they have it • or with CSS selectors if you understand the cascade • Xpath is like a buzzsaw (a little more expensive) • link text as a last resort (since it changes often)
  63. 63. Now, SELENIUM IDE is not the same as SELENIUM RC
  64. 64. IDE and RC play great together!
  65. 65. RC Remote Control, that is. • Runtests in multiple browsers. • Runthem remotely (on a dedicated server) • Runthem whenever you check in code!
  66. 66. exported test to c#
  67. 67. exported test in java
  68. 68. exported test to ruby
  69. 69. Selenium-RC leverages the full power of programming languages, creating tests that can do things like • read and write external files, • make queries to a database, • send emails with test reports • practically anything else a user can do with a normal application ...
  70. 70. RC can where IDE can’t • condition statements • iteration • logging and reporting of test results • error handling, particularly unexpected errors • database testing • test case grouping • re-execution of failed tests • test case dependency • capture screenshots on test failures
  71. 71. WAIT, WHAT ABOUT TEST- DRIVEN DEVELOPMENT? If you click around the app to build a test, that can’t be testing before development.
  72. 72. RIGHT. You actually should write them beforehand, by hand, just like you would unit tests. It’s not so scary. • NUnit for C# • Junit for Java • Selenium gem for Ruby
  73. 73. PUT IT ALL TOGETHER
  74. 74. Put it on your SVN server trigger it with SVN hooks
  75. 75. Continuous Integration with Selenium and Criuse Control
  76. 76. WHAT IT MEANS • Run your unit tests first locally (because they’re fast). • Checking in your changes triggers the continuous integration server running your Selenium tests (slow because they are in the browser). • Cruise Control gives you a web-based heads up when you fail or pass tests. • Joy.
  77. 77. THANKS! :) Chris Blow http://unthinkingly.com User Experience @ Meedan.net

×