Skip to content

Commit

Permalink
Allow to override browser setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Romfos committed Mar 10, 2024
1 parent c132779 commit 8d051c1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/AutoTests.Framework.Playwright/PlaywrightHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@ public static async Task BeforeTestRun(ObjectContainer objectContainer)
: new BrowserTypeLaunchOptions { Headless = true };

Program.Main(["install"]);
var playwright = await Microsoft.Playwright.Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync(browserTypeLaunchOptions);

objectContainer.BaseContainer.RegisterInstanceAs(playwright);
objectContainer.BaseContainer.RegisterInstanceAs(browser);
IPlaywright playwright;
if (objectContainer.IsRegistered<IPlaywright>())
{
playwright = objectContainer.Resolve<IPlaywright>();
}
else
{
playwright = await Microsoft.Playwright.Playwright.CreateAsync();
objectContainer.BaseContainer.RegisterInstanceAs(playwright);
}

if (!objectContainer.IsRegistered<IBrowser>())
{
var browser = await playwright.Chromium.LaunchAsync(browserTypeLaunchOptions);
objectContainer.BaseContainer.RegisterInstanceAs(browser);
}
}

[BeforeScenario(Order = 1000)]
Expand Down

0 comments on commit 8d051c1

Please sign in to comment.