Skip to content

Instantly share code, notes, and snippets.

@leonardoeloy
Created July 12, 2012 19:25
Show Gist options
  • Save leonardoeloy/3100313 to your computer and use it in GitHub Desktop.
Save leonardoeloy/3100313 to your computer and use it in GitHub Desktop.
Multiple browsers tests with Webinator, SpecFlow and NUnit
Feature: Authentication
In order to SOMETHING
As SOMEONE
I want to SOMETHING
Scenario: Registering with a valid e-mail
Given I am on the registration page
When I fill the "E-Mail" field with "valid@email.com"
And I click "OK"
Then I should be on the confirmation page
Scenario: Registering with an invalid e-mail
Given I am on the registration page
When I fill the "E-Mail" field with "invalidemail.com"
And I click "OK"
Then I should see the error "Invalid e-mail, please verify and try again."
And I should be on the registration page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using TechTalk.SpecFlow;
using Webinator;
namespace TestNamespace.Steps
{
[Binding]
class AuthenticationSteps
{
private MultipleBrowsers _multipleBrowsers;
public AuthenticationSteps()
{
_multipleBrowsers = new MultipleBrowsers(new List<Config.AvailableBrowsers>
{
// TODO: Figure out why InternetExplorer doesn't work well alongside Chrome.
// Config.AvailableBrowsers.Chrome,
Config.AvailableBrowsers.Firefox,
Config.AvailableBrowsers.InternetExplorer
});
}
[Given(@"I am on the registration page")]
public void GivenIAmOnTheMainPage()
{
_multipleBrowsers.RunTest(web => web.GoToUrl("http://localhost/PROJECT/Authentication/Registration"));
}
[When(@"I fill the ""(.*)"" field with ""(.*)""")]
public void WhenFillField(string label, string value)
{
_multipleBrowsers.RunTest(web => StepsHelper.FillField(web, label, value));
}
[When(@"I click ""(.*)""")]
public void ThenIClick(string buttonValue)
{
_multipleBrowsers.RunTest(web => StepsHelper.ClickButton(web, buttonValue));
}
[Then(@"I should be on the confirmation page")]
public void ThenIShouldBeOnTheConfirmationPage()
{
_multipleBrowsers.RunTest(delegate(IWebManager web)
{
var confirmationUrl = "http://localhost/PROJECT/Authentication/Confirmation";
Assert.AreEqual(confirmationUrl, web.Url());
web.CloseBrowser();
});
}
[Then(@"I should see the error ""(.*)""")]
public void ThenIShouldSeeTheError(string text)
{
_multipleBrowsers.RunTest(delegate(IWebManager web)
{
var pageText = web.GetText(LocateBy.Id("error"));
Assert.IsNotNull(pageText);
Assert.AreEqual(text, pageText);
});
}
[Then(@"I should be on the registration page")]
public void ThenIShouldBeOnTheRegistrationPage()
{
_multipleBrowsers.RunTest(delegate(IWebManager web)
{
var registrationUrl = "http://localhost/PROJECT/Authentication/Registration";
Assert.AreEqual(registrationUrl, web.Url());
web.CloseBrowser();
});
}
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using Webinator;
namespace TestNamespace
{
class MultipleBrowsers
{
private List<Config.AvailableBrowsers> _browsers;
private List<IWebManager> _webManagers = new List<IWebManager>();
private Config _baseConfig = new Config
{
LogScreenshots = true,
LogLevel = Config.AvailableLogLevels.Verbose,
BaseUrl = "about:blank",
Framework = Config.AvailableFrameworks.WebDriver
};
public MultipleBrowsers(List<Config.AvailableBrowsers> browsers)
{
_browsers = browsers;
CreateWebManagers();
}
private void CreateWebManagers()
{
foreach (var browser in _browsers)
{
var localConfig = new Config
{
LogScreenshots = _baseConfig.LogScreenshots,
LogLevel = _baseConfig.LogLevel,
BaseUrl = _baseConfig.BaseUrl,
Framework = _baseConfig.Framework,
Browser = browser
};
var web = WebManagerFactory.CreateInstance(localConfig);
_webManagers.Add(web);
}
}
public void RunTest(Action<IWebManager> action)
{
foreach (var web in _webManagers)
{
Debug.WriteLine("Running test with " + web.Config.Browser);
action(web);
}
}
}
}
@leonardoeloy
Copy link
Author

For some Christ forsaken reason, whenever I'm running these tests against any combination that involves Chrome and Internet Explorer, the latter won't ever send a post request. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment