Scott Hanselman's Blog

Updating to .NET 8, updating to IHostBuilder, and running Playwright Tests within NUnit headless or headed on any OS

Follow
In 2007, the author employed Selenium for integration and browser automation testing. Currently, Playwright is preferred for its versatility and compatibility across platforms. To ensure end-to-end testing, Playwright tests are integrated into .NET applications using Visual Studio or VS Code. Previously, a hack involving WebApplicationFactory was used to spin up ASP.NET within unit tests. However, with .NET 8, IHostBuilder has replaced IWebHostBuilder, necessitating code changes. The author's goal is to write Playwright tests within NUnit, which assumes a running web application and a defined URL. A WebApplicationTestBuilderFactory starts the web app within TestHost, retrieving the port dynamically. The builder factory uses a manifest file generated by MSBuild, which is a necessary workaround in .NET 8. However, this hack can be eliminated in .NET 9, making testing more straightforward. With these enhancements, both unit tests and Playwright integration tests can be run across various operating systems and environments, ensuring comprehensive testing of the site updated to .NET 8.
favicon
feeds.hanselman.com
feeds.hanselman.com
Create attached notes ...