Specflow Tutorial
Introduction to SpecFlow Installation of SpecFlowWriting first SpecFlow test in Visual Studio Writing step definitions for a SpecFlow feature file Executing SpecFlow scenarios and feature files Using SpecFlow runner to execute the feature files Using tags in SpecFlow Passing parameters to steps Data table in SpecFlow Scenario Background Scenario outline Hooks in SpecFlow Executing Selenium tests with SpecFlow Executing the failed test multiple times Sharing selenium Webdriver instance in SpecFlow Writing to SpecFlow HTML reportsScenario background in Specflow
Sometimes, we need to execute certain steps, before every scenario in the same feature file. Backgrounds allow you to reuse same steps across multiple scenarios. For example – to test some feature, we might need to filter records before every scenario. So we can put the steps required to filter the records inside Background. These steps would be executed every time each scenario in the same feature file is executed. Consider below feature file.
Feature: This is a simple feature file to demonstrate Background
Background: This is a background
Given I visit a bank ATM
@simple
Scenario: ATM money withdrawal scenario-1 using Background
Given I have $1000 in my account
When I withdraw $200 from ATM
Then my balance should be $800
@simple
Scenario: ATM money withdrawal scenario-2 using Background
Given I have $3000 in my account
When I withdraw $200 from ATM
Then my balance should be $2800
When we execute this feature file, steps in the background are executed before every scenario. Here is the sample output of above scenario execution.
Web development and Automation testing
solutions delivered!!