Download - Selenium Basics
![Page 1: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/1.jpg)
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
![Page 2: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/2.jpg)
“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
![Page 3: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/3.jpg)
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
![Page 4: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/4.jpg)
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
![Page 5: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/5.jpg)
SELENIUM IDIOMS
• Verify vs. Assert
• Location, location, location!
• ClickAndWait, and wait, and wait...
Tuesday, September 25, 12
![Page 6: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/6.jpg)
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
![Page 7: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/7.jpg)
“SHUT UP AND SHOW ME THE CODE!”
Tuesday, September 25, 12
![Page 8: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/8.jpg)
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
![Page 9: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/9.jpg)
HONORABLE MENTION
•Moving between windows and frames
• Pop-up dialogs
•Drag and Drop
• Cookies
• Changing the User Agent
Tuesday, September 25, 12
![Page 10: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/10.jpg)
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
![Page 11: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/11.jpg)
“NO REALLY, SHUT UP AND SHOW ME
THE CODE!”
Tuesday, September 25, 12
![Page 12: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/12.jpg)
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
![Page 13: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/13.jpg)
“IS THAT IT?”
Tuesday, September 25, 12
![Page 14: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/14.jpg)
DIY FRAMEWORKrobot/
.rspecRakefileGemfileart/
results.htmlbrains/
config.rbpage_objects/
google_search.rbguts/
Tuesday, September 25, 12
![Page 15: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/15.jpg)
FRAMEWORK CONT’D
rake robot:run
Code available at github.com/tourdedave/diy_framework
Tuesday, September 25, 12
![Page 16: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/16.jpg)
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
![Page 17: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/17.jpg)
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
![Page 18: Selenium Basics](https://reader034.vdocuments.site/reader034/viewer/2022052321/556252f6d8b42aa02d8b5143/html5/thumbnails/18.jpg)
Q&A
@TourDeDaveQA-Lounge.com
Tuesday, September 25, 12