selenium basics

18
SELENIUM BASICS brought to you by the QA Lounge Show of hands new 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

Upload: dave-haeffner

Post on 25-May-2015

2.077 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Selenium Basics

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

“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

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

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

SELENIUM IDIOMS

• Verify vs. Assert

• Location, location, location!

• ClickAndWait, and wait, and wait...

Tuesday, September 25, 12

Page 6: Selenium Basics

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

“SHUT UP AND SHOW ME THE CODE!”

Tuesday, September 25, 12

Page 8: Selenium Basics

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

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

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

“NO REALLY, SHUT UP AND SHOW ME

THE CODE!”

Tuesday, September 25, 12

Page 12: Selenium Basics

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

“IS THAT IT?”

Tuesday, September 25, 12

Page 14: Selenium Basics

DIY FRAMEWORKrobot/

.rspecRakefileGemfileart/

results.htmlbrains/

config.rbpage_objects/

google_search.rbguts/

Tuesday, September 25, 12

Page 15: Selenium Basics

FRAMEWORK CONT’D

rake robot:run

Code available at github.com/tourdedave/diy_framework

Tuesday, September 25, 12

Page 16: Selenium Basics

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

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

Q&A

@TourDeDaveQA-Lounge.com

Tuesday, September 25, 12