Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class Config
public float? SlowMoMilliseconds { get; set; }

[ConfigurationKeyName("HEADLESS")] public bool? Headless { get; set; } = true;
[ConfigurationKeyName("RECORD_VIDEO")] public bool RecordVideo { get; set; } = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Hooks
private readonly ScenarioContext _scenarioContext;
private static readonly float? SlowMoMilliseconds = ConfigManager.GetConfig<Config>().SlowMoMilliseconds;
private static readonly bool? Headless = ConfigManager.GetConfig<Config>().Headless;
private static readonly bool RecordVideo = ConfigManager.GetConfig<Config>().RecordVideo;
private readonly TestServicesBuilder _testServicesBuilder;

public Hooks(WebContext webContext, ScenarioContext scenarioContext, IObjectContainer objectContainer)
Expand Down Expand Up @@ -50,7 +51,15 @@ public static async Task InitBrowser()
[BeforeScenario]
public async Task CreateContextAsync()
{
_webContext.Context = await _browser!.NewContextAsync();
if (_browser is null)
{
throw new NullReferenceException($"Playwright browser is not initialized.");
}

_webContext.Context = RecordVideo
? await _browser.NewContextAsync(new BrowserNewContextOptions { RecordVideoDir = "videos/" })
: await _browser.NewContextAsync();

_webContext.Page = await _webContext.Context.NewPageAsync();
}

Expand Down Expand Up @@ -87,10 +96,11 @@ await _webContext.Page.ScreenshotAsync(new PageScreenshotOptions
//TODO Implement configuration
private static async Task<IBrowser?> InitBrowserAsync()
{
return await _playwright!.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
if (_playwright is null) throw new NullReferenceException($"Playwright is not initialized.");
return await _playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = Headless,
SlowMo = SlowMoMilliseconds,
});
}
}
}