Skip to content

Instantly share code, notes, and snippets.

@BenHall
Created January 7, 2010 10:07
Show Gist options
  • Save BenHall/271138 to your computer and use it in GitHub Desktop.
Save BenHall/271138 to your computer and use it in GitHub Desktop.
Compare C# to Ruby + WebRat or Watir
Given /^(?:I'm on|I go to) the search page$/ do
@browser.goto 'http://www.google.com/'
end
When /^I search for \"(.*)\"$/ do |query|
@browser.text_field(:name, 'q').set(query)
@browser.button(:name, 'btnG').click
end
Then /^I should be on the search page$/ do
@browser.title.should == "Google"
end
Then /^I should see \"(.*)\" in the results$/ do |text|
@browser.text.should =~ /#{text}/m
end
Given /^(?:I'm on|I go to) the search page$/ do
visit 'http://www.google.com'
end
When /^I search for "([^\"]*)"$/ do |query|
fill_in 'q', :with => query
click_button 'Google Search'
end
Then /^I should be on the search page$/ do
dom.search('title').should == "Google" # I think
end
Then /^I should see \"(.*)\" in the results$/ do |text|
response.should contain(text)
end
using Cuke4Nuke.Framework;
using NUnit.Framework;
using WatiN.Core;
namespace Google.StepDefinitions
{
public class SearchSteps
{
Browser _browser;
[Before]
public void SetUp()
{
_browser = new WatiN.Core.IE();
}
[After]
public void TearDown()
{
if (_browser != null)
{
_browser.Dispose();
}
}
[When(@"^(?:I'm on|I go to) the search page$")]
public void GoToSearchPage()
{
_browser.GoTo("http://www.google.com/");
}
[When("^I search for \"(.*)\"$")]
public void SearchFor(string query)
{
_browser.TextField(Find.ByName("q")).TypeText(query);
_browser.Button(Find.ByName("btnG")).Click();
}
[Then("^I should be on the search page$")]
public void IsOnSearchPage()
{
Assert.That(_browser.Title == "Google");
}
[Then("^I should see \"(.*)\" in the results$")]
public void ResultsContain(string expectedResult)
{
Assert.That(_browser.ContainsText(expectedResult));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment