Getting started with specflow
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.
Setup for Specflow
Pre -Requsite:
Download Visual Studio IDE
-
Create a new project
-
Install specflow visual studio integration, Nunit Adapter & Nunit framework
- Download specflow for visual studio as shown below
A Simple Google Search using Specflow
This is a simple example to search in Google. It containt two parts,
- Feature File
- 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);
}
}
}