33using System . Text . Json ;
44using System . Threading . Tasks ;
55using Microsoft . Extensions . Logging ;
6- using OpenQA . Selenium ;
7- using OpenQA . Selenium . Remote ;
86using LambdaTest . Sdk . Utils ;
97
108namespace LambdaTest . Selenium . Driver
@@ -13,7 +11,7 @@ public static class SmartUISnapshot
1311 {
1412 private static readonly ILogger SmartUILogger = Logger . CreateLogger ( "Lambdatest.Selenium.Driver" ) ;
1513
16- public static async Task < String > CaptureSnapshot ( IWebDriver driver , string name , Dictionary < string , object > options = null )
14+ public static async Task < String > CaptureSnapshot ( dynamic driver , string name , Dictionary < string , object > options = null )
1715 {
1816 if ( string . IsNullOrEmpty ( name ) )
1917 {
@@ -43,14 +41,20 @@ public static async Task<String> CaptureSnapshot(IWebDriver driver, string name,
4341
4442 string script = domSerializerScript . Data . Dom ;
4543
46- ( ( IJavaScriptExecutor ) driver ) . ExecuteScript ( script ) ;
44+ // Execute script using dynamic driver
45+ driver . ExecuteScript ( script ) ;
4746
4847 // Extract sessionId from driver
4948 string sessionId = "" ;
50- if ( driver is RemoteWebDriver remoteDriver )
49+ try
5150 {
52- sessionId = remoteDriver . SessionId . ToString ( ) ;
51+ sessionId = driver . SessionId ? . ToString ( ) ?? "" ;
5352 }
53+ catch
54+ {
55+ // SessionId not available or accessible
56+ }
57+
5458 if ( options == null )
5559 {
5660 options = new Dictionary < string , object > ( ) ;
@@ -68,7 +72,8 @@ public static async Task<String> CaptureSnapshot(IWebDriver driver, string name,
6872 url: document.URL
6973 });" ;
7074
71- var domJSON = ( string ) ( ( IJavaScriptExecutor ) driver ) . ExecuteScript ( snapshotScript ) ;
75+ // Execute script and get DOM JSON using dynamic driver
76+ var domJSON = ( string ) driver . ExecuteScript ( snapshotScript ) ;
7277
7378 if ( domJSON == null )
7479 {
@@ -116,17 +121,17 @@ public static async Task<String> CaptureSnapshot(IWebDriver driver, string name,
116121 SmartUILogger . LogInformation ( $ "Snapshot captured: { name } ") ;
117122
118123 // Get Snapshot Status
119- var timeout = 600 ;
124+ var timeout = 600 ;
120125 if ( options . ContainsKey ( "timeout" ) )
121126 {
122- var tempTimeout = ( int ) options [ "timeout" ] ;
123- if ( tempTimeout < 30 || tempTimeout > 900 )
127+ var tempTimeout = ( int ) options [ "timeout" ] ;
128+ if ( tempTimeout < 30 || tempTimeout > 900 )
124129 {
125130 SmartUILogger . LogWarning ( "Timeout value is out of range(30-900). Defaulting to 600 seconds." ) ;
126131 }
127132 else
128133 {
129- timeout = tempTimeout ;
134+ timeout = tempTimeout ;
130135 }
131136 }
132137 var snapshotStatusJSON = await LambdaTest . Sdk . Utils . SmartUI . GetSnapshotStatus ( contextId , timeout , name ) ;
0 commit comments