Reputation: 296
I want to write acceptance tests, with SpecFlow (Gherkin) to verify different scenarios. Especially I want to verify the login process, that uses persistant cookies and sessionstate.
I've done something similar with services, where I programmatically started each service needed for the test, in a servicehost. This enables me to manipulate the IoC container before the service is instantiated.
I want something similar for my MVC controllers. Does anyone have any experience with this sort of testing in MVC 4?
Upvotes: 1
Views: 839
Reputation: 10209
Check out Selenium WebDriver
Here is an example with Chrome Driver:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using NUnit.Framework;
namespace Tests.UI
{
[TestFixture]
public class TestGoogleSearch
{
IWebDriver _driver;
[SetUp]
public void Setup()
{
//path to chrome driver exe
_driver = new ChromeDriver(@"C:\MyProject\lib\");
}
[TearDown]
public void Teardown()
{
_driver.Quit();
}
[Test]
public void TestSearchGoogleForTheAutomatedTester()
{
//Given
//When
_driver.Navigate().GoToUrl("http://www.google.com");
IWebElement queryBox = _driver.FindElement(By.Name("q"));
queryBox.SendKeys("stack overflow");
queryBox.SendKeys(Keys.ArrowDown);
queryBox.Submit();
//Then
Assert.True(_driver.Title.Contains("stack overflow"));
}
}
}
Upvotes: 2