From 44c63d7d51fed902388a9c3e221c1d9d67b023cf Mon Sep 17 00:00:00 2001 From: Andrey Brovko <97605929+andrey-brovko@users.noreply.github.com> Date: Wed, 13 Jul 2022 09:23:02 +0300 Subject: [PATCH 1/2] Update Hooks.cs --- .../Behavioral.Automation.Playwright/Hooks.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Hooks.cs b/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Hooks.cs index 562a92a9..c11b91ca 100644 --- a/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Hooks.cs +++ b/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Hooks.cs @@ -50,7 +50,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(); } @@ -87,10 +95,11 @@ await _webContext.Page.ScreenshotAsync(new PageScreenshotOptions //TODO Implement configuration private static async Task 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, }); } -} \ No newline at end of file +} From 830bd132c7b78829fa3459e685dc720f7cb889b8 Mon Sep 17 00:00:00 2001 From: Andrey Brovko Date: Wed, 13 Jul 2022 09:27:03 +0300 Subject: [PATCH 2/2] Add record video parameter --- .../Behavioral.Automation.Playwright/Configs/Config.cs | 1 + .../Behavioral.Automation.Playwright/Hooks.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Configs/Config.cs b/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Configs/Config.cs index 06be618f..244e6a7f 100644 --- a/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Configs/Config.cs +++ b/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Configs/Config.cs @@ -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; } \ No newline at end of file diff --git a/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Hooks.cs b/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Hooks.cs index c11b91ca..8c46765d 100644 --- a/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Hooks.cs +++ b/Behavioral.Automation.Playwright/Behavioral.Automation.Playwright/Hooks.cs @@ -22,6 +22,7 @@ public class Hooks private readonly ScenarioContext _scenarioContext; private static readonly float? SlowMoMilliseconds = ConfigManager.GetConfig().SlowMoMilliseconds; private static readonly bool? Headless = ConfigManager.GetConfig().Headless; + private static readonly bool RecordVideo = ConfigManager.GetConfig().RecordVideo; private readonly TestServicesBuilder _testServicesBuilder; public Hooks(WebContext webContext, ScenarioContext scenarioContext, IObjectContainer objectContainer)