Skip to content

Commit 6aac996

Browse files
authored
Merge pull request #1 from LambdaTest/datatype-fix
fix datatype of resources to list of objects
2 parents fad6c29 + 5067df8 commit 6aac996

File tree

6 files changed

+75
-16
lines changed

6 files changed

+75
-16
lines changed

.github/workflows/publish.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Publish NuGet Packages
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
package-name:
7+
description: 'Package to Publish (utils/selenium)'
8+
required: true
9+
type: choice
10+
options:
11+
- lambdatest-sdk-utils
12+
- lambdatest-selenium-driver
13+
default: 'lambdatest-sdk-utils'
14+
15+
jobs:
16+
build-and-publish:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Setup .NET
24+
uses: actions/setup-dotnet@v3
25+
with:
26+
dotnet-version: '8.x'
27+
28+
- name: Build and publish LambdaTest.Sdk.Utils
29+
if: github.event.inputs.package-name == 'lambdatest-sdk-utils'
30+
run: |
31+
dotnet restore ./LambdaTest.Sdk.Utils
32+
dotnet build ./LambdaTest.Sdk.Utils --configuration Release --no-restore
33+
dotnet pack ./LambdaTest.Sdk.Utils --configuration Release --no-build --output ./LambdaTest.Sdk.Utils/nupkgs
34+
dotnet nuget push ./LambdaTest.Sdk.Utils/nupkgs/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
35+
36+
- name: Build and publish LambdaTest.Selenium.Driver
37+
if: github.event.inputs.package-name == 'lambdatest-selenium-driver'
38+
run: |
39+
dotnet restore ./LambdaTest.Selenium.Driver
40+
dotnet build ./LambdaTest.Selenium.Driver --configuration Release --no-restore
41+
dotnet pack ./LambdaTest.Selenium.Driver --configuration Release --no-build --output ./LambdaTest.Selenium.Driver/nupkgs
42+
dotnet nuget push ./LambdaTest.Selenium.Driver/nupkgs/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}

LambdaTest.Sdk.Utils/LambdaTest.Sdk.Utils.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFramework>net8.0</TargetFramework>
44
<PackageId>LambdaTest.Sdk.Utils</PackageId>
5-
<Version>1.0.0</Version>
5+
<Version>1.0.2</Version>
66
<Authors>Lambdatest-SmartUI</Authors>
77
<Company>LambdaTest</Company>
88
<Description>LambdaTest SDK Utilities for SmartUI CLI in C#</Description>

LambdaTest.Sdk.Utils/SmartUI.cs

Lines changed: 24 additions & 5 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,22 @@ 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+
56+
var snapshotData = new SnapshotData
5457
{
5558
dom = snapshot.Dom,
5659
name = snapshot.Name,
57-
url = snapshot.Url
60+
url = snapshot.Url,
61+
options = options ?? new Dictionary<string, object>()
5862
};
5963

6064
var jsonObject = new
6165
{
62-
snapshot = options != null ? new { dom = snapshot.Dom, name = snapshot.Name, url = snapshot.Url, options } : snapshotObject,
66+
snapshot = snapshotData,
6367
testType = pkg
6468
};
6569

@@ -81,11 +85,18 @@ public static async Task<string> PostSnapshot(DomObject snapshot, string pkg, o
8185
throw new Exception("post snapshot failed", e);
8286
}
8387
}
88+
89+
public class Resource
90+
{
91+
public string content { get; set; } = string.Empty;
92+
public string mimetype { get; set; } = string.Empty;
93+
public string url { get; set; } = string.Empty;
94+
}
8495
public class DomContent
8596
{
8697
public string html { get; set; } = string.Empty;
8798
public List<string> warnings { get; set; } = new List<string>();
88-
public List<string> resources { get; set; } = new List<string>();
99+
public List<Resource> resources { get; set; } = new List<Resource>();
89100
public List<string> hints { get; set; } = new List<string>();
90101
}
91102

@@ -95,5 +106,13 @@ public class DomObject
95106
public string Url { get; set; } = string.Empty;
96107
public string Name { get; set; } = string.Empty;
97108
}
109+
110+
public class SnapshotData
111+
{
112+
public DomContent? dom { get; set; }
113+
public string? name { get; set; }
114+
public string? url { get; set; }
115+
public Dictionary<string, object>? options { get; set; } // Nullable for handling cases with or without options
116+
}
98117
}
99118
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
<PropertyGroup>
33
<TargetFramework>net8.0</TargetFramework>
44
<PackageId>LambdaTest.Selenium.Driver</PackageId>
5-
<Version>1.0.0</Version>
5+
<Version>1.0.2</Version>
66
<Authors>Lambdatest-SmartUI</Authors>
77
<Company>LambdaTest</Company>
88
<Description>LambdaTest C# Selenium SDK </Description>
99
<ImplicitUsings>enable</ImplicitUsings>
1010
<Nullable>enable</Nullable>
1111
</PropertyGroup>
1212
<ItemGroup>
13-
<ProjectReference Include="..\LambdaTest.Sdk.Utils\LambdaTest.Sdk.Utils.csproj" />
14-
</ItemGroup>
15-
<ItemGroup>
13+
<PackageReference Include="LambdaTest.Sdk.Utils" Version="1.0.2" />
1614
<PackageReference Include="Selenium.Support" Version="4.21.0" />
1715
<PackageReference Include="Selenium.WebDriver" Version="4.21.0" />
1816
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />

LambdaTest.Selenium.Driver/SmartUI.cs

Lines changed: 4 additions & 4 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,14 +106,14 @@ 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

112113
private class FetchDomSerializerResponse
113114
{
114115
public FetchDomSerializerData Data { get; set; } = new FetchDomSerializerData();
115116
}
116-
117117
private class FetchDomSerializerData
118118
{
119119
public string Dom { get; set; } = string.Empty;
@@ -122,7 +122,7 @@ private class DomJSONContent
122122
{
123123
public string html { get; set; } = string.Empty;
124124
public List<string> warnings { get; set; } = new List<string>();
125-
public List<string> resources { get; set; } = new List<string>();
125+
public List<LambdaTest.Sdk.Utils.SmartUI.Resource> resources { get; set; } = new List<LambdaTest.Sdk.Utils.SmartUI.Resource>();
126126
public List<string> hints { get; set; } = new List<string>();
127127
}
128128
private class DomDeserializerResponse

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ LambdaTest.Selenium.Driver integrates seamlessly with Selenium WebDriver to capt
2727
To install the packages, use the .NET CLI:
2828

2929
```sh
30-
dotnet add package LambdaTest.Sdk.Utils --version 1.0.0
31-
dotnet add package LambdaTest.Selenium.Driver --version 1.0.0
30+
dotnet add package LambdaTest.Sdk.Utils --version 1.0.2
31+
dotnet add package LambdaTest.Selenium.Driver --version 1.0.2
3232
```
3333

3434
## License

0 commit comments

Comments
 (0)