在ASP.NET 5/MVC 6上运行Selenium测试之前,先启动IIS Express. [英] Starting IIS Express before running Selenium tests on ASP.NET 5 / MVC 6

查看:53
本文介绍了在ASP.NET 5/MVC 6上运行Selenium测试之前,先启动IIS Express.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个VS解决方案,其中包含一个"web"项目(ASP.NET v5)和一个"web.Tests"项目(xunit.net 2.1beta)-其中一项测试是检查渲染的页面,我试图让测试自动启动该站点,所以我不需要使其单独/手动运行.

I have a VS solution with a "web" project (ASP.NET v5) and a "web.Tests" project (xunit.net 2.1beta) -- one of the tests is checking the rendered pages, and I'm trying to have the test bring up the site automatically, so I don't need to have it running separately/manually.

namespace web.Tests
{
  public abstract class BrowserTest : IDisposable
  {
    protected readonly IisExpress server;
    protected readonly IWebDriver driver;

    protected BrowserTest()
    {
      var project = ProjectLocation.FromPath(Path.Combine(SolutionRoot, "src", "web", "wwwroot"));
      var app = new WebApplication(project, 8080);
      server = new IisExpress(app);
      server.Start();
      driver = new PhantomJSDriver();
    }

    public void Dispose()
    {
      server.Stop();
    }
  }
}

服务器可以正常启动和停止,但是当我打一个页面时会收到一个HTTP 500,带有System.InvalidOperationException:
A type named 'StartupProduction' or 'Startup' could not be found in assembly 'web.Tests'.

The server starts and stops fine, but I get an HTTP 500 when I hit a page, with a System.InvalidOperationException:
A type named 'StartupProduction' or 'Startup' could not be found in assembly 'web.Tests'.

如何指定要从"web"项目而不是"web.Tests"项目运行Startup.cs?

How do I specify that I want to run Startup.cs from the "web" project, not the "web.Tests" project?

推荐答案

此问题已通过切换为使用Kestrel作为主机来解决-尤其是因为Kestrel现在是ASP.NET 5中唯一受支持的主机

This was fixed by switching to Kestrel as the host -- especially since Kestrel is now the only supported host in ASP.NET 5

using System;
using System.Diagnostics;
using System.IO;
using OpenQA.Selenium;
using OpenQA.Selenium.PhantomJS;

namespace Test
{
    public abstract class PhantomFixture : IDisposable
    {
        public readonly IWebDriver driver;
        private readonly Process server;

        protected PhantomFixture()
        {
            server = Process.Start(new ProcessStartInfo
            {
                FileName = "dnx.exe",
                Arguments = "web",
                WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), "..", "Web")
            });
            driver = new PhantomJSDriver();
        }

        public void Dispose()
        {
            server.Kill();
            driver.Dispose();
        }
    }
}

(显然,将Path.Combine(...)中的参数替换为Web应用程序所在的位置)

(obviously replacing the arguments in Path.Combine(...) with where your web app is located)

这篇关于在ASP.NET 5/MVC 6上运行Selenium测试之前,先启动IIS Express.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆