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,21 @@ 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+ SmartUILogger . LogWarning ( "SessionId not available or accessible from driver." ) ;
57+ }
58+
5459 if ( options == null )
5560 {
5661 options = new Dictionary < string , object > ( ) ;
@@ -68,7 +73,8 @@ public static async Task<String> CaptureSnapshot(IWebDriver driver, string name,
6873 url: document.URL
6974 });" ;
7075
71- var domJSON = ( string ) ( ( IJavaScriptExecutor ) driver ) . ExecuteScript ( snapshotScript ) ;
76+ // Execute script and get DOM JSON using dynamic driver
77+ var domJSON = ( string ) driver . ExecuteScript ( snapshotScript ) ;
7278
7379 if ( domJSON == null )
7480 {
@@ -116,17 +122,17 @@ public static async Task<String> CaptureSnapshot(IWebDriver driver, string name,
116122 SmartUILogger . LogInformation ( $ "Snapshot captured: { name } ") ;
117123
118124 // Get Snapshot Status
119- var timeout = 600 ;
125+ var timeout = 600 ;
120126 if ( options . ContainsKey ( "timeout" ) )
121127 {
122- var tempTimeout = ( int ) options [ "timeout" ] ;
123- if ( tempTimeout < 30 || tempTimeout > 900 )
128+ var tempTimeout = ( int ) options [ "timeout" ] ;
129+ if ( tempTimeout < 30 || tempTimeout > 900 )
124130 {
125131 SmartUILogger . LogWarning ( "Timeout value is out of range(30-900). Defaulting to 600 seconds." ) ;
126132 }
127133 else
128134 {
129- timeout = tempTimeout ;
135+ timeout = tempTimeout ;
130136 }
131137 }
132138 var snapshotStatusJSON = await LambdaTest . Sdk . Utils . SmartUI . GetSnapshotStatus ( contextId , timeout , name ) ;
0 commit comments