Skip to content

Commit 2302122

Browse files
authored
Merge pull request #16 from LambdaTest/stage
Release 27th Nov
2 parents def8f6a + eebce7a commit 2302122

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

LambdaTest.Selenium.Driver/LambdaTest.Selenium.Driver.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>net8.0;net48</TargetFrameworks>
44
<PackageId>LambdaTest.Selenium.Driver</PackageId>
5-
<Version>1.0.5</Version>
5+
<Version>1.0.6</Version>
66
<Authors>Lambdatest-SmartUI</Authors>
77
<Company>LambdaTest</Company>
88
<Description>LambdaTest C# Selenium SDK</Description>
@@ -13,10 +13,9 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Selenium.Support" Version="4.21.0" />
17-
<PackageReference Include="Selenium.WebDriver" Version="4.21.0" />
1816
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
1917
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
18+
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
2019
</ItemGroup>
2120

2221
<ItemGroup Condition="'$(TargetFramework)' == 'net48'">

LambdaTest.Selenium.Driver/SmartUI.cs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
using System.Text.Json;
44
using System.Threading.Tasks;
55
using Microsoft.Extensions.Logging;
6-
using OpenQA.Selenium;
7-
using OpenQA.Selenium.Remote;
86
using LambdaTest.Sdk.Utils;
97

108
namespace 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

Comments
 (0)