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
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. 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
}
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
18. SpecFlow - Test Fixture
• BeforeFeature/BeforeScenario: Precondition of each
feature/scenario
• AfterFeature/AfterScenario: Teardown or cleanup after test
execution
• Tags
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
23. Domain Driven Design
• Express your tests in the language of the end-user of the app.
23
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
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)