How to use WebApplicationFactory/Program.cs with Selenium

155 views
Skip to first unread message

Lawrence McCartin

unread,
Dec 24, 2023, 9:20:01 AM12/24/23
to Selenium Users
I've found older solutions to this problem, but nothing for .NET 6 webapps that only use Program.cs and hope someone can point me in the right direction.

We're basically doing the cutomized WebApplicationFactory approach (except with Xunit) as shown here:

https://learn.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-8.0#customize-webapplicationfactory

And it works great, we can arrange whatever data we want in the DBContext in the test: 

using (var scope = scopeFactory.CreateScope())
{
    var context = scope.ServiceProvider.GetService<PriceListDbContext>();
    var agency = new Agency();

    agency.AgencyName = "DAS";
    agency.AgencyNo = 15000;
    context.Agencies.Add(agency);

    context.SaveChanges();
}

in a SQLite instance and then do integration tests using the client from the factory.  

But when we try to fire up Selenium in a test with that DBContext arrange, the data isn't there.  So, seems like we're hitting two separate apps.  There are posts about how to solve this in older dotnet versions, but not the newer versions when we don't use a separate startup.cs file.
Reply all
Reply to author
Forward
0 new messages