selenium in the real world

27
1 Where are the tests, and how do I run them? Selenium In The Real World Iain Rose May 2012

Upload: iainrose

Post on 17-Jun-2015

1.112 views

Category:

Technology


2 download

TRANSCRIPT

  • 1. Selenium In The Real WorldWhere are the tests, and how do I run them?Iain Rose May 2012

2. INTROA bit about meIain RoseSoftware Engineer in Test, xMattersslides:http://bit.ly/vanqcode:https://github.com/iainrose/vanq-javatwitter: @iainroseemail: [email protected] 3. AGENDAComing up next Selenium & friends Page objects Locators Implicit & explicit waits Building your tests Running your testsTHERE WILL BE CODE!!! 4. W H Y A U T O M AT E ?Regression testing sucks 5. SELENIUM AND FRIENDSThe world it lives in WebDriver API (Java / Ruby / Python / C#) Test FrameworksJava (jUnit, TestNG)Ruby (Test::Unit, MiniTest, Rspec, Cucumber)Python (py.test)C# (nUnit) Build Tools (Ant, Maven, Gradle, Rake .... ) Continuous Integration Server (Jenkins, Bamboo, Cruise Control) Browsers (IE, FF, Chrome, Mobile .... ) Application Under Test 6. A W ORD ABOUT SELENIUM IDEUse with caution 7. R E C O R D & P L AY B A C K ( I S ) F O R D U M M I E SA shortcut to brittle, flaky tests 8. PA G E O B J E C T SA test automation design patternPAGETESTSSELENIUM WEB APP OBJECTS 9. PA G E O B J E C T SUsage guidelines The public methods represent the services that the page offers Try not to expose the internals of the page Generally dont make assertions Methods return other Page Objects Need not represent an entire page Different results for the same action are modelled as different methodshttp://code.google.com/p/selenium/wiki/PageObjects 10. PA G E O B J E C T E X A M P L E : VA N Q . O R GIdentifying Public Methodsclass HomeclickMeetingsTab()clickPastMeetingsLink()getDateOfNextMeeting()getPresenterOfNextMeeting()isVanqLogoDisplayed() 11. PA G E O B J E C T E X A M P L E : VA N Q . O R GSample test method 12. PA G E O B J E C T E X A M P L E : VA N Q . O R GSample page object 13. L O C AT O R SA map to your web application 14. L O C AT O R SWays to save your locators Inline Page Factory By Objects 15. L O C AT O R SWhy I prefer By objectsWebDriver does not have an isElementPresent() method. 16. L O C AT O R SWhy I prefer By object locatorsBy locators allow for nested lookups 17. FIREFINDER PLUGIN FOR FIREFOXA tool for testing CSS & xPath locators 18. WAIT CONDITIONSTiming is everythingImplicit Waits+ Quick to implement+ Covers most scenarios- Slows down tests- Cannot use to wait for absence of Web Elements 19. WAIT CONDITIONSTiming is everythingExplicit Waits 20. WAIT CONDITIONSExplicit Waits+ Most efficient use of waits+ Built in ExpectedConditions class covers majority of scenarios+ Custom wait conditions can be added to cover any other scenario- Need to be manually added to each Page Object methodhttp://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/support/ui/ExpectedConditions.html 21. WAIT CONDITIONSUsage Guidelines Avoid static pauses Use long timeouts Add explicit waits to end of page object action methods Always leave your Web Application in known ready state 22. BUILDING THE TESTSLessons learnt so farKeep tests focusedDont share test dataDo test data tear down at the start of each testPlan to run in parallel from day 1 23. RUNNING THE TESTSTime for actionIDE (Run & Debug)Command Line (Remote and Local)CI ToolSelenium Grid 24. GRADLEBuild ToolNo XMLCan setup your development IDE (IDEA, Eclipse)Dependency management1 line of code runs TestNG & jUnit tests in parallelManage TestNG group inclusions and exclusionsNo XMLNo XML 25. BUILD.GRADLEProject Definition 26. D E M O N S T R AT I O NTime for action