Web automation in BDD

Post on 12-May-2015

776 views 5 download

Tags:

description

Web UI automation test Specflow WatiN Page Object

Transcript of Web automation in BDD

Web Automation in BDD

SpecFlow + WatiN

What about me?

2

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

Agenda

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

4

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

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 }

BDD vs TDD

BDD Tools

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

Scenario: GIVEN, WHEN, THEN

10

BDD Framework

11

How SpecFlow Works?

Drives

GUI

• Demo 1: Coffee Machine

13

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

14

SpecFlow - Step Argument

• Step definition: use regular expression to eliminate duplicate script

15

SpecFlow - Table argument

16

SpecFlow - Context

17

Data Sharing between steps/scenarios

SpecFlow - Test Fixture

• BeforeFeature/BeforeScenario: Precondition of each feature/scenario

• AfterFeature/AfterScenario: Teardown or cleanup after test execution

• Tags

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

Data driven on scenarios.

From framework to platform

• Test Report/Test Log

21

NunitTestResults.txt

TestResults.xml

SpecificationResults.html

SpecFlow

• Test environment

• Continuous build

Patterns and Practices

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

22

Domain Driven Design

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

23

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 Object Pattern

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

25

Driver Pattern

• Driver object defines all actions/events among current page

26

Reusable Modules

27

Summary

• BDD Concept• SpecFlow Test Framework• Web Automation Practice

28

The framework and pattern matters, not the tools

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

Questions?

Suggestions?

Thank you!

- 余宗宝(@Sandyshow)zbyu81@hotmail.com