2

I've been looking at Playwright as a replacement for Selenium to process end-to-end tests. I would like to run the tests in memory, as there are many benefits from using mock services and removing all the set-up or tear-down.

I've been finding it a bit of a challenge to launch the server against a Blazor wasm project, Blazor server is fine - no worries there (Demonstration of it working in Blazor Server https://github.com/carlblanchard/EndToEndBlazorWasmPlaywrightTesting)

I just can't figure it out for a WASM project, If anyone could provide some assistance I'd be very grateful. (WASM branch - https://github.com/carlblanchard/EndToEndBlazorWasmPlaywrightTesting/tree/InMemoryWasmHostedTests)

ca53rlb
  • 77
  • 5

1 Answers1

0

The solution to this problem is far more simple than it looks, just take a look to the Blazor Wasm + Asp.Net Core Hosted template solution, exactly, in the startup at the application configuration part, there must be a code that looks like this

        app.UseWebAssemblyDebugging();
        
        app.UseHttpsRedirection();

        app.UseBlazorFrameworkFiles();
        app.UseStaticFiles();

        app.UseRouting();


        app.MapRazorPages();
        app.MapControllers();
        app.MapFallbackToFile("index.html");

That code is what makes the API, in case that the requested url is not associated to any route, to fallback to the frontend.

So, I suggest to use something like that, have a Api project that fallback to the front (Remember to add a referente of your Client project in the new Api), and use the WebApplicationFactory to setup in memory that Api

Then, you can use Playwright to access the Api Address, and it will fallback to the blazor frontend.

If you want a more "cody" answer, here I have a repository with the solution, https://github.com/HernanFAR/inmemoryblazor

Hernan
  • 73
  • 3
  • 6