@@ -11,7 +11,6 @@ namespace LambdaTest.Playwright.Driver
1111 public static class SmartUISnapshot
1212 {
1313 private static readonly ILogger SmartUILogger = Logger . CreateLogger ( "Lambdatest.Playwright.Driver" ) ;
14-
1514 public static async Task CaptureSnapshot ( IPage page , string name , Dictionary < string , object > ? options = null )
1615 {
1716 if ( string . IsNullOrEmpty ( name ) )
@@ -39,6 +38,31 @@ public static async Task CaptureSnapshot(IPage page, string name, Dictionary<str
3938
4039 string script = domSerializerScript . Data . Dom ;
4140
41+ if ( options == null )
42+ {
43+ options = new Dictionary < string , object > ( ) ;
44+ }
45+
46+ // Get test details from LambdaTestHook to extract the test ID
47+ string sessionId = "" ;
48+ try
49+ {
50+ var testDetailsResponse = await page . EvaluateAsync < string > ( "_ => {}" , "lambdatest_action: {\" action\" : \" getTestDetails\" }" ) ;
51+ if ( ! string . IsNullOrEmpty ( testDetailsResponse ) )
52+ {
53+ var testDetails = JsonSerializer . Deserialize < TestDetailsResponse > ( testDetailsResponse , new JsonSerializerOptions { PropertyNameCaseInsensitive = true } ) ;
54+ sessionId = testDetails ? . Data ? . SessionId ?? $ "playwright_{ Guid . NewGuid ( ) : N} ";
55+ }
56+ }
57+ catch ( Exception )
58+ {
59+ SmartUILogger . LogError ( "Failed to get test details from LambdaTestHook." ) ;
60+ }
61+ if ( ! string . IsNullOrEmpty ( sessionId ) )
62+ {
63+ // Append sessionId to options
64+ options [ "sessionId" ] = sessionId ;
65+ }
4266 // Execute the DOM serializer script in the page context
4367 await page . EvaluateAsync ( script ) ;
4468 var optionsJSON = JsonSerializer . Serialize ( options ) ;
@@ -77,7 +101,7 @@ public static async Task CaptureSnapshot(IPage page, string name, Dictionary<str
77101 Url = domContent . Url
78102 } ;
79103
80- var apiResponseJSON = await LambdaTest . Sdk . Utils . SmartUI . PostSnapshot ( dom , "Lambdatest.Playwright.Driver " , options ) ;
104+ var apiResponseJSON = await LambdaTest . Sdk . Utils . SmartUI . PostSnapshot ( dom , "lambdatest-csharp-playwright-driver " , options ) ;
81105 var apiResponse = JsonSerializer . Deserialize < ApiResponse > ( apiResponseJSON , new JsonSerializerOptions { PropertyNameCaseInsensitive = true } ) ;
82106
83107 if ( apiResponse ? . Data ? . Warnings != null && apiResponse . Data . Warnings . Count > 0 )
@@ -160,5 +184,20 @@ private class DomDeserializerResponse
160184 public DomJSONContent Dom { get ; set ; } = new DomJSONContent ( ) ;
161185 public string Url { get ; set ; } = string . Empty ;
162186 }
187+
188+ private class TestDetailsResponse
189+ {
190+ [ System . Text . Json . Serialization . JsonPropertyName ( "data" ) ]
191+ public TestDetailsData Data { get ; set ; } = new TestDetailsData ( ) ;
192+ }
193+
194+ private class TestDetailsData
195+ {
196+ [ System . Text . Json . Serialization . JsonPropertyName ( "test_id" ) ]
197+ public string TestId { get ; set ; } = string . Empty ;
198+
199+ [ System . Text . Json . Serialization . JsonPropertyName ( "session_id" ) ]
200+ public string SessionId { get ; set ; } = string . Empty ;
201+ }
163202 }
164203}
0 commit comments