How can I programmatically launch and interact with an ASP.NET MVC application?

I am working on an ASP.NET MVC application. It HttpApplicationlooks like this:

public class MvcApplication : HttpApplication
{
    protected void Application_Start()
    {
        //Do some sort of initialisation. Set the DependencyResolver.
    }
}

For the integration test, I want to programmatically launch the application and use it DependencyResolverto interact with it. Access DependencyResolverseems easy as I can just call DependencyResolver.Current. However, I did not understand how to start the application initialization logic.

I tried to call new MvcApplication().Init(), but this does not call the method call Application_Start. I tried to inherit from MvcApplicationand provide access to the direct call Application_Start, but this failed with an exception from ASP.NET MVC.

+4
1

Selenium WebDriver MVC. -. MSTest, . Selenium http://docs.seleniumhq.org/docs/03_webdriver.jsp

:

    [TestMethod]
    public void runUITest()
    {
        driver = new FirefoxDriver(); //launches a Firefox window so you can observe the test run
        driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 7));                
        driver.Navigate().GoToUrl("http://localhost/yourWebApp"));
        //assert something
Assert.IsTrue(driver.FindElement(By.XPath("//fieldset[@id='YourControl']/div/div[2]/label/span/span")).Displayed);
        //find an element and click it
        driver.FindElement(By.Id("FormSubmitButton")).Click();           
    }

Selenium WebDriver NuGet.

0

All Articles