Your SlideShare is downloading. ×
0
Acceptance Testing with Selenium
Topics <ul><li>Why test? </li></ul><ul><li>Types of testing </li></ul><ul><ul><li>Unit </li></ul></ul><ul><ul><li>Acceptan...
Why test? <ul><li>Find bugs </li></ul>
Why test? <ul><li>Find bugs </li></ul><ul><li>Other </li></ul><ul><ul><li>Performance </li></ul></ul><ul><ul><li>Usability...
Why test? <ul><li>Find bugs </li></ul><ul><li>Prove correctness </li></ul><ul><li>Other </li></ul><ul><ul><li>Performance ...
Software Development <ul><li>Requirements </li></ul><ul><ul><li>What do we want it to do? </li></ul></ul><ul><li>Developme...
Testing - Traditional <ul><li>Requirements </li></ul><ul><li>Design / Specification </li></ul><ul><li>Coding </li></ul><ul...
Testing - Agile <ul><li>Requirements </li></ul><ul><li>Write (failing) test </li></ul><ul><li>Write code </li></ul><ul><li...
Testing - Agile <ul><li>Requirements  in the form of a test </li></ul><ul><li>Run test </li></ul><ul><li>Code </li></ul><u...
Unit Test – Simple Example <ul><li>Calculator </li></ul><ul><li>Add </li></ul><ul><li>Subtract </li></ul><ul><li>Multiply ...
Unit Test – Simple Example <ul><li># Calculator.add() – implementation </li></ul><ul><li>function add(first, second) </li>...
Unit Test – Simple Example <ul><li># Calculator.add() – test </li></ul><ul><li># 1 + 1 = 2 </li></ul><ul><li>assert_equal(...
Unit Test – Simple Example <ul><li># Calculator.add() - test </li></ul><ul><li>assert_equal(2, Calculator.add(1, 1)) </li>...
Unit Test – Simple Example <ul><li># Calculator.divide() - implementation </li></ul><ul><li>function divide(first, second)...
Unit Test – Simple Example <ul><li># Calculator.divide() – test </li></ul><ul><li># 12 / 3 = 4 </li></ul><ul><li>assert_eq...
Unit Test – Simple Example <ul><li>5 / 2 = ? </li></ul>
Unit Test – Simple Example <ul><li># Calculator.divide() - test </li></ul><ul><li>assert_equal(2, Calculator.divide(5, 2))...
Unit Test – Simple Example <ul><li># Calculator.divide() – implementation </li></ul><ul><li>function divide(first, second)...
Unit Test – Simple Example <ul><li>1 / 0 = ? </li></ul>
Unit Test – Simple Example <ul><li># Calculator.divide() - test </li></ul><ul><li>assert_equal(0, Calculator.divide(1, 0))...
Unit Test – Simple Example <ul><li># Calculator.divide() – implementation </li></ul><ul><li>function divide(first, second)...
Unit Test – Simple Example <ul><li>It works – the tests pass … </li></ul><ul><li>…  but the code is a little verbose … </l...
Unit Test – Simple Example <ul><li># Calculator.divide() – refactored </li></ul><ul><li># (boolean expr) ? true-result : f...
Unit Test – Simple Example <ul><li>The tests run successfully </li></ul><ul><li>Working calculator </li></ul><ul><li>Nicel...
Calculator.divide() Requirements 0 0 1 2 2 5 4 3 12 Expected Second First
Calculator.divide() Tests assert_equal(Calculator.add(1, 0), 0) assert_equal(Calculator.add(5, 2), 2) assert_equal(Calcula...
RSpec <ul><li>describe “Calculator” do </li></ul><ul><li>it “should divide 12 by 4 and return 3” do </li></ul><ul><li>Calc...
RSpec - Results <ul><li>Calculator </li></ul><ul><li>- should divide 12 by 4 and return 3 </li></ul><ul><li>- should divid...
Design for Testing <ul><li>function calculate(first, operator, second) </li></ul><ul><li>if (operator == “add”) then </li>...
Design for Testing <ul><li>function calculate(first, operator, second) </li></ul><ul><li>if (operator == “add”) then </li>...
<ul><li>Questions on unit testing? </li></ul>
Acceptance Testing <ul><li>Functional  tests are written from a user's perspective. These tests confirm that the system do...
Customer Test-Driven Development (CTDD) <ul><li>Tests </li></ul><ul><ul><li>Customer (browser) perspective </li></ul></ul>...
Acceptance Testing <ul><li>Finds bugs </li></ul><ul><li>Finds usability issues </li></ul><ul><li>Produces new/changed requ...
Acceptance Testing <ul><li>Comes near the end of the project (late) </li></ul><ul><li>Changes are most expensive </li></ul...
Acceptance Testing - CTDD <ul><li>Requirements in the form of a test </li></ul><ul><li>Meeting requirements is an objectiv...
Testing Types <ul><li>Happy Path – verifies expected behavior with correct input </li></ul><ul><li>Validity – verifies inc...
Example Requirement <ul><li>Add comments field </li></ul><ul><li>Make it required </li></ul>
 
Requirement <ul><li>Add comments field as an HTML text area, 3 rows x 30 columns. </li></ul><ul><li>Put label “Additional ...
 
Requirements as Test Record saved verify text present save click  “ My comment” comments type Additional Comments is a req...
More Requirements <ul><li>Comments can be blank for existing data </li></ul><ul><li>Don’t display comments on “Delete Veri...
Comments can be blank for existing data Record saved verify text present save click “” comment verify text /record/edit?id...
Don’t display comments on  Delete - Verify page “ comment #9” verify text not present delete click “ comment #9” comment v...
Comments should be 20-80 characters Comments s/b 20-80 chars verify text not present save click (> 19 chars) comment type ...
Requirements as Runnable Test <ul><li>It’s real </li></ul><ul><li>Selenium </li></ul><ul><ul><li>Selenium Core </li></ul><...
Selenium Core <ul><li>Installs in public/html (e.g.) </li></ul><ul><li>Test runner is all Javascript </li></ul><ul><li>Wri...
Selenium IDE <ul><li>Firefox plugin </li></ul><ul><li>Record, playback, save, edit scripts </li></ul><ul><li>Works on any ...
Selenium IDE Demo
Selenium Element Selectors <ul><li>id=some_id or name=some_name </li></ul><ul><li>dom=document.forms[1].myDropdown </li></...
Selenium Element Selectors <ul><li>What are you testing? </li></ul><ul><li><a href=“…”, id=“new_link”>Add New</a> </li></u...
HTML Recommendations <ul><li>Id attributes on all important elements </li></ul><ul><li>Class attributes a close second </l...
Selenium Remote Control <ul><li>…  write automated web application UI tests in any programming language against any HTTP w...
 
C# (NUnit) Example <ul><li>using Selenium; </li></ul><ul><li>using NUnit.Framework; </li></ul><ul><li>namespace MyTests { ...
C# (NUnit) Example <ul><li>[Test] </li></ul><ul><li>public void testGoogle() { </li></ul><ul><li>sel.Open(&quot;http://www...
Selenium on Rails <ul><li>Ruby on Rails plugin </li></ul><ul><li>Runs within Rails test framework </li></ul><ul><li>Write ...
Selenium on Rails Demo <ul><li>Data Model </li></ul>roles user_roles users
Selenium on Rails Demo
Upcoming SlideShare
Loading in...5
×

Acceptance Testing With Selenium

3,952

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,952
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
150
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Acceptance Testing With Selenium"

  1. 1. Acceptance Testing with Selenium
  2. 2. Topics <ul><li>Why test? </li></ul><ul><li>Types of testing </li></ul><ul><ul><li>Unit </li></ul></ul><ul><ul><li>Acceptance </li></ul></ul><ul><li>Acceptance testing with Selenium </li></ul>
  3. 3. Why test? <ul><li>Find bugs </li></ul>
  4. 4. Why test? <ul><li>Find bugs </li></ul><ul><li>Other </li></ul><ul><ul><li>Performance </li></ul></ul><ul><ul><li>Usability </li></ul></ul><ul><ul><li>Etc. </li></ul></ul>
  5. 5. Why test? <ul><li>Find bugs </li></ul><ul><li>Prove correctness </li></ul><ul><li>Other </li></ul><ul><ul><li>Performance </li></ul></ul><ul><ul><li>Usability </li></ul></ul><ul><ul><li>Etc. </li></ul></ul>
  6. 6. Software Development <ul><li>Requirements </li></ul><ul><ul><li>What do we want it to do? </li></ul></ul><ul><li>Development </li></ul><ul><ul><li>Write code that meets requirements. </li></ul></ul><ul><li>Testing </li></ul><ul><ul><li>Does the code meet the requirements? </li></ul></ul>
  7. 7. Testing - Traditional <ul><li>Requirements </li></ul><ul><li>Design / Specification </li></ul><ul><li>Coding </li></ul><ul><li>Testing </li></ul>
  8. 8. Testing - Agile <ul><li>Requirements </li></ul><ul><li>Write (failing) test </li></ul><ul><li>Write code </li></ul><ul><li>Run test (successfully) </li></ul>
  9. 9. Testing - Agile <ul><li>Requirements in the form of a test </li></ul><ul><li>Run test </li></ul><ul><li>Code </li></ul><ul><li>When test passes, you’re done. </li></ul>
  10. 10. Unit Test – Simple Example <ul><li>Calculator </li></ul><ul><li>Add </li></ul><ul><li>Subtract </li></ul><ul><li>Multiply </li></ul><ul><li>Divide </li></ul>
  11. 11. Unit Test – Simple Example <ul><li># Calculator.add() – implementation </li></ul><ul><li>function add(first, second) </li></ul><ul><li>return first + second </li></ul><ul><li>end </li></ul>
  12. 12. Unit Test – Simple Example <ul><li># Calculator.add() – test </li></ul><ul><li># 1 + 1 = 2 </li></ul><ul><li>assert_equal(2, Calculator.add(1, 1)) </li></ul>
  13. 13. Unit Test – Simple Example <ul><li># Calculator.add() - test </li></ul><ul><li>assert_equal(2, Calculator.add(1, 1)) </li></ul><ul><li>assert_equal(-2, Calculator.add(-1, -1)) </li></ul><ul><li>assert_equal(42, Calculator.add(0, 42)) </li></ul><ul><li>assert_equal(1001, Calculator.add(1000, 1)) </li></ul>
  14. 14. Unit Test – Simple Example <ul><li># Calculator.divide() - implementation </li></ul><ul><li>function divide(first, second) </li></ul><ul><li>return first / second </li></ul><ul><li>end </li></ul>
  15. 15. Unit Test – Simple Example <ul><li># Calculator.divide() – test </li></ul><ul><li># 12 / 3 = 4 </li></ul><ul><li>assert_equal(4, Calculator.divide(12, 3)) </li></ul>
  16. 16. Unit Test – Simple Example <ul><li>5 / 2 = ? </li></ul>
  17. 17. Unit Test – Simple Example <ul><li># Calculator.divide() - test </li></ul><ul><li>assert_equal(2, Calculator.divide(5, 2)) </li></ul>
  18. 18. Unit Test – Simple Example <ul><li># Calculator.divide() – implementation </li></ul><ul><li>function divide(first, second) </li></ul><ul><li>return round( first / second ) </li></ul><ul><li>end </li></ul>
  19. 19. Unit Test – Simple Example <ul><li>1 / 0 = ? </li></ul>
  20. 20. Unit Test – Simple Example <ul><li># Calculator.divide() - test </li></ul><ul><li>assert_equal(0, Calculator.divide(1, 0)) </li></ul>
  21. 21. Unit Test – Simple Example <ul><li># Calculator.divide() – implementation </li></ul><ul><li>function divide(first, second) </li></ul><ul><li>if (second == 0) then </li></ul><ul><li>return 0 </li></ul><ul><li>else </li></ul><ul><li>return round(first + second) </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  22. 22. Unit Test – Simple Example <ul><li>It works – the tests pass … </li></ul><ul><li>… but the code is a little verbose … </li></ul><ul><li>… so let’s refactor. </li></ul>
  23. 23. Unit Test – Simple Example <ul><li># Calculator.divide() – refactored </li></ul><ul><li># (boolean expr) ? true-result : false-result </li></ul><ul><li>function divide(first, second) </li></ul><ul><li>return (second == 0) ? 0 : round(first/second) </li></ul><ul><li>end </li></ul>
  24. 24. Unit Test – Simple Example <ul><li>The tests run successfully </li></ul><ul><li>Working calculator </li></ul><ul><li>Nicely refactored code </li></ul><ul><li>All functionality covered by tests </li></ul>
  25. 25. Calculator.divide() Requirements 0 0 1 2 2 5 4 3 12 Expected Second First
  26. 26. Calculator.divide() Tests assert_equal(Calculator.add(1, 0), 0) assert_equal(Calculator.add(5, 2), 2) assert_equal(Calculator.add(12, 4), 3)
  27. 27. RSpec <ul><li>describe “Calculator” do </li></ul><ul><li>it “should divide 12 by 4 and return 3” do </li></ul><ul><li>Calculator.divide(12, 4).should == 3 </li></ul><ul><li>end </li></ul><ul><li># rest of Calculator assertions </li></ul><ul><li>end </li></ul>
  28. 28. RSpec - Results <ul><li>Calculator </li></ul><ul><li>- should divide 12 by 4 and return 3 </li></ul><ul><li>- should divide 5 by 2 and return 2 </li></ul><ul><li>- should divide 1 by 0 and return 0 </li></ul><ul><li>Finished in 0.014 seconds </li></ul><ul><li>3 examples, 0 failures </li></ul>
  29. 29. Design for Testing <ul><li>function calculate(first, operator, second) </li></ul><ul><li>if (operator == “add”) then </li></ul><ul><li>return first + second </li></ul><ul><li>else if (operator == “subtract”) then </li></ul><ul><li>return first – second </li></ul><ul><li>else < etc. > </li></ul><ul><li>end </li></ul>
  30. 30. Design for Testing <ul><li>function calculate(first, operator, second) </li></ul><ul><li>if (operator == “add”) then </li></ul><ul><li>return add(first, second) </li></ul><ul><li>else if (operator == “subtract”) then </li></ul><ul><li>return subtract(first, second) </li></ul><ul><li>else < etc. > </li></ul><ul><li>end </li></ul>
  31. 31. <ul><li>Questions on unit testing? </li></ul>
  32. 32. Acceptance Testing <ul><li>Functional tests are written from a user's perspective. These tests confirm that the system does what users are expecting it to. (IBM) </li></ul><ul><li>… acceptance testing is performed by the customer on a system prior to the customer accepting delivery … (Wikipedia) </li></ul>
  33. 33. Customer Test-Driven Development (CTDD) <ul><li>Tests </li></ul><ul><ul><li>Customer (browser) perspective </li></ul></ul><ul><ul><li>Validate correctness of application </li></ul></ul><ul><ul><li>Successful test constitutes acceptance </li></ul></ul><ul><li>Tests created, run, re-run throughout project life </li></ul>
  34. 34. Acceptance Testing <ul><li>Finds bugs </li></ul><ul><li>Finds usability issues </li></ul><ul><li>Produces new/changed requirements </li></ul>
  35. 35. Acceptance Testing <ul><li>Comes near the end of the project (late) </li></ul><ul><li>Changes are most expensive </li></ul><ul><li>How often is software not “accepted”? </li></ul>
  36. 36. Acceptance Testing - CTDD <ul><li>Requirements in the form of a test </li></ul><ul><li>Meeting requirements is an objective, unambiguous activity. </li></ul><ul><li>Consideration given to exceptions and edge cases, not just “happy path”. </li></ul>
  37. 37. Testing Types <ul><li>Happy Path – verifies expected behavior with correct input </li></ul><ul><li>Validity – verifies incorrect input results in expected errors </li></ul><ul><li>Edge case – checks boundaries between Happy Path and invalid data </li></ul>
  38. 38. Example Requirement <ul><li>Add comments field </li></ul><ul><li>Make it required </li></ul>
  39. 40. Requirement <ul><li>Add comments field as an HTML text area, 3 rows x 30 columns. </li></ul><ul><li>Put label “Additional Comments” on top of text area </li></ul><ul><li>Make it required. If empty, error message should be “Additional Comments is a required field.” </li></ul>
  40. 42. Requirements as Test Record saved verify text present save click “ My comment” comments type Additional Comments is a required field verify text present save click /record/new open
  41. 43. More Requirements <ul><li>Comments can be blank for existing data </li></ul><ul><li>Don’t display comments on “Delete Verify” page. </li></ul><ul><li>Comments should be 20 – 80 characters. </li></ul>
  42. 44. Comments can be blank for existing data Record saved verify text present save click “” comment verify text /record/edit?id=42 open
  43. 45. Don’t display comments on Delete - Verify page “ comment #9” verify text not present delete click “ comment #9” comment verify text /record/edit?id=9 open
  44. 46. Comments should be 20-80 characters Comments s/b 20-80 chars verify text not present save click (> 19 chars) comment type Comments s/b 20-80 chars verify text present save click “ cmmt” comment type /record/edit?id=9 open
  45. 47. Requirements as Runnable Test <ul><li>It’s real </li></ul><ul><li>Selenium </li></ul><ul><ul><li>Selenium Core </li></ul></ul><ul><ul><li>Selenium IDE </li></ul></ul><ul><ul><li>Selenium Remote Control </li></ul></ul><ul><ul><li>Selenium on Rails </li></ul></ul>
  46. 48. Selenium Core <ul><li>Installs in public/html (e.g.) </li></ul><ul><li>Test runner is all Javascript </li></ul><ul><li>Write test cases in Selenese (HTML) </li></ul><ul><li>Point browser to your_app/selenium </li></ul>
  47. 49. Selenium IDE <ul><li>Firefox plugin </li></ul><ul><li>Record, playback, save, edit scripts </li></ul><ul><li>Works on any (combination of) web sites </li></ul>
  48. 50. Selenium IDE Demo
  49. 51. Selenium Element Selectors <ul><li>id=some_id or name=some_name </li></ul><ul><li>dom=document.forms[1].myDropdown </li></ul><ul><li>xpath=//img[@alt=‘Some alt text’] </li></ul><ul><li>link=some link text </li></ul><ul><li>css=cssSelectorSyntax </li></ul>
  50. 52. Selenium Element Selectors <ul><li>What are you testing? </li></ul><ul><li><a href=“…”, id=“new_link”>Add New</a> </li></ul><ul><li>click id=new_link </li></ul><ul><li>or </li></ul><ul><li>click link=Add New </li></ul>
  51. 53. HTML Recommendations <ul><li>Id attributes on all important elements </li></ul><ul><li>Class attributes a close second </li></ul><ul><li>Valid mark-up reduces dom and xpath errors </li></ul>
  52. 54. Selenium Remote Control <ul><li>… write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser. </li></ul><ul><li>Java, .Net, Perl, PHP, Python, Ruby </li></ul>
  53. 56. C# (NUnit) Example <ul><li>using Selenium; </li></ul><ul><li>using NUnit.Framework; </li></ul><ul><li>namespace MyTests { </li></ul><ul><li>[TestFixture] </li></ul><ul><li>public class GoogleTest { </li></ul><ul><li>private ISelenium sel; </li></ul><ul><li>[SetUp] </li></ul><ul><li>public void SetUp() { </li></ul><ul><li>sel = new DefaultSelenium(&quot;localhost&quot;, </li></ul><ul><li>4444, &quot;*firefox&quot;, &quot;http://www.google.com&quot;); </li></ul><ul><li>sel.Start(); </li></ul><ul><li>} </li></ul><ul><li>[Test] </li></ul><ul><li>public void testGoogle() { </li></ul><ul><li>sel.Open(&quot;http://www.google.com/webhp&quot;); </li></ul><ul><li>sel.Type(&quot;q&quot;, &quot;hello world&quot;); </li></ul><ul><li>sel.Click(&quot;btnG&quot;); </li></ul><ul><li>sel.WaitForPageToLoad(&quot;5000&quot;); </li></ul><ul><li>Assert.AreEqual(&quot;hello world - Google Search&quot;, sel.GetTitle()); </li></ul><ul><li>} </li></ul><ul><li>[TearDown] </li></ul><ul><li>public void TearDown() { </li></ul><ul><li>sel.Stop(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  54. 57. C# (NUnit) Example <ul><li>[Test] </li></ul><ul><li>public void testGoogle() { </li></ul><ul><li>sel.Open(&quot;http://www.google.com/webhp&quot;); </li></ul><ul><li>sel.Type(&quot;q&quot;, &quot;hello world&quot;); </li></ul><ul><li>sel.Click(&quot;btnG&quot;); </li></ul><ul><li>sel.WaitForPageToLoad(&quot;5000&quot;); </li></ul><ul><li>Assert.AreEqual(&quot;hello world - Google Search&quot;, sel.GetTitle()); </li></ul><ul><li>} </li></ul>
  55. 58. Selenium on Rails <ul><li>Ruby on Rails plugin </li></ul><ul><li>Runs within Rails test framework </li></ul><ul><li>Write tests in Ruby or Selenese </li></ul><ul><ul><li>database access </li></ul></ul><ul><ul><li>can abstract tests into reusable functions </li></ul></ul><ul><ul><li>and much more </li></ul></ul>
  56. 59. Selenium on Rails Demo <ul><li>Data Model </li></ul>roles user_roles users
  57. 60. Selenium on Rails Demo
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×