-
Notifications
You must be signed in to change notification settings - Fork 311
Selenium web tests: in-process hosting of ASP.NET Core web application #1139
Comments
TestServer is an in memory server only, it does not open any ports accessible from a web browser. It's designed for use in unit tests. There are a few other issues about geting Razor to work with TestServer. For Selenium testing why not just drop the TestServer and start Kestrel normally? |
Okay, I tried to run the web server with Kestrel now:
However, on Edit: indeed the libuv.dll resides in the output of MyProject.WebClient but not in the output of MyProject.WebClient.WebTests - do I have to reference some special NuGet package for libuv? |
Second problem: even when manually copying the libuv.dll to the output of the WebTests project, the test starts to run, but the Kestrel server never answers to any request. Is it important to run it on a different thread? |
Here is a repro solution:
Info 1: note, that although using the new project format, I have to target net47, otherwise we wouldn't even be able to use Selenium) Info 2: I set the platform to x86, seems to be the default for the web app and wanted to make sure that the webtests project targets the same platform. |
I imagine the libuv issue is the same as all the others. Just do a GitHub search for |
@khellang : I found the following workaround:
Why is this necessary? Is this going to get fixed? What are those two settings doing to my project? |
I have the libuv workarounded now + I am using the developer error page. My problem now is that Kestrel can't compile the Razor views from the other project:
I don't even have a project.json. How to overcome this problem? Edit: I found dotnet/sdk#958, however, it doesn't help. I switched my test project to reference the |
See #954 for view discovery. |
What _baseAddress do you get back? |
@drauch - libuv is native code. As such you have to use the version that matches the processor architecture your application runs on. |
@Tratcher : http://localhost:5000/ Finally got it working, I had to use #959 (comment) which uses the code from https://github.com/aspnet/Mvc/blob/66deaf0b3fb935027730cf470cf6a331e69f2cee/test/Microsoft.AspNetCore.Mvc.FunctionalTests/Microsoft.AspNetCore.Mvc.FunctionalTests.csproj#L79-L85 to fix the Razor issue. It seems better than to manually try to load some assemblies. If anybody else wants to wait for a "real" fix, follow the aspnet/Mvc#6233 issue. Thank you everybody for your time! |
@drauch the workaround you linked to + the instantiation code from above was able to get my instance working with Selenium as well. Hopefully others can find this page, the Kestral error was not immediately obvious to me in VS2017. Thanks! |
@drauch I was able to make this work with a core 2.0 test library (Microsoft.NET.Sdk) targeting net70, however when I try the exact same thing with a full framework 4.7 old style csproj, I am getting these errors: Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred: I am unsure if the fix for the razor issue you posted is compatible with the old style csproj format. Any ideas ? |
It certainly looks like either your deps file or your refs folder is not in the build output. Are you sure you have added the copy-deps-file task? Are you sure you have shadow copying disabled? |
I copied the same fixes in the old style csproj. I ran the test from the test explorer, and from the console with nunit3-console (by default, it does not shadow copy), and I still have the same problem. I copied your InProcKestrel solution, fixed it with the fixes in this post and made it work. I then added the OldProjectFormat as a full framework 4.7 project, made the same fixes, and I still have the same problem, even in your solution. I uploaded it to github at https://github.com/CurlyFire/InProcKestrel Can you have a peak ? Thanks |
I think I figured out what was missing. I compared the bin folders of your test project dans my old format project, and the refs folder was missing from the old format bin folder. I started it up and everything worked. However, I don't know why it's not copied... |
I have opened your solution with VS2017 and ReSharper installed. I could execute your test in the InProcKestrel.WebTests project without any problems. I even debugged it to look if the page renders correctly, no problem at all. The old project didn't even compile. Note: In my solution above I'm not using the old project format! I'm using the new project format, I just switched the TargetFramework manually from .NET Core to .NET 4.7! I don't know anything about how to run it using the old project format, sorry! |
Allright thanks. You probably don't have the full framework 4.7 installed... |
I isolated what fix copies the refs folder to the output folder of the testproject. It seems it's true I'm not sure why it's not working for the old style csproj project... Gonna keep digging |
Was explained in aspnet/Razor#2146 |
For our Selenium web test suite we are trying to host our ASP.NET Core 1.1 web application (targetting net462) using in-process hosting with the
TestServer
. Both projects reside in the same solution.We encounter two problems when doing so, and I have the feeling those are related.
In our NUnit3 setup fixture we try to host the page using the following code:
server.BaseAddress is http://localhost -> when I surf to that location it does not show the web application, instead it shows the IIS default page. Which is somewhat "right", because I have a local full-fledged IIS server running on port 80 ... don't know how this is support to work ...
Interestingly enough, server.CreateRequest("/").GetAsync().Result does not return the IIS default page but instead results in an exception:
OneTimeSetUp: System.AggregateException : One or more errors occurred.
----> Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException : One or more compilation failures occurred:
[...]
Which looks a lot like Razor isn't able to compile the view due to missing assemblies (the web test project references the web app project using a project reference, which looks like it isn't enough to pull the required assemblies to compile razor views?!
What am I doing wrong? How to use in-process hosting to run my web tests? I tried to find something in the docs @ https://docs.microsoft.com/en-us/aspnet/core/testing/integration-testing but no hit...
The text was updated successfully, but these errors were encountered: