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 reportsSpecflow Selenium tests
We can execute selenium tests using SpecFlow. In your visual studio project, you need to add Selenium NuGet Package as shown in below image.
Feature: Selenium Feature file
@selenium
Scenario: Selenium Scenario 1
Given I am on the web page "https://www.softpost.org"
Then I verify that title of the page contains "tutorial"
Here is the Step definition class for above feature file. Above test will open Firefox and navigate to www.softpost.org website. Then it will check the title of web page.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
using TechTalk.SpecFlow;
namespace SpecFlowRunnerProject
{
[Binding]
public class ParametersInFeatureFileSteps
{
IWebDriver driver;
[Given(@"I am on the web page ""(.*)""")]
public void GivenIAmOnTheWebPage(string p0)
{
driver= new FirefoxDriver();
Console.WriteLine("I am on page " + p0);
driver.Navigate().GoToUrl(p0);
}
[Then(@"I verify that title of the page contains ""(.*)""")]
public void ThenIVerifyThatTitleOfThePageContains(string p0)
{
Console.WriteLine("Title of the web page is " + p0);
Assert.IsTrue(driver.Title.ToLower().Contains(p0));
driver.Close();
}
}
}
Web development and Automation testing
solutions delivered!!