Web automation in BDD


Published on

Web UI automation test
Page Object

Published in: Technology, Education
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Thank you ChinaTest committee and all comings
  • Thank you ChinaTest committee and all comings
  • Why BDD?
  • Together with demo to introduce in parallel
  • Question: How to handle Login in your system?
  • Express your tests in the language of the end-user of the our product/softwareBusiness level scenarios: To allow the creation of test scenarios ahead of the SUT delivery.Easy to maintain, less dependent on GUI changes.(domain-specific language, domain driven design....)Not functional point test: xxx dialog, xxx input box1. What must be automated?2. What should be automated?3. What could be automated?4. What won’t be automated?This method allowed us to focus our efforts on those test components that werenecessary and would give the greatest value by assessing the associated business risk,reusability, usage, complexity, and feasibility of each test component
  • 1. In order to walk the browser through several steps in a scenario, you need a way to pass the same browser object between steps in the step definition class.Create a WebBrowser static class towork with the WatiN IE object and the ScenarioContext that SpecFlow uses to store state between steps in a scenario.2. Wrapper browsers/ EncapsulationIE/Firefox/Chrome3. WatiN/Selenium
  • This is widely used in web automation, especially in Selenium community. Here I share my practicesThree essential parts of GUI automation: Find controls, Manipulate controls, VerifyPage object pattern: Find controls
  • Manipulate controlsSeparate this from page object reason:Business logic is too complexSome module is reusable(example of section assessment page, section details page)
  • Object model (user class)Loadable components (Documents tool/ selector tool /master page/logout link)ConstantsWatiN/SeleniumExtensionsWait
  • Go through one real project framework
  • Auto coverage?Easy to use?Selenium or WatiN?Dev/QA ratio?
  • Web automation in BDD

    1. 1. Web Automation in BDD SpecFlow + WatiN
    2. 2. What about me? 2
    3. 3. What about you? • Who is doing test automation? • Who is using open source Selenium or WatiN? • Who is practicing BDD with SpecFlow or Cucumber or other BDD tool? 3
    4. 4. Agenda • BDD Introduction • Demo • BDD Test Framework (SpecFlow + WatiN) • Test design patterns/practices 4
    5. 5. Behaviour Driven Development  One of many agile development techniques  Specification driven by examples  Clear communication between domain experts, developers, testers and customers BDD is an agile software development technique that encourages collaboration between developers, QA, and non- technical or business participants in a software project. It's more about business specifications than about tests. You write a specification for a story and verify whether the specs work as expected. 5
    6. 6. BDD Examples Feature: Serve coffee In order to earn money Customers should be able to buy coffee at all times Scenario: Buy last coffee Given there are 1 coffee left in the machine And I have deposited 1$ When I press the coffee button Then I should be served a coffee [Test] public void TestCoffeeMachine() { // Some test codes here }
    7. 7. BDD vs TDD
    8. 8. BDD Tools
    9. 9. BDD Languages - Gherkin • Domain Specific Language • Easy to understand by customers • Simple with few keywords – Feature – Scenario, Scenario Outline – Given, When, Then • Localized to 35+ languages
    10. 10. Scenario: GIVEN, WHEN, THEN 10
    11. 11. BDD Framework 11
    12. 12. How SpecFlow Works? Drives GUI
    13. 13. • Demo 1: Coffee Machine 13
    14. 14. • Demo 2: Google Search (Compare with WatiN Hello World example) 14
    15. 15. SpecFlow - Step Argument • Step definition: use regular expression to eliminate duplicate script 15
    16. 16. SpecFlow - Table argument 16
    17. 17. SpecFlow - Context 17 Data Sharing between steps/scenarios
    18. 18. SpecFlow - Test Fixture • BeforeFeature/BeforeScenario: Precondition of each feature/scenario • AfterFeature/AfterScenario: Teardown or cleanup after test execution • Tags
    19. 19. SpecFlow - Scenario Outline (Data Driven) Scenario: TC1 Add two numbers Given I have entered 1 into the calculator And I have entered 2 into the calculator When I press add Then the result should be 3 on the screen Scenario: TC2 Add two numbers Given I have entered 2 into the calculator And I have entered 2 into the calculator When I press add Then the result should be 4 on the screen
    20. 20. Data driven on scenarios.
    21. 21. From framework to platform • Test Report/Test Log 21 Nunit TestResults.txt TestResults.xml SpecificationResults.html SpecFlow • Test environment • Continuous build
    22. 22. Patterns and Practices • Domain Driven Design • Singleton • Page object pattern • Driver pattern • Reusable modules 22
    23. 23. Domain Driven Design • Express your tests in the language of the end-user of the app. 23  
    24. 24. Web Browser in Singleton Mode public static class WebBrowser { public static IE Current { get { if (!ScenarioContext.Current.ContainsKey("browser")) ScenarioContext.Current["browser"] = new IE(); return ScenarioContext.Current["browser"] as IE; } } } 24
    25. 25. Page Object Pattern • A simple abstraction of the UI of your web app. 25
    26. 26. Driver Pattern • Driver object defines all actions/events among current page 26
    27. 27. Reusable Modules 27
    28. 28. Summary • BDD Concept • SpecFlow Test Framework • Web Automation Practice 28 The framework and pattern matters, not the tools 
    29. 29. Reference • Specification by Examples - http://specificationbyexample.com/ • MSDN article on BDD: http://msdn.microsoft.com/en- us/magazine/gg490346.aspx • BDD from NDC: http://vimeo.com/43536443 • WATIN and more: http://watinandmore.blogspot.com/ 29
    30. 30. Questions?  Suggestions? 
    31. 31. Thank you!  - 余宗宝(@Sandyshow) zbyu81@hotmail.com