secret
Created

SpecFlow Hello World

  • Download Gist
SpecFlowFeature1.feature
Cucumber
1 2 3 4 5 6
Feature: SpecFlowFeature1
I want to be able to go to google.com
 
Scenario: Go to google.com
When I navigate to google.com
Then I should go to google.com
SpecFlowFeature1Steps.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
using System;
using TechTalk.SpecFlow;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
 
namespace SpecFlow
{
[Binding]
public class SpecFlowFeature1Steps
{
[When(@"I navigate to google\.com")]
public void WhenINavigateToGoogle_Com()
{
WebBrowser.Current.Navigate().GoToUrl("http://google.com");
}
[Then(@"I should go to google\.com")]
public void ThenIShouldGoToGoogle_Com()
{
Assert.That(WebBrowser.Current.Url, Is.SamePath("http://www.google.com"));
}
}
}
WebBrowser.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
 
namespace SpecFlow
{
[Binding]
class WebBrowser
{
public static IWebDriver Current
{
get
{
if (!ScenarioContext.Current.ContainsKey("browser"))
{
ScenarioContext.Current["browser"] = new FirefoxDriver();
}
return ScenarioContext.Current.Get<IWebDriver>("browser");
}
}
 
[AfterScenario]
public static void Quit()
{
if (ScenarioContext.Current.ContainsKey("browser"))
{
Current.Quit();
}
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.