Published on

These are the slides I used to introduce one of my classes to web automation using Selenium

Published in: Technology
  • Don't forget the Firefox plugin 'Xpath Checker', it will allow you to validate your xpath locators and see the returned results!
    Are you sure you want to  Yes  No
    Your message goes here
  • Some corrections: You can get selenium support for free from the users group (see PushToTest uses Selenium as one of it's front end test record/playback tools along with SoapUI and others.
    You can get paid for support for Selenium and all the tools that PushToTest incorporates, including their 'TestMaker functional/performance test and production monitor tool which lets you use your tests as functional test cases, load/performance tests and production monitors. See their professional services group at

    It's much easier to use selenium with multi data sets and test cases using testmaker than having to code all that yourself, manually.

    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Selenium Adam Goucher [email_address]
  2. 2. Lecture Objective <ul><li>Give students an introduction to web automation using the Selenium framework. </li></ul>
  3. 3. What is Selenium? <ul><li>Selenium is a web test tool that runs in the browser </li></ul><ul><li>Because it runs in the browser, it does exactly what a user does </li></ul>
  4. 4. What tests can Selenium do? <ul><li>Browser compatibility – One script, many browsers </li></ul><ul><li>Regression </li></ul>
  5. 5. Javascript <ul><li>Selenium is written in Javascript </li></ul><ul><li>Javascript is how AJAX applications are written, so Selenium can test them too </li></ul>
  6. 6. Where to get it? <ul><li>Selenium can be downloaded and installed for free from http:// </li></ul>
  7. 7. QTP vs. Selenium <ul><li>QTP is not cross platform, Selenium is </li></ul><ul><li>QTP costs a lot of money, Selenium is free </li></ul><ul><li>QTP needs VBScript, Selenium has lots of language bindings </li></ul><ul><li>The default format of testing in Selenium is HTML </li></ul><ul><li>QTP can control other types of applications other than web </li></ul>
  8. 8. Multiple Seleniums? <ul><li>There are 3 versions of Selenium </li></ul><ul><li>Selenium Core – The main component of Selenium </li></ul><ul><li>Selenium RC – A scripting layer over Selenium Core </li></ul><ul><li>Selenium IDE – a Firefox extension with record / playback functionality </li></ul>
  9. 9. Selenium IDE <ul><li>Selenium IDE adds a layer of Record / Playback to Selenium </li></ul><ul><li>Is available for Firefox only </li></ul>
  10. 10. First Script link=sqa clickAndWait Submit01 clickAndWait label=Banking ct_category select qa queryTitle type /jobmining/ open Value Target Command
  11. 11. Checkpoints <ul><li>Of course, scripts wouldn’t be tests if they didn’t check something </li></ul><ul><li>assert* tests fail the test immediately </li></ul><ul><li>verify* tests keep track of results and continue the script regardless </li></ul>Job Requirements sdrfasf asserTextPresent Job Description dgds verifyTextPresent
  12. 12. Locators <ul><li>Selenium identifies what a component is through the use of a locator </li></ul><ul><li>link=name </li></ul><ul><li>dom=document.images[56] </li></ul><ul><li>xpath=//table[@id='table1']//tr[4]/td[2] </li></ul><ul><li>css=a[href=&quot;#id3&quot;] </li></ul><ul><li>Depending on your application, there might be major performance differences </li></ul>
  13. 13. Playback <ul><li>Playback of a single script is handled through the IDE </li></ul><ul><li>Run – Go as fast as the script can process </li></ul><ul><li>Walk – Slows down the execution </li></ul><ul><li>Step – Executes the next step </li></ul>
  14. 14. Test Suites <ul><li>In order to run multiple scripts, you need to chain them together in a Test Suite </li></ul><ul><li>Just another html table </li></ul><ul><li>Runs inside Firefox, but not in S-IDE </li></ul><ul><li>Saved in the same directory as the tests that are included in it </li></ul>
  15. 15. Test Suites <ul><li><table> </li></ul><ul><li><tr> </li></ul><ul><li><td>Job Search test suite</td> </li></ul><ul><li></tr> </li></ul><ul><li><tr> </li></ul><ul><li><td><a target=&quot;testFrame&quot; href=“selenium-ide-01.html&quot;>Job Search</a></td> </li></ul><ul><li></tr> </li></ul><ul><li></table> </li></ul>
  16. 16. Test Suites <ul><li>The URL has a specific format </li></ul><ul><li>chrome://selenium-ide/content/selenium/TestRunner.html?baseURL=http://your_hose:port&test=file:///c://temp/qa109/testsuite.html&auto=true&multiWindow=false </li></ul>
  17. 17. Selenium RC <ul><li>Selenium IDE is great for quick recording of tests, but it somewhat lacks for power </li></ul><ul><li>Selenium RC gives you the ability to drive Selenium from a real programming language (Java, Perl, Python, Ruby, and more) </li></ul>
  18. 18. Why do you want a real language? <ul><li>By using Selenium inside a full fledged language you can do the following </li></ul><ul><li>Seed the database </li></ul><ul><li>Check the database </li></ul><ul><li>Control external services </li></ul><ul><li>Launch multiple windows </li></ul><ul><li>Run multiple browsers in parallel </li></ul><ul><li>In addition to running the actual test. </li></ul>
  19. 19. Proxy <ul><li>Because the commands for Selenium RC are embedded in a script, a proxy is needed to control the browser. </li></ul>
  20. 20. Python <ul><li>There are python bindings for most of the Selenium calls </li></ul><ul><li>Watch for naming differences </li></ul><ul><li>While not necessary, most use the unittest module with Selenium </li></ul>
  21. 21. <ul><li>import selenium, unittest </li></ul><ul><li>class JM(unittest.TestCase): </li></ul><ul><li>def setUp(self): </li></ul><ul><li>protocol = &quot;http&quot; </li></ul><ul><li>host = &quot;your host&quot; </li></ul><ul><li>port = your_port_number </li></ul><ul><li>self.verificationErrors = [] </li></ul><ul><li>self.selenium = selenium.selenium(&quot;localhost&quot;, 4444, &quot;*chrome&quot;, &quot;%s://%s:%s&quot; % (protocol, host, port)) self.selenium.start() </li></ul><ul><li>;/jobmining/&quot;) </li></ul><ul><li>def test_doSearch(self): </li></ul><ul><li>sel = self.selenium </li></ul><ul><li>;/jobmining/&quot;) </li></ul><ul><li>sel.type(&quot;queryTitle&quot;, &quot;qa&quot;) </li></ul><ul><li>;ct_category&quot;, &quot;label=Banking&quot;) </li></ul><ul><li>;Submit01&quot;) </li></ul><ul><li>sel.wait_for_page_to_load(&quot;30000&quot;) </li></ul><ul><li>;link=sqa&quot;) </li></ul><ul><li>sel.wait_for_page_to_load(&quot;30000&quot;) </li></ul><ul><li>try: </li></ul><ul><li>self.failUnless(sel.is_text_present(&quot;Job Description dgds&quot;)) </li></ul><ul><li>except AssertionError, e: </li></ul><ul><li>self.verificationErrors.append(str(e)) </li></ul><ul><li>def tearDown(self): </li></ul><ul><li>self.selenium.stop() </li></ul><ul><li>if __name__ == &quot;__main__&quot;: </li></ul><ul><li>unittest.main() </li></ul>
  22. 22. Data Driven <ul><li>One key concept when doing automation is to recycle your scripts through data driving them </li></ul><ul><li>Use the underlying language you are using Selenium RC with to handle most of it for you </li></ul>
  23. 23. Same Origin <ul><li>Prevents a document or script loaded from one origin from getting or setting properties of a document from a different origin – Mozilla security documentation </li></ul><ul><li>In other words, cannot work across server boundries </li></ul>
  24. 24. Selenium Core <ul><li>Selenium Core is used by both Selenium IDE and RC </li></ul><ul><li>Runs test suites on the same server to avoid the Same Origin problem </li></ul><ul><li>Don’t have same flexibility as RC, but tests and code under test is in the same spot </li></ul>
  25. 25. Tips <ul><li>Start and stop your script from the same spot </li></ul><ul><li>Record your script in S-IDE, then use it as a base for a S-RC script </li></ul><ul><li>Use Firebug to give you the XPath </li></ul>
  26. 26. Designing for Selenium <ul><li>Proper use of tables and CSS div tags makes Selenium much easier </li></ul>
  27. 27. Support <ul><li>Because this is free, open source software there is no official support channel </li></ul><ul><li>Mailing lists </li></ul><ul><li>Wiki </li></ul><ul><li>Forums </li></ul><ul><li>Are your main sources of assistence. </li></ul><ul><li>But don’t forget your peers! </li></ul>