48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using Microsoft.Playwright;
|
|
|
|
namespace Enciphered.Blazor.UIComponents.Tests;
|
|
|
|
/// <summary>
|
|
/// Base class for Playwright tests. Creates a fresh browser context per test.
|
|
/// </summary>
|
|
public abstract class PlaywrightTestBase
|
|
{
|
|
protected IBrowser Browser { get; private set; } = null!;
|
|
protected IBrowserContext Context { get; private set; } = null!;
|
|
protected IPage Page { get; private set; } = null!;
|
|
protected string BaseUrl => GlobalSetup.Server.BaseUrl;
|
|
|
|
protected static ILocatorAssertions Expect(ILocator locator) => Assertions.Expect(locator);
|
|
protected static IPageAssertions Expect(IPage page) => Assertions.Expect(page);
|
|
|
|
private static IPlaywright? _playwright;
|
|
private static IBrowser? _sharedBrowser;
|
|
|
|
[OneTimeSetUp]
|
|
public async Task PlaywrightOneTimeSetUp()
|
|
{
|
|
_playwright ??= await Playwright.CreateAsync();
|
|
_sharedBrowser ??= await _playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
|
|
{
|
|
Headless = true
|
|
});
|
|
Browser = _sharedBrowser;
|
|
}
|
|
|
|
[SetUp]
|
|
public async Task PlaywrightSetUp()
|
|
{
|
|
Context = await Browser.NewContextAsync(new BrowserNewContextOptions
|
|
{
|
|
IgnoreHTTPSErrors = true
|
|
});
|
|
Page = await Context.NewPageAsync();
|
|
}
|
|
|
|
[TearDown]
|
|
public async Task PlaywrightTearDown()
|
|
{
|
|
await Context.CloseAsync();
|
|
}
|
|
}
|