Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Automated Web Testing With Selenium

9,089 views

Published on

Automated Web Testing with Selenium. A presentation to Sydney Business Technology User Group (SBTUG) on 30 September 2009

Published in: Technology, Business
  • Be the first to comment

Automated Web Testing With Selenium

  1. 1. Automated Web Testing with Selenium<br />By Jodie Miners<br />Presented to SBTUG<br />30 September 2009 <br />
  2. 2. What is Selenium?<br />It’s Free and Open Source<br />It originally came from Thoughtworks<br />It comes in 3 flavours<br />IDE (Integrated Development Environment) – for recording test cases in Firefox<br />RC (Remote Control) – for running automated tests on any browser<br />Grid – for large scale test runs of multiple tests in parallel <br />You can get it here http://www.seleniumhq.org/<br />“Selenium tests run directly in a browser, just as real users do”<br />
  3. 3. Why use Selenium<br />You are always doing the same steps over and over again<br />You need to get to the last step in a wizard to test that step<br />You want to pre-fill some dummy data<br />Formal Functional and Regression Testing<br />Load Testing *<br />
  4. 4. Selenium IDE<br />A Firefox add-on that allows you to record tests for playing back in any browser.<br />Very simple to use<br />Allows non developers to get up and running with automated testing very quickly<br />Then they can pass on to developers for refinement or inclusion into a continuous build system<br />Can extend it easily with a little bit of HTML knowledge<br />
  5. 5. Recording and Playback<br />First Decide what you are testing and work out your test case(s)<br />IDE Demo<br />Record a test<br />Play back a test<br />Debug a test<br />Step through a test<br />Capture screen shot<br />Asserts<br />
  6. 6. Selenese<br />The language of selenium. It is quite easy to learn<br />3 parts to it<br />Command – eg Type<br />Locator – eg Input Box<br />Value – eg “ABC”<br />Can easily be written in HTML<br />Things to help build the IDE tests<br />Assert / Wait for Page to Load / Verify Text Present / Verify element present on each page<br />Slow things down with pauses and timeouts<br />Step through firs then run, add pauses and wait’s if it fails because it’s going too fast<br />Add think times<br />
  7. 7. Selenese Locators<br />Can Locate page elements by the following 4 methods<br />ID, DOM, Xpath, CSS<br />IDE recorderwill choose the best one to use, or you can choose which ever method if you are coding the tests. <br />Can also use Wildcards and Regular Expressions <br />See http://seleniumhq.org/docs/04_selenese_commands.html for more info - it’s very comprehensive<br />Install Firebug to help with working out the locators<br />
  8. 8. Selenium RC<br />Takes a little time and effort to get it up and running<br />Can then run your tests scripts from IDE in different browsers<br />With good results reporting<br />Or write the tests in code and automate the testing even further<br />Issues<br />Need to Install and use Java<br />Very command line / batch file based<br />Selenium RC Demo<br />
  9. 9. Demo<br />Run the test in Firefox<br />Run the test in IE<br />Run the test in Chrome<br />Note that they are all in sequence<br />
  10. 10. Coding your tests<br />Coding of Selenium testing can be done in<br />Java, Ruby, Groovy, C#, Perl, PHP, Python<br />Most examples are Java or Ruby, not that many people using C#<br />Add If statements<br />Eg if stock exists then add to cart (rather than having an error message)<br />Add looping statements<br />For each product found, add to cart<br />Easier to add parameterisation or data driven tests<br />eg have a list of products in a file or table – add each of the products to the cart<br />(you can do data driven tests in IDE – see here http://wiki.openqa.org/display/SEL/datadriven )<br />Multiple test runs<br />Run the test 4 times, each time logged in as a different user<br />Selenium Code Demo with NUnit<br />
  11. 11. Demo<br />Show the code<br />Paste the selenese in<br />Show NunitvsMSTest?<br />Run the Nunit test<br />Have one prepared ready to go<br />
  12. 12. Reporting<br />There is a great reporting framework if you code in Java or use TestNG<br />Logging Selenium http://loggingselenium.sourceforge.net/<br />For C# these are the options: <br />Just capture the Selenium output to a file<br />Code a reporting framework yourself<br />Use the Visual Studio Team System Test Edition framework<br />Use the NUnit reporting<br />I use a combination of VSTT reporting and some additional logging to a database that I created myself.<br />
  13. 13. Selenium Grid<br />Scale out the tests to run on multiple browsers at the same time<br />Saves time in doing the testing<br />But you need to rely on the reporting as you can’t watch 5+ browsers do the testing<br />Great tutorial and demo here http://selenium-grid.seleniumhq.org/<br />Requires Java SDK and Apache Ant to run<br />
  14. 14. My Grid Setup<br />
  15. 15. Taking the Grid Further<br />Scale out your grid to the Cloud using Amazon EC2 service<br />Or use a third party service<br />Sauce Labs http://www.saucelabs.com<br />In early beta<br />Uses your own code <br />So can set up the code to either run locally or via web <br />Current special US$100 for 5000 minutes<br />Lots of Browser / OS combinations<br />Test Environment Picture<br />BrowserMobhttp://www.browsermob.com<br />Time consuming to set up<br />Some limitations on which selenium commands can be used<br />Lots of options (eg can test with specific bandwidth limitations)<br />Can be used as for http requests only, as well as real browser tests<br />Around US$2.00 per browser per hour<br />
  16. 16. More Advanced Topics<br />UI Element mapping – How developers can make it easier for end users to build Selenium tests using element locator names that they can understand<br />http://ttwhy.org/home/blog/2007/05/12/selenium-ui-element-locator/<br />Using Xpath references with the Ext-JS javascript framework <br />http://www.xeolabs.com/portal/node/34<br />
  17. 17. Load Testing<br />Purists say Selenium is not for load testing<br />That is mainly because of the hardware required to run multiple browsers on the same machine.<br />I hit limits of 5-8 browsers on a standard desktop machine and 12-15 browsers on a server<br />Use Browser Mob or SauceLabs to overcome these issues.<br />Also as Selenium uses Real Browsers it requires real logins to simulate real loads – so you have to log in as real users on your system<br />It does not do virtual load and virtual users<br />
  18. 18. Recording in IE (just for @aussienick)<br />Watin for .net<br />http://watin.sourceforge.net/<br />Has a built in recorder for IE<br />There are also Watir (ruby), and Watij (java) variants <br />http://wtr.rubyforge.org/<br />Visual Studio Team System 2008 Test Edition (VSTT)<br />Visual Studio Team System 2010 Test Edition + Team Foundation Server<br />Looks Fantastic<br />Will also record and play back windows apps<br />Must use TFS<br />
  19. 19. References<br />Selenium Tutorial http://dynamitemap.com/selenium/including a good video<br />Full list of software testing tools http://www.softwareqatest.com/qatweb1.html<br />VSTT Quick Reference http://vstt2008qrg.codeplex.com/<br />
  20. 20. X-Path References<br />There is a great deal of help online for Xpath, here are some of the best sites I’ve found<br />Xpath reference http://www.w3schools.com/Xpath/default.asp<br />Some nice simple examples (on the Xpath tab) http://confluence.sakaiproject.org/display/QA/Selenium<br />Quick Reference Card http://confluence.sakaiproject.org/display/QA/Selenium<br />MSDN http://msdn.microsoft.com/en-us/library/ms256115.aspx<br />Great tutorial with lots of examples http://www.zvon.org/xxl/XPathTutorial/General/examples.html<br />Selenium Wiki Xpath reference http://wiki.openqa.org/display/SEL/Help+With+XPath<br />

×