SpecFlow + Selenium2 + ASP.NET MVC + TeamCity Not Working

被刻印的时光 ゝ 提交于 2020-01-24 15:05:09

问题


I have some SpecFlow features which are using Selenium 2 to automate some UI testing of an ASP.NET MVC 3 application. When I run these locally, it runs fine and the tests pass. Once committing my changes to Git and pushing the commits to our remote repository for our TeamCity instance to pick up, the tests run and take a hell of a lot longer, only to fail with the following.

Test(s) failed. OpenQA.Selenium.WebDriverException : No response from server for url http://localhost:7055/hub/session/1ada0501-154a-45f7-b0a3-487af59f7a0b/timeouts/implicit_wait

I have tried searching around for various solutions with zero luck of finding anything remotely relevant. If anyone can link to any resources that would make my life easier please feel free to share them. Or help solve this issue.


回答1:


I don't know the answer, but here is or plumbing code that worked for us with the following setup:

  • TeamCity (6.0.3)
  • IIS (from fix virtual folder)
  • ASP.NET MVC3
  • SeleniumDotNet v2.0.3
  • FireFox driver,
  • Firefox version on server: 3.6.17
  • TeamCity is running as Local System (default)

Selenium setup:

public static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(10);

private BrowserContext()
{
    //browser = new InternetExplorerDriver();
    browser = new FirefoxDriver();
    browser.Manage().Timeouts().ImplicitlyWait(DefaultTimeout);
}

Setup/teardown firefox with SpecFlow events:

        [BeforeScenario]
        public void BeforeWebScenario()
        {
            if (!BrowserContext.IsRunning) 
                BrowserContext.Start();

            BrowserContext.Current.Browser.NavigateTo("/Test/RecreateDatabase");
            BrowserContext.Current.Browser.FindElement(By.ClassName("success-message"));
        }

        [AfterScenario]
        public void AfterWebScenario()
        {
            if (ScenarioContext.Current.TestError != null)
            {
                Console.WriteLine("Browser page source for failing test: {0}",
                    BrowserContext.Current.Browser.PageSource);
            }

            bool browserPerScenario;
            if (bool.TryParse(ConfigurationManager.AppSettings["browserPerScenario"], out browserPerScenario) && browserPerScenario)
                BrowserContext.Stop();
        }

        [AfterTestRun()]
        public static void StopBrowser()
        {
            if (BrowserContext.IsRunning) 
                BrowserContext.Stop();
        }



回答2:


taking a wild guess, I think this is the offender:

:7055

Most likely, you are running the built in ASP.NET development server locally and running on a more full featured web server (most likely IIS) on the other server. Unless you have the server running off of a non-standard port (the port mentioned above), you will fail.

One thing to think about is moving from the ASP.NET development server to IIS (or IIS Express). You can then set up the site with localhost and no port.



来源:https://stackoverflow.com/questions/6694442/specflow-selenium2-asp-net-mvc-teamcity-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!