@@ -22,6 +22,7 @@ public class Hooks
2222 private readonly ScenarioContext _scenarioContext ;
2323 private static readonly float ? SlowMoMilliseconds = ConfigManager . GetConfig < Config > ( ) . SlowMoMilliseconds ;
2424 private static readonly bool ? Headless = ConfigManager . GetConfig < Config > ( ) . Headless ;
25+ private static readonly bool RecordVideo = ConfigManager . GetConfig < Config > ( ) . RecordVideo ;
2526 private readonly TestServicesBuilder _testServicesBuilder ;
2627
2728 public Hooks ( WebContext webContext , ScenarioContext scenarioContext , IObjectContainer objectContainer )
@@ -50,7 +51,15 @@ public static async Task InitBrowser()
5051 [ BeforeScenario ]
5152 public async Task CreateContextAsync ( )
5253 {
53- _webContext . Context = await _browser ! . NewContextAsync ( ) ;
54+ if ( _browser is null )
55+ {
56+ throw new NullReferenceException ( $ "Playwright browser is not initialized.") ;
57+ }
58+
59+ _webContext . Context = RecordVideo
60+ ? await _browser . NewContextAsync ( new BrowserNewContextOptions { RecordVideoDir = "videos/" } )
61+ : await _browser . NewContextAsync ( ) ;
62+
5463 _webContext . Page = await _webContext . Context . NewPageAsync ( ) ;
5564 }
5665
@@ -87,10 +96,11 @@ await _webContext.Page.ScreenshotAsync(new PageScreenshotOptions
8796 //TODO Implement configuration
8897 private static async Task < IBrowser ? > InitBrowserAsync ( )
8998 {
90- return await _playwright ! . Chromium . LaunchAsync ( new BrowserTypeLaunchOptions
99+ if ( _playwright is null ) throw new NullReferenceException ( $ "Playwright is not initialized.") ;
100+ return await _playwright . Chromium . LaunchAsync ( new BrowserTypeLaunchOptions
91101 {
92102 Headless = Headless ,
93103 SlowMo = SlowMoMilliseconds ,
94104 } ) ;
95105 }
96- }
106+ }
0 commit comments