selenium basics
TRANSCRIPT
SELENIUM BASICSbrought to you by the QA Lounge
Show of handsnew to Selenium?some experience with?experienced?
new to programming?some experience with?experienced?not sure how to answer?
Intro* I’m Dave Haeffner* I’ve been doing QA and automated web testing for 4 years* Most of that time was spent at The Motley Fool* More recently I started my own consulting company and work with software development shops to help them with QA strategy and implementing automated web testing
Tuesday, September 25, 12
“WHAT IS SELENIUM? TELL ME LIKE I’M 5.”
Selenium is a software robot sent from the future to test our software.
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 IDEI 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-Actionget fetch a page
navigate same as get to, forward, back
find_element(a.k.a. “by” strategies)
(:id, “idtext”)
click, textfind_element(a.k.a. “by” strategies)
(:class, “classtext”)
click, textfind_element(a.k.a. “by” strategies)
(:tag_name, “tagtext”)click, textfind_element
(a.k.a. “by” strategies) (:name, “nametext”) click, textfind_element(a.k.a. “by” strategies)
(:link, “linktext”)click, textfind_element
(a.k.a. “by” strategies)
(:partial_link_text, “”)
click, textfind_element(a.k.a. “by” strategies)
(:css, “csstext”)
click, text
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 RSPECThing Action Sub-Action
object shouldshould_not
include(“text”)start_with(“text”)end_with(“text”)equal(expected)be(expected)be > expected
be >= expectedbe <= expectedbe < expected
match(/expression/)
Tuesday, September 25, 12
“NO REALLY, SHUT UP AND SHOW ME
THE CODE!”
Tuesday, September 25, 12
PAGE OBJECT PATTERN
• 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
Create a classPass the session to itStore and use it through an instance variableAssertions done outside of the class
Tuesday, September 25, 12
“IS THAT IT?”
Tuesday, September 25, 12
DIY FRAMEWORKrobot/
.rspecRakefileGemfileart/
results.htmlbrains/
config.rbpage_objects/
google_search.rbguts/
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
@TourDeDaveQA-Lounge.com
Tuesday, September 25, 12