Getting started with specflow

Download specflow eBook

Remarks

This section provides an overview of what specflow is, and why a developer might want to use it.

It should also mention any large subjects within specflow, and link out to the related topics. Since the Documentation for specflow is new, you may need to create initial versions of those related topics.

A Simple Google Search using Specflow

This is a simple example to search in Google. It containt two parts,

  1. Feature File
  2. Step Definition File

Am not going into much details here as the code itself is self explanatory.

Feature File

Feature:Google  Key word search

@mytag

Scenario: search Spec Flow in Google search bar
Given I have entered the Google Home page
And I have entered spec flow into google search bar
When I press search button
Then the result should be a new pages with results for spec flow
 

Step Definition File

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
using TechTalk.SpecFlow;
using static NUnit.Core.NUnitFramework;

namespace GoogleSearch.GoogleSearch
{
    [Binding]
    public class GoogleKeyWordSearchSteps
    {
          IWebDriver driver = new FirefoxDriver();
        [Given(@"I have entered the Google Home page")]
        public void GivenIHaveEnteredTheGoogleHomePage()
        {
            driver.Navigate().GoToUrl("https://www.google.co.nz");
        }
        
        [Given(@"I have entered spec flow into google search bar")]
        public void GivenIHaveEnteredSpecFlowIntoGoogleSearchBar()
        {
        driver.FindElement(By.XPath("/html/body/div/div[3]/form/div[2]/div[2]/div[1]/div[1]/div[3]/div/div[3]/div/input[1]")).SendKeys("Spec Flow");
        }
        
        [When(@"I press search button")]
        public void WhenIPressSearchButton()
        {
        driver.FindElement(By.XPath("/html/body/div/div[3]/form/div[2]/div[3]/center/input[1]")).Click();
        }
        
        [Then(@"the result should be a new pages with results for spec flow")]
        public void ThenTheResultShouldBeANewPagesWithResultsForSpecFlow()
        {
            //  Assert.AreEqual("Google", driver.Title);
        }
    }
}
 

Setup for Specflow

Pre -Requsite:

Download Visual Studio IDE

  1. Create a new project

  2. Install specflow visual studio integration, Nunit Adapter & Nunit framework

enter image description here

  1. Download specflow for visual studio as shown below

enter image description here

Stats

26 Contributors: 3
Wednesday, December 7, 2016
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook