Skip to content

Instantly share code, notes, and snippets.

@pdelre
Created February 25, 2013 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdelre/30f5b21350d844c8a326 to your computer and use it in GitHub Desktop.
Save pdelre/30f5b21350d844c8a326 to your computer and use it in GitHub Desktop.
SpecFlow Hello World
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
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"));
}
}
}
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();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment