Skip to content

Commit e2c592a

Browse files
committed
Changes to accept options as dictionary inplace of object
1 parent 1087a34 commit e2c592a

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

LambdaTest.Sdk.Utils/SmartUI.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#nullable enable
2+
13
using System;
24
using System.Net.Http;
35
using System.Text.Json;
@@ -46,20 +48,36 @@ public static async Task<string> FetchDomSerializer()
4648
}
4749
}
4850

49-
public static async Task<string> PostSnapshot(DomObject snapshot, string pkg, object options = null)
51+
public static async Task<string> PostSnapshot(DomObject snapshot, string pkg, Dictionary<string, object>? options =null)
5052
{
5153
try
5254
{
53-
object snapshotObject = new
55+
// object snapshotObject = new
56+
// {
57+
// dom = snapshot.Dom,
58+
// name = snapshot.Name,
59+
// url = snapshot.Url
60+
// };
61+
62+
// var jsonObject = new
63+
// {
64+
// snapshot = options != null ? new { dom = snapshot.Dom, name = snapshot.Name, url = snapshot.Url, options } : snapshotObject,
65+
// testType = pkg
66+
// };
67+
68+
// var json = JsonSerializer.Serialize(jsonObject);
69+
70+
var snapshotData = new SnapshotData
5471
{
5572
dom = snapshot.Dom,
5673
name = snapshot.Name,
57-
url = snapshot.Url
74+
url = snapshot.Url,
75+
options = options ?? new Dictionary<string, object>()
5876
};
5977

6078
var jsonObject = new
6179
{
62-
snapshot = options != null ? new { dom = snapshot.Dom, name = snapshot.Name, url = snapshot.Url, options } : snapshotObject,
80+
snapshot = snapshotData,
6381
testType = pkg
6482
};
6583

@@ -95,5 +113,13 @@ public class DomObject
95113
public string Url { get; set; } = string.Empty;
96114
public string Name { get; set; } = string.Empty;
97115
}
116+
117+
public class SnapshotData
118+
{
119+
public DomContent? dom { get; set; }
120+
public string? name { get; set; }
121+
public string? url { get; set; }
122+
public Dictionary<string, object>? options { get; set; } // Nullable for handling cases with or without options
123+
}
98124
}
99125
}

LambdaTest.Selenium.Driver/SmartUI.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class SmartUISnapshot
1212
{
1313
private static readonly ILogger SmartUILogger = Logger.CreateLogger("Lambdatest.Selenium.Driver");
1414

15-
public static async Task CaptureSnapshot(IWebDriver driver, string name, object? options = null)
15+
public static async Task CaptureSnapshot(IWebDriver driver, string name, Dictionary<string, object>? options = null)
1616
{
1717
if (string.IsNullOrEmpty(name))
1818
{
@@ -80,7 +80,7 @@ public static async Task CaptureSnapshot(IWebDriver driver, string name, object?
8080
};
8181

8282
var apiResponseJSON = await LambdaTest.Sdk.Utils.SmartUI.PostSnapshot(dom, "Lambdatest.Selenium.Driver", options);
83-
var apiResponse = JsonSerializer.Deserialize<ApiResponse>(apiResponseJSON);
83+
var apiResponse = JsonSerializer.Deserialize<ApiResponse>(apiResponseJSON, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
8484

8585
if (apiResponse?.Data?.Warnings != null && apiResponse.Data.Warnings.Count > 0)
8686
{
@@ -106,6 +106,7 @@ private class ApiResponse
106106

107107
private class ApiData
108108
{
109+
public string Message { get; set; } = string.Empty;
109110
public List<string> Warnings { get; set; } = new List<string>();
110111
}
111112

0 commit comments

Comments
 (0)