automated web testing with selenium
DESCRIPTION
Automated Web Testing With SeleniumTRANSCRIPT
![Page 1: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/1.jpg)
Automated Web Testingwith
SeleniumDeepak MittalDec 15, 2007
![Page 2: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/2.jpg)
http://www.IntelliGrape.com
Agenda• Introduction to Selenium• Quick Demo• Different ways of using Selenium• Best practices with using Selenium• Questions & Feedback
![Page 3: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/3.jpg)
http://www.IntelliGrape.com
Quick Poll• Do you do Web Testing?• Do you do automated Web Testing?• Do you need to support & test your web
app on multiple browsers?• Which automated webtesting frameworks
do you use?
![Page 4: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/4.jpg)
http://www.IntelliGrape.com
What is Selenium?
• A JavaScript based• Open Source• Web testing tool• That supports testing Web 2.0 applications• On multiple browsers• And multiple Operating Systems
![Page 5: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/5.jpg)
http://www.IntelliGrape.com
What is Selenium• Acceptance Testing tool for webapps
• Tests run directly in browser
• Implemented entirely using browser technologies
• JavaScript• DHTML• Frames
![Page 6: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/6.jpg)
http://www.IntelliGrape.com
Origins of Selenium
• Developed by ThoughtWorks to test new time and expenses system
• Selenium is the key mineral to protect body from mercury toxicity
• http://www.openqa.org/selenium
![Page 7: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/7.jpg)
http://www.IntelliGrape.com
Selenium Modes
• Test Runner Mode• test cases in HTML tables
• RecordPlayback mode (Selenium IDE)• Selenium Remote Control (RC) Mode
• testcases in your language of choice
![Page 8: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/8.jpg)
http://www.IntelliGrape.com
Selenium Modes
• Test Runner Mode• test cases in HTML tables
• RecordPlayback mode (Selenium IDE)• Selenium Remote Control (RC) Mode
• testcases in your language of choice
![Page 9: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/9.jpg)
http://www.IntelliGrape.com
Test Runner Mode
![Page 10: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/10.jpg)
http://www.IntelliGrape.com
Selenium HTML Tests
• Selenium tests are HTML files• Selenium interacts with the DOM served to
browser• Selenium is agnostic of server side
technology• Selenium HTML language is called
Selenese
![Page 11: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/11.jpg)
http://www.IntelliGrape.com
Selenese• Selenium declarative DSL : Selenese• Selenium understands two types of HTML
files (which have simple HTML tables):–Tests–Test Suites
• Every test is contained within a test suite• Point TestRunner.html at the test suite to
run it
![Page 12: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/12.jpg)
http://www.IntelliGrape.com
Format of a Selenium Test
• HTML Table with 3 columns –First Column: Selenium command–Second Column: Target of command–Third Column: Optional parameter
![Page 13: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/13.jpg)
http://www.IntelliGrape.com
Selenium Concepts
• Element Locators : specify HTML elements• Patterns : for pattern matching values• Action : manipulate app state• Accessors : store results in variables• Assertion : verify that the app is in a certain
state
![Page 14: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/14.jpg)
http://www.IntelliGrape.com
Test Runner Demo
• See Demo suite• Look at tests bundled with Selenium• Running selenium test in slow and fast
mode
![Page 15: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/15.jpg)
http://www.IntelliGrape.com
Problems with HTML Tests
• Selenium is sensitive to the format of the table
• No separation of concern• Duplication is a major issue• Tests need to be deployed with AUT
(Application under Test)
![Page 16: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/16.jpg)
http://www.IntelliGrape.com
Selenium Modes
• Test Runner Mode• test cases in HTML tables
• RecordPlayback mode (Selenium IDE)• Selenium Remote Control (RC) Mode
• testcases in your language of choice
![Page 17: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/17.jpg)
http://www.IntelliGrape.com
Selenium IDE
• Very useful tool for beginners• Firefox extension which allows record/play
testing paradigm• Automates commands, but asserts must be
entered by hand• Creates the simplest possible Locator• Based on Selenese
![Page 18: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/18.jpg)
http://www.IntelliGrape.com
Selenium IDE Demo
• Look at firefox extension• Look at various possible commands• Record a test on AUT and playback• Save the test at HTML file• Export the test as Java / Ruby
![Page 19: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/19.jpg)
http://www.IntelliGrape.com
Selenium Modes
• Test Runner Mode• test cases in HTML tables
• RecordPlayback mode (Selenium IDE)• Selenium Remote Control (RC) Mode
• testcases in your language of choice
![Page 20: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/20.jpg)
http://www.IntelliGrape.com
Selenium RC Mode
![Page 21: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/21.jpg)
http://www.IntelliGrape.com
Selenium RC Mode Demo• Run selenium server• Look at sample tests
![Page 22: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/22.jpg)
http://www.IntelliGrape.com
Maintaining Selenium Tests
• Test code is just like production code• Needs refactoring, abstraction• API for the application• Can build tests from API building blocks• Try to maintain meaning – in test names,
variable names, comments, and suite organization
![Page 23: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/23.jpg)
http://www.IntelliGrape.com
Selenium with Continuous Integration
• Run Selenium tests as part of the build• Can generate HTML reports, published to
entire team• Helps catch bugs ASAP
![Page 24: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/24.jpg)
http://www.IntelliGrape.com
Ajax Support
• Selenium supports testing Web 2.0 applications
• Monitor the DOM for completion of Async calls
• waitForCondition(script, timeout)
![Page 25: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/25.jpg)
http://www.IntelliGrape.com
Useful Selenium Tools
• Chris Pederick's Web Developer toolbar• XPather• Firebug• Xpath Checker
![Page 26: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/26.jpg)
http://www.IntelliGrape.com
Selenium Best Practices
• Use Ids wherever possible (xpaths make the tests brittle)
• Use datadriven tests. Use a JSP/PHP page to generate tests
• In order to generate unique Ids, use timestamp
• Use the right level of granularity
![Page 27: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/27.jpg)
http://www.IntelliGrape.com
What have we not covered?
• Continuous Integration setups• Creating screencasts using Selenium• Testing of Ajax applications• Selenium Commands in detail• User Extensions• Using Python/Ruby/C# ...
![Page 28: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/28.jpg)
http://www.IntelliGrape.com
Selenium Limitations
• Slow when testing all the edge cases• Slow for testing finegrained features – set
up and teardown are called for each test
![Page 29: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/29.jpg)
http://www.IntelliGrape.com
Selenium Strengths
• For testing Ajax applications• Multiple browsers• Test fullstack
![Page 30: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/30.jpg)
http://www.IntelliGrape.com
Interesting Possibilities
• Delivering Selenium Screencast as Documentation to endusers
• Creating a report with screenshots • A Server having VMWare images of various
OS/browser and each submitting a report back
![Page 31: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/31.jpg)
http://www.IntelliGrape.com
Summary
• Selenium is a testing framework for Web Applications
• Drivers allow web testing in language of choice
• Test scripts are code: need maintenance, refactoring
![Page 32: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/32.jpg)
http://www.IntelliGrape.com
Summary
• Can be used on Developer machines• Most valuable when used with CI setup• Can be used to make screen casts• Tests run on real browser – most people
use it to test their JavaScript works predictably on all browsers
![Page 33: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/33.jpg)
http://www.IntelliGrape.com
Summary
• Can be used for unittesting, regression testing, smoketesting, integration and acceptance testing
![Page 34: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/34.jpg)
http://www.IntelliGrape.com
References / Attribution
• Neal Ford's presentation on Selenium• Selenium site
This work is licensed under the Creative Commons AttributionNoncommercialShare Alike 3.0 License http://creativecommons.org/licenses/byncsa/3.0/
![Page 35: Automated Web Testing With Selenium](https://reader034.vdocument.in/reader034/viewer/2022042601/5456c7b2af795953128b46b8/html5/thumbnails/35.jpg)
http://www.IntelliGrape.com
Feedback
<dmittal> AT <IntelliGrape.com>