Basic testing with selenium

6,911 views

Published on

Introduction to using Selenium IDE for development and test of web applications.

Published in: Technology
2 Comments
0 Likes
Statistics
Notes
  • Hi Michael,

    You need two things installed (aloing with any number of browsers):

    1) Java
    2) selenium-server-standalone jar - http://docs.seleniumhq.org/download/

    Then from a command prompt do the following:

    java -jar selenium-server-standalone-2.30.0.jar -htmlSuite '*firefox' http://mysite.com/ 'C:\Dev\htmlsuite.html' 'C:\Dev\results.html'
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi. I would like to run my Selenium IDE HTML tests from a command line. End goal is to automate them from a Jenkins server so they can be part of continuous integration. Can you guide me on how to accomplish this? Do I need to download selenium RC?

    I tried something like this but it didn't work:
    C:\Program Files (x86)\Mozilla Firefox\firefox.exe' -chrome 'chrome://selenium-ide/content/selenium/TestRunner.html?test=file:///C:/Dev/htmlsuite.html&auto=true&baseURL=http://mysite.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total views
6,911
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
43
Comments
2
Likes
0
Embeds 0
No embeds

No notes for slide

Basic testing with selenium

  1. 1. Cph.Pm Tech Talk 2012-02-28 <ul>Basic Testing with Selenium IDE Søren Lund (slu) [email_address] </ul>
  2. 2. Topics <ul><li>Web Technologies
  3. 3. Using Selenium IDE
  4. 4. Record and Play Test Cases
  5. 5. Modifiyng Test Cases </li></ul>
  6. 6. Web Technologies <ul><li>HTTP – H yper t ext T ransfer P rotocol
  7. 7. HTML – H yper t ext M arkup L anguage
  8. 8. DOM – D ocument O bject M odel
  9. 9. CSS – C ascading S tyle S heets
  10. 10. JavaScript </li></ul>
  11. 11. HTTP <ul><li>Client / Server - Request / Response
  12. 12. Request: </li><ul><li>GET /images/logo.png HTTP/1.1 Accept-Language: en, da
  13. 13. POST /login.jsp HTTP/1.1 user=slu&pass=secret </li></ul><li>Response: </li><ul><li>HTTP/1.1 200 OK Content-Type: text/html; charset=UTF-8 ... </li></ul></ul>
  14. 14. HTML and XHTML <ul><li>Parsed and Rendered by Browser
  15. 15. Hello World: </li><ul><li><!DOCTYPE html> <html> <head> <title>Hello HTML</title> </head> <body> <div id=&quot;main&quot;> <h1>Hello World!</h1> <p class=”intro”>This is HTML.</p> <p>Here's more</p> </div> </body> </html> </li></ul></ul>
  16. 16. DOM <ul><li>Link between HTML and JavaScript / CSS
  17. 17. Example (simplified): </li><ul><li>Document </li><ul><li>Element (html) </li><ul><li>Element (head) </li><ul><li>Element (title) </li><ul><li>text node </li></ul></ul><li>Element (body) </li><ul><li>Element (div) </li><ul><li>Element (h1) </li><ul><li>text node </li></ul><li>Element (p) </li><ul><li>text node </li></ul></ul></ul></ul></ul></ul></ul>
  18. 18. CSS <ul><li>Styling of HTML (colors, fonts, sizes, etc).
  19. 19. selector { property: value; property2: value; … }
  20. 20. h1 { color: blue; font-size: xx-large; }
  21. 21. .intro { text-align: center; }
  22. 22. #main { border: 1px solid red; } </li></ul>
  23. 23. Hello World
  24. 24. JavaScript <ul><li>Runs in the browser
  25. 25. Can modify the DOM after page load (i.e. post-response).
  26. 26. Makes it possible to do sub-requests after page load. (AJAX)
  27. 27. Selenium uses JavaScript to drive the browser </li></ul>
  28. 28. Using Selenium IDE <ul><li>(Front-end) Developer creates (and uses) initial test cases (normal flow).
  29. 29. Initial test cases are expanded and modified during development by testers/developers.
  30. 30. Additional test cases created when testing and reporting bugs.
  31. 31. Tests must be maintained alongside the code.
  32. 32. Selenium doesn't discover new bugs. </li></ul>
  33. 33. Limitations <ul><li>It's not possible to upload files
  34. 34. Java Applets and Flash (can be) near impossible to test
  35. 35. Very AJAX-heavy sites will be cumbersome to test (but possible)
  36. 36. No real way to do fixtures, but work-arounds can be used (i.e. a reset.cgi page available only during testing) </li></ul>
  37. 37. http://www.mozilla.org/
  38. 38. http://seleniumhq.org/download/
  39. 39. Starting Selenium IDE ...or press Ctrl+Alt+S
  40. 40. Starting Selenium IDE 2 Tab Alt-key to display menu
  41. 41. Starting Selenium IDE 3 In sidebar, nice if using only one monitor (e.g. laptop)
  42. 42. Selenium IDE Test Cases (current is bold ) Commands / Test Script Play Test Suite Play Current Test Case Play Test Suite Pause/Continue Running Test Case Record a Test Case Infomation Area Edit/Insert commands
  43. 43. Record and Play <ul><li>Demo </li></ul>
  44. 44. Test Cases and Suites <ul><li>Suggested layout and naming standard </li><ul><li>user/ UserNavigationTestCase.html UserLogInTestCase.html admin/ AdminNavigationTestCase.html AdminCreateUserTestCase.html AdminTestSuite.html CompleteTestSuite.html UserTestSuite.html </li></ul><li>CamelCase (ending with either TestCase or TestSuite ) and .html extension – no spaces. </li></ul>
  45. 45. Modify Recorded Test <ul><li>Demo </li></ul>
  46. 46. Checking Links Command Target Value assertElementPresent link=Kontakt Os assertText //a[@href='mailto:info@369.dk'] Kontakt Os assertAttribute css=#contactLink@href mailto:info@369.dk
  47. 47. Date Calculations Command Target Value storeEval var now = new Date(); y = now.getYear()+1900; m = '0' + (now.getMonth()+1); d = '0' + now.getDate(); y+'-'+m.substr(-2)+'-'+d.substr(-2) today storeEval var now = new Date(); 1900 + now.getYear() year storeEval storedVars['year'] + 1 nextYear type name=start_date 01-01-${year} type name=end_date ${today} click id=send assertTextPresent Intet fundet i perioden 01-01-${year} - ${today} Everything is on one line
  48. 48. Random Input (in lieu of fixtures) Command Target Value store javascript { 'user' + (new Date()).getTime() + '@domain.dom' } email type user.email javascript { storedVars['email'] } store javascript { vat_no=''; for(i=0; i<8; i++) { vat_no+=Math.ceil(Math.random()*9) } } vat_no type company.vat_no Javascript { storedVars['vat_no'] }
  49. 49. Selenium Standalone Server <ul><li>Can run the test suites created using Selenium IDE
  50. 50. Consists of a Java jar-file
  51. 51. Thus, requires Java to run
  52. 52. Can be used to run test in other browsers , i.e. Internet Explorer and Google Chrome </li></ul>
  53. 53. http://seleniumhq.org/download/
  54. 54. http://java.com/
  55. 55. Running Standalone Server <ul><li>Add ”-htmlSuite” to get (a little) help $ java -jar selenium-server-standalone-2.19.0.jar -htmlSuite 24-02-2012 19:19:59 org.openqa.grid.selenium.GridLauncher main INFO: Launching a standalone server Not enough command line arguments for -htmlSuite -htmlSuite requires you to specify: * browserString (e.g. &quot;*firefox&quot;) * startURL (e.g. &quot; http://www.google.com &quot;) * suiteFile (e.g. &quot;c:absolutepathtomyHTMLSuite.html&quot;) * resultFile (e.g. &quot;c:absolutepathtomyresults.html&quot;) </li></ul>
  56. 56. Running Standalone Server <ul><li>Real Example C:Usersname> java -jar selenium-server-standalone-2.19.0.jar -htmlSuite &quot;*iexplore&quot; http://localhost:8080/ c:UsersnameProjectsdemoseleniumClientTestSuite.html c:UsersnameProjectsdemoClientTestResult.html 28-02-2012 14:25:56 org.openqa.grid.selenium.GridLauncher main INFO: Launching a standalone server 14:25:56.091 INFO - Java: Sun Microsystems Inc. 20.4-b02 14:25:56.092 INFO - OS: Windows 7 6.1 x86 14:25:56.098 INFO - v2.19.0, with Core v2.19.0. Built from revision 15849 14:25:56.216 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub 14:25:56.218 INFO - Version Jetty/5.1.x ... 14:25:56.257 INFO - Started [email_address] 14:25:56.929 INFO - Launching Embedded Internet Explorer... 14:25:57.433 INFO - Launching Internet Explorer HTA... 14:26:01.637 INFO - Checking Resource aliases </li></ul>
  57. 57. Standalone Server Window Simplified version of the IDE (running in the target browser) Plus a seperate (browser) window where the tests are performed...
  58. 58. Playing with Selenium <ul><li>Try it on your own web applications
  59. 59. … or your favorite web site
  60. 60. … or download QEDServer and play with that </li></ul>
  61. 61. http://qedserver.napcs.com/
  62. 62. Running QEDServer <ul><li>(Start by unzipping download archive)
  63. 63. Open a Command Prompt/Terminal
  64. 64. Run the server script (server.bat, server.sh)
  65. 65. Goto http://localhost:8080/ and play
  66. 66. Quit with Ctrl-C
  67. 67. Use fresh_server script to start over </li></ul>
  68. 68. Resources <ul><li>Firefox download: https://www.mozilla.org/
  69. 69. Selenium download: http://seleniumhq.org/download/
  70. 70. QEDServer download: http://qedserver.napcs.com/
  71. 71. Public Domain Clip Art: http://www.pdclipart.org/ </li></ul>
  72. 72. The End <ul><li>Slides available at slideshare http://www.slideshare.net/slu </li></ul>

×