Completing the circle      Automated web tests as a team communication toolJohn Ferguson Smart
So who is this guy, anyway?               Consulta                       nt               Trainer              Mentor     ...
ATDDor Specification by example      The story of your app
User storiesAs a job seekerI want to find jobs in relevant categoriesSo that I can find a suitable job                      ...
User storiesAs a job seekerI want to find jobs in relevant categoriesSo that I can find a suitable job                      ...
User stories    As a job seeker    I want to find jobs in relevant categories    So that I can find a suitable job          ...
scenario "A job seeker can see the available job categories on the home page", { 	   when "the job seeker is looking for a...
Not All Web Tests are Acceptance Tests  Technical tests are for   Acceptance tests are      the dev team            for ev...
Not All Web Tests are Acceptance Tests  Technical tests talk to   Acceptance tests talk      the dev team            to ev...
The art of sustainable web tests          or how not to have web tests like this
So what are our goals?
Good web tests should         speak everybody’s language
Good web tests should           hide unnecessary details
Good web tests should           use reusable components
Good web tests should              be low maintenance
The Three Ways of Automated Web Testing        Record/Replay      ScriptingPage Objects
Record-replay automated tests      Promise           Reality
Record-replay automated tests
Script-based automated testsSelenium RC      HTMLUnit              JWebUnit                     Canoe Webtest             ...
Script-based automated testsSelenium RC      HTMLUnit              JWebUnit                     Canoe Webtest             ...
How about Page Objects?Reusable Low maintenance  Hide unnecessary detail                            2
A sample Page Object                       A web page
A sample Page Object                                                 A Page Object                        FindAJobPage    ...
A sample Page Object  public class FindAJobPage extends PageObject {                                                      ...
A sample Page Object  public class WhenSearchingForAJob {      @Test      public void searching_for_a_job_should_display_m...
Sustainable web tests                        Are we there yet?
Acceptance TestsThe high-level view  So	  where	  are	          we	  at?
Page Objects           Page	  Objects	                rock!           Implementation focus
How do we bridge the gap?
How do we bridge the gap?                 Test steps
scenario "A job seeker can see the available job categories on the home page",    {    	   when "the job seeker is looking...
scenario "The user can see the available job categories on the home page",{	   when "the job seeker is looking for a job",...
Test steps        help organize your tests
Test stepsare a communication tool
Test steps     are reusable building blocks
Test stepshelp estimate progress
And so we built a tool...
Webdriver/Selenium 2 extensionOrganize tests, stories and features                               Record/report test execut...
Thucydides in action   A simple demo app
Defining your acceptance tests  scenario "A              job seeker  {                       can see the                   ...
Organizing your requirements Features   public class Application {                @Feature                public class Man...
Implementing your acceptance testsusing "thucydides"                                   We are testing this storythucydides...
Some folks prefer JUnit...@RunWith(ThucydidesRunner.class)@Story(AddNewCategory.class)                      Thucydides han...
Defining your test stepspublic class AdministratorSteps extends ScenarioSteps {                  A step library    @Step   ...
Defining your page objectspublic class EditCategoryPage extends PageObject {    @FindBy(id="object_label")    WebElement la...
Data-driven testing                                                Test data             categories.csvpublic class DataDr...
Data-driven testing                                                Test data             categories.csvpublic class DataDr...
Now run your tests
Displaying the results in easyb
Displaying the results in easyb
Thucydides reports               Browse the features
Browse the stories            Browse the stories
Browse the stories               Browse the test scenarios
Illustrating the test paths                                    A test                                   scenario          ...
Illustrating the test paths                                           Test                                         scenari...
Functional coverage                      Features
Functional coverage                       User                      stories
Functional coverage                      Passing tests                            Pending tests
Progress
Functional coverage                        Test                      scenarios
Functional coverage
References           easyb.org    github.com/thucydides-webtests                 wakaleo.com/thucydides
The Circle is Complete Automated web tests as a team communication tool                                        John	  Ferg...
Completing the circle - Automated web tests as a team communication tool
Upcoming SlideShare
Loading in...5
×

Completing the circle - Automated web tests as a team communication tool

19,597

Published on

Acceptance Test Driven Development, or ATDD, is a very effective technique for driving and guiding development, that helps enhancing communication between developers and other project stakeholders, document your product, and report on project progress.

Learn how to use automated web tests as a communication, reporting and product documentation tool. Automated web tests can be used to generate living, illustrated documentation about how the system is used. Organize your automated web tests more effectively, so that they can be used to report on test coverage in terms the business can understand. And discover a new open source library designed to helps developers and testers write better automated acceptance tests for web applications using WebDriver/Selenium 2.

Published in: Technology, Business
4 Comments
25 Likes
Statistics
Notes
No Downloads
Views
Total Views
19,597
On Slideshare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
237
Comments
4
Likes
25
Embeds 0
No embeds

No notes for slide

Transcript of "Completing the circle - Automated web tests as a team communication tool "

  1. 1. Completing the circle Automated web tests as a team communication toolJohn Ferguson Smart
  2. 2. So who is this guy, anyway? Consulta nt Trainer Mentor Author Speaker Coder John Fer guson S mar t
  3. 3. ATDDor Specification by example The story of your app
  4. 4. User storiesAs a job seekerI want to find jobs in relevant categoriesSo that I can find a suitable job Features/Epics
  5. 5. User storiesAs a job seekerI want to find jobs in relevant categoriesSo that I can find a suitable job Acceptance criteria ☑  The  job  seeker  can  see  available  categories  on  the  home  page ☑  The  job  seeker  can  look  for  jobs  in  a  given  category ☑  The  job  seeker  can  see  what  category  a  job  belongs  to
  6. 6. User stories As a job seeker I want to find jobs in relevant categories So that I can find a suitable job Acceptance criteria ☑  The  job  seeker  can  see  available  categories  on  the  home  page ☑  The  job  seeker  can  look  for  jobs  in  a  given  category ☑  The  job  seeker  can  see  what  category  a  job  belongs  toscenario "A job seeker can see the available job categories on the home page",{ when "the job seeker is looking for a job", then "the job seeker can see all the available job categories"} Automated acceptance test
  7. 7. scenario "A job seeker can see the available job categories on the home page", { when "the job seeker is looking for a job", then "the job seeker can see all the available job categories" } Automated acceptance testImplemented development tests Implemented acceptance tests
  8. 8. Not All Web Tests are Acceptance Tests Technical tests are for Acceptance tests are the dev team for everyone else
  9. 9. Not All Web Tests are Acceptance Tests Technical tests talk to Acceptance tests talk the dev team to everyone else
  10. 10. The art of sustainable web tests or how not to have web tests like this
  11. 11. So what are our goals?
  12. 12. Good web tests should speak everybody’s language
  13. 13. Good web tests should hide unnecessary details
  14. 14. Good web tests should use reusable components
  15. 15. Good web tests should be low maintenance
  16. 16. The Three Ways of Automated Web Testing Record/Replay ScriptingPage Objects
  17. 17. Record-replay automated tests Promise Reality
  18. 18. Record-replay automated tests
  19. 19. Script-based automated testsSelenium RC HTMLUnit JWebUnit Canoe Webtest Watir
  20. 20. Script-based automated testsSelenium RC HTMLUnit JWebUnit Canoe Webtest Watir
  21. 21. How about Page Objects?Reusable Low maintenance Hide unnecessary detail 2
  22. 22. A sample Page Object A web page
  23. 23. A sample Page Object A Page Object FindAJobPage lookForJobsWithKeywords(values : String) getJobTitles() : List<String>
  24. 24. A sample Page Object public class FindAJobPage extends PageObject { An implemented WebElement keywords; WebElement searchButton; Page Object public FindAJobPage(WebDriver driver) { super(driver); } public void lookForJobsWithKeywords(String values) { typeInto(keywords, values); searchButton.click(); } public List<String> getJobTitles() { List<WebElement> tabs = getDriver() .findElements(By.xpath("//div[@id=jobs]//a")); return extract(tabs, on(WebElement.class).getText()); } }
  25. 25. A sample Page Object public class WhenSearchingForAJob { @Test public void searching_for_a_job_should_display_matching_jobs() { FindAJobPage page = new FindAJobPage(); page.open("http://localhost:9000"); page.lookForJobsWithKeywords("Java"); assertThat(page.getJobTitles(), hasItem("Java Developer")); } } A test using this Page Object
  26. 26. Sustainable web tests Are we there yet?
  27. 27. Acceptance TestsThe high-level view So  where  are   we  at?
  28. 28. Page Objects Page  Objects   rock! Implementation focus
  29. 29. How do we bridge the gap?
  30. 30. How do we bridge the gap? Test steps
  31. 31. scenario "A job seeker can see the available job categories on the home page", { when "the job seeker is looking for a job", then "the job seeker can see all the available job categories" } Automatedscenario "The user can see the available job categories on the home page",{ when "the job seeker is looking for a job", { job_seeker.open_jobs_page() } then "the job seeker can see all the available job categories", { job_seeker.should_see_job_categories "Java Developers", "Groovy Developers" }} Implemented JobSeekerSteps JobSeekerSteps JobSeekerSteps open_jobs_page() open_jobs_page() open_jobs_page() should_see_job_categories(String...  categories) should_see_job_categories(String...  categories) ... should_see_job_categories(String...  categories) ... ... Step libraries
  32. 32. scenario "The user can see the available job categories on the home page",{ when "the job seeker is looking for a job", { job_seeker.open_jobs_page() } then "the job seeker can see all the available job categories", { job_seeker.should_see_job_categories "Java Developers", "Groovy Developers" }} Implemented Tests JobSeekerSteps JobSeekerSteps JobSeekerSteps open_jobs_page() open_jobs_page() open_jobs_page() should_see_job_categories(String...  categories) should_see_job_categories(String...  categories) ... should_see_job_categories(String...  categories) ... ... Step libraries Page Objects
  33. 33. Test steps help organize your tests
  34. 34. Test stepsare a communication tool
  35. 35. Test steps are reusable building blocks
  36. 36. Test stepshelp estimate progress
  37. 37. And so we built a tool...
  38. 38. Webdriver/Selenium 2 extensionOrganize tests, stories and features Record/report test execution Measure functional coverage
  39. 39. Thucydides in action A simple demo app
  40. 40. Defining your acceptance tests scenario "A job seeker { can see the available j ob categori when "the j es on the h ob seeker i ome page", then "the j s looking f ob seeker c o r a j o b ", } an see all the availab le job cate gories" High level requ irements... scenario "The administrator adds a new category to the system", { given "a new category needs to be added to the system", when "the administrator adds a new category", then "the system should confirm that the category has been created", and "the new category should be visible to job seekers", } { scenario "The admini strator deletes a ca tegory from the syst em", ...defined in business terms given "a category ne eds to be deleted", when "the administra tor deletes a catego then "the system will ry", confirm that the cate and "the deleted cate gory has been delete gory should no longer d", } be visible to job se eker s", focus on business value
  41. 41. Organizing your requirements Features public class Application { @Feature public class ManageCompanies { public class AddNewCompany {} public class DeleteCompany {} public class ListCompanies {} } @Feature public class ManageCategories { public class AddNewCategory {} public class ListCategories {} public class DeleteCategory {} } @Feature Stories public class BrowseJobs { public class UserLookForJobs {} public class UserBrowsesJobTabs {} } }
  42. 42. Implementing your acceptance testsusing "thucydides" We are testing this storythucydides.uses_steps_from AdministratorStepsthucydides.uses_steps_from JobSeekerStepsthucydides.tests_story AddNewCategory An acceptance criteriascenario "The administrator adds a new category to the system",{ given "a new category needs to be added to the system", { Narrative style administrator.logs_in_to_admin_page_if_first_time() administrator.opens_categories_list() } Step through an when "the administrator adds a new category", example { administrator.selects_add_category() administrator.adds_new_category("Scala Developers","SCALA") } then "the system should confirm that the category has been created", { administrator.should_see_confirmation_message "The Category has been created" } and "the new category should be visible to job seekers", { Still high-level job_seeker.opens_jobs_page() job_seeker.should_see_job_category "Scala Developers" }}
  43. 43. Some folks prefer JUnit...@RunWith(ThucydidesRunner.class)@Story(AddNewCategory.class) Thucydides handles thepublic class AddCategoryStory { web driver instances @Managed public WebDriver webdriver; @ManagedPages(defaultUrl = "http://localhost:9000") public Pages pages; @Steps public AdministratorSteps administrator; @Steps Using the same steps public JobSeekerSteps job_seeker; @Test public void administrator_adds_a_new_category_to_the_system() { administrator.logs_in_to_admin_page_if_first_time(); administrator.opens_categories_list(); administrator.selects_add_category(); administrator.adds_new_category("Java Developers","JAVA"); administrator.should_see_confirmation_message("The Category has been created"); job_seeker.opens_job_page(); job_seeker.should_see_job_category("Java Developers"); } Tests can be pending @Pending @Test public void administrator_adds_an_existing_category_to_the_system() {}}
  44. 44. Defining your test stepspublic class AdministratorSteps extends ScenarioSteps { A step library @Step public void opens_categories_list() { AdminHomePage page = getPages().get(AdminHomePage.class); page.open(); page.selectObjectType("Categories"); } High level steps... @Step public void selects_add_category() { CategoriesPage categoriesPage = getPages().get(CategoriesPage.class); categoriesPage.selectAddCategory(); } @Step public void adds_new_category(String label, String code) { EditCategoryPage newCategoryPage = getPages().get(EditCategoryPage.class); newCategoryPage.saveNewCategory(label, code); } ...implemented @Step public void should_see_confirmation_message(String message) { with Page Objects AdminPage page = getPages().get(AdminPage.class); page.shouldContainConfirmationMessage(message); } @StepGroup ...or with other steps public void deletes_category(String name) { opens_categories_list(); displays_category_details_for(name); deletes_category(); }}
  45. 45. Defining your page objectspublic class EditCategoryPage extends PageObject { @FindBy(id="object_label") WebElement label; Provides some useful @FindBy(id="object_code") utility methods... WebElement code; @FindBy(name="_save") WebElement saveButton; public EditCategoryPage(WebDriver driver) { super(driver); } public void saveNewCategory(String labelValue, String codeValue) { typeInto(label, labelValue); typeInto(code, codeValue); saveButton.click(); }} but otherwise a normal WebDriver Page Object
  46. 46. Data-driven testing Test data categories.csvpublic class DataDrivenCategorySteps extends ScenarioSteps { Test steps public DataDrivenCategorySteps(Pages pages) { super(pages); } private String name; private String code; @Steps public AdminSteps adminSteps; public void setCode(String code) {...} public void setName(String name) {...} @Step public void add_a_category() { adminSteps.add_category(name, code); }}
  47. 47. Data-driven testing Test data categories.csvpublic class DataDrivenCategorySteps extends ScenarioSteps { Test steps public DataDrivenCategorySteps(Pages pages) { super(pages); } private String name; private String code; @Steps public AdminSteps adminSteps; @Steps public void setCode(String code) {...} public DataDrivenCategorySteps categorySteps; public void setName(String name) {...} @Step @Test public void add_a_category() { Call this step for public void adding_multiple_categories() throws IOException { adminSteps.add_category(name, code); steps.login_to_admin_page_if_first_time();} } steps.open_categories_list(); each row withTestDataFrom("categories.csv").run(categorySteps).add_a_category(); }
  48. 48. Now run your tests
  49. 49. Displaying the results in easyb
  50. 50. Displaying the results in easyb
  51. 51. Thucydides reports Browse the features
  52. 52. Browse the stories Browse the stories
  53. 53. Browse the stories Browse the test scenarios
  54. 54. Illustrating the test paths A test scenario Steps Test scenarios
  55. 55. Illustrating the test paths Test scenario Steps Test scenarios Screenshots
  56. 56. Functional coverage Features
  57. 57. Functional coverage User stories
  58. 58. Functional coverage Passing tests Pending tests
  59. 59. Progress
  60. 60. Functional coverage Test scenarios
  61. 61. Functional coverage
  62. 62. References easyb.org github.com/thucydides-webtests wakaleo.com/thucydides
  63. 63. The Circle is Complete Automated web tests as a team communication tool John  Ferguson  Smart Email:  john.smart@wakaleo.com Web:  hCp://www.wakaleo.com TwiCer:  wakaleo
  1. A particular slide catching your eye?

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

×