Web automation in BDD

31
Web Automation in BDD SpecFlow + WatiN

description

Web UI automation test Specflow WatiN Page Object

Transcript of Web automation in BDD

Page 1: Web automation in BDD

Web Automation in BDD

SpecFlow + WatiN

Page 2: Web automation in BDD

What about me?

2

Page 3: Web automation in BDD

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

Page 4: Web automation in BDD

Agenda

• BDD Introduction• Demo• BDD Test Framework (SpecFlow + WatiN)• Test design patterns/practices

4

Page 5: Web automation in BDD

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

Page 6: Web automation in BDD

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 }

Page 7: Web automation in BDD

BDD vs TDD

Page 8: Web automation in BDD

BDD Tools

Page 9: Web automation in BDD

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

Page 10: Web automation in BDD

Scenario: GIVEN, WHEN, THEN

10

Page 11: Web automation in BDD

BDD Framework

11

Page 12: Web automation in BDD

How SpecFlow Works?

Drives

GUI

Page 13: Web automation in BDD

• Demo 1: Coffee Machine

13

Page 14: Web automation in BDD

• Demo 2: Google Search (Compare with WatiN Hello World example)

14

Page 15: Web automation in BDD

SpecFlow - Step Argument

• Step definition: use regular expression to eliminate duplicate script

15

Page 16: Web automation in BDD

SpecFlow - Table argument

16

Page 17: Web automation in BDD

SpecFlow - Context

17

Data Sharing between steps/scenarios

Page 18: Web automation in BDD

SpecFlow - Test Fixture

• BeforeFeature/BeforeScenario: Precondition of each feature/scenario

• AfterFeature/AfterScenario: Teardown or cleanup after test execution

• Tags

Page 19: Web automation in BDD

SpecFlow - Scenario Outline (Data Driven)

Scenario: TC1 Add two numbers

Given I have entered 1 into the calculatorAnd I have entered 2 into the calculatorWhen I press add

Then the result should be 3 on the screen

Scenario: TC2 Add two numbers

Given I have entered 2 into the calculatorAnd I have entered 2 into the calculatorWhen I press add

Then the result should be 4 on the screen

Page 20: Web automation in BDD

Data driven on scenarios.

Page 21: Web automation in BDD

From framework to platform

• Test Report/Test Log

21

NunitTestResults.txt

TestResults.xml

SpecificationResults.html

SpecFlow

• Test environment

• Continuous build

Page 22: Web automation in BDD

Patterns and Practices

• Domain Driven Design• Singleton• Page object pattern• Driver pattern• Reusable modules

22

Page 23: Web automation in BDD

Domain Driven Design

• Express your tests in the language of the end-user of the app.

23

Page 24: Web automation in BDD

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

Page 25: Web automation in BDD

Page Object Pattern

• A simple abstraction of the UI of your web app.

25

Page 26: Web automation in BDD

Driver Pattern

• Driver object defines all actions/events among current page

26

Page 27: Web automation in BDD

Reusable Modules

27

Page 28: Web automation in BDD

Summary

• BDD Concept• SpecFlow Test Framework• Web Automation Practice

28

The framework and pattern matters, not the tools

Page 29: Web automation in BDD

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

Page 30: Web automation in BDD

Questions?

Suggestions?

Page 31: Web automation in BDD

Thank you!

- 余宗宝(@Sandyshow)[email protected]