Testing ASP.NET Core app using Protractor in Visual Studio 2015

孤街醉人 提交于 2019-12-08 02:02:39

问题


I've got a ASP.NET Core Project based on the angular2 template from the core template pack. I added a second project with xunit and protractor to run unit test against my main app.

Both work nicely alone, there is just one small thing I miss:

When I want to run the protractor tests I need to host the main project somewhere manually. If I don't host the main project manually it does not run, so all the Tests fail because my page is unreachable.

I probably need to start the main app / project somehow from the test, but I got no idea how. All examples for protractor run against some already running Homepages, none does run against some other project.

How do I start the main ASP.NET Core Project from my test Project, so it is running for testing?

Weird thing is: after I started the main app once using Strg+F5 protractor with ChromeDriver will find the homepage of the app. But I need to run it once manually for the tests to work...

public class EndToEndTests : IDisposable
{
  private const string Url = "https://localhost:44391/";
  private readonly IWebDriver _driver;
  private readonly NgWebDriver _browser;

  public EndToEndTests()
  {
// TODO: somehow get the ASP.NET Core project up and running
    _driver = new ChromeDriver(@"\test\ChromeDriver");
    _driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(10));
    _browser = new NgWebDriver(_driver);
  }

  public void Dispose()
  {
    _driver.Quit();
  }

  [Fact(DisplayName = "Has a title")]
  public void HasATitle()
  {
    _browser.Url = Url;
    Assert.Equal("My page", _browser.Title);
  }

回答1:


You need to self-host your WebApp in your SetUp method.

With .NET 4.5 Owin based applications, you need to use the Microsoft.Owin.Hosting package with WebApp.Start method.

With .NET Core, you need to use WebHostBuilder




回答2:


Trying again. When im developing my webserver is running all the time. So the e2e tests should not need to start the webserver? When it comes to nightly builds the server might need to be started before tests runs. Check TeamServer for niglty build setup. Note: If you look at angular2 homepage you see that they work in an node enviroment. Mayby Protractor.NET is not the way to go? If you want to work with C# i suggest ASP.NET with JQuery. Where you let C# render the html.



来源:https://stackoverflow.com/questions/41675510/testing-asp-net-core-app-using-protractor-in-visual-studio-2015

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