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 reportsPassing parameters in Specflow
We can pass any number of parameters to the SpecFlow tests. Consider below feature file.
Feature: Parameters in Feature file
@param
Scenario: Parameter Scenario 1
Given I am on the web page "https://www.softpost.org"
Then I verify that title of the page contains "free tutorial"
@param
Scenario: Parameter Scenario 2
Given I am on the web page "https://www.yahoo.com"
Then I verify that title of the page contains "yahoo"
In above scenarios, we have used re-used same steps but with different parameters. Here is the step definition class containing methods for steps in above scenarios. Note that we can pass other data types like int, double in similar way.
using System;
using TechTalk.SpecFlow;
namespace SpecFlowRunnerProject
{
[Binding]
public class ParametersInFeatureFileSteps
{
[Given(@"I am on the web page ""(.*)""")]
public void GivenIAmOnTheWebPage(string p0)
{
Console.WriteLine("I am on page " + p0);
}
[Then(@"I verify that title of the page contains ""(.*)""")]
public void ThenIVerifyThatTitleOfThePageContains(string p0)
{
Console.WriteLine("Title of the web page is " + p0);
}
}
}
Web development and Automation testing
solutions delivered!!