Skip to content

Commit

Permalink
[C#] Add baselineOverride functionality (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: Logan Graham <[email protected]>
  • Loading branch information
omacranger and Logan Graham authored Aug 16, 2024
1 parent 5d21606 commit b13b355
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 6 deletions.
37 changes: 37 additions & 0 deletions visual-dotnet/SauceLabs.Visual/BaselineOverride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using SauceLabs.Visual.GraphQL;
using SauceLabs.Visual.Models;

namespace SauceLabs.Visual
{
/// <summary>
/// <c>BaselineOverride</c> One or more values from 'SnapshotIn' we should use as an override
/// when finding a baseline. Enables cross browser / OS snapshot comparison by matching the
/// values set on the device you'd like to compare against.
/// </summary>
public class BaselineOverride
{
public Browser? Browser { get; set; }
public string? BrowserVersion { get; set; }
public string? Device { get; set; }
public string? Name { get; set; }
public OperatingSystem? OperatingSystem { get; set; }
public string? OperatingSystemVersion { get; set; }
public string? SuiteName { get; set; }
public string? TestName { get; set; }

internal BaselineOverrideIn ToBaselineOverrideIn()
{
return new BaselineOverrideIn()
{
Browser = Browser,
BrowserVersion = BrowserVersion,
Device = Device,
Name = Name,
OperatingSystem = OperatingSystem,
OperatingSystemVersion = OperatingSystemVersion,
SuiteName = SuiteName,
TestName = TestName,
};
}
}
}
3 changes: 0 additions & 3 deletions visual-dotnet/SauceLabs.Visual/CreateBuildOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using OpenQA.Selenium;
using SauceLabs.Visual.Models;

namespace SauceLabs.Visual
{

Expand Down
25 changes: 25 additions & 0 deletions visual-dotnet/SauceLabs.Visual/GraphQL/BaselineOverrideIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;
using SauceLabs.Visual.Models;

namespace SauceLabs.Visual.GraphQL
{
internal class BaselineOverrideIn
{
[JsonProperty("browser", NullValueHandling = NullValueHandling.Ignore)]
public Browser? Browser { get; set; }
[JsonProperty("browserVersion", NullValueHandling = NullValueHandling.Ignore)]
public string? BrowserVersion { get; set; }
[JsonProperty("device", NullValueHandling = NullValueHandling.Ignore)]
public string? Device { get; set; }
[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)]
public string? Name { get; set; }
[JsonProperty("operatingSystem", NullValueHandling = NullValueHandling.Ignore)]
public OperatingSystem? OperatingSystem { get; set; }
[JsonProperty("operatingSystemVersion", NullValueHandling = NullValueHandling.Ignore)]
public string? OperatingSystemVersion { get; set; }
[JsonProperty("suiteName", NullValueHandling = NullValueHandling.Ignore)]
public string? SuiteName { get; set; }
[JsonProperty("testName", NullValueHandling = NullValueHandling.Ignore)]
public string? TestName { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ internal class CreateSnapshotFromWebDriverIn
public string? TestName { get; set; }
[JsonProperty("captureDom")]
public bool? CaptureDom { get; set; }

[JsonProperty("baselineOverride")]
public BaselineOverrideIn? BaselineOverride { get; set; }
[JsonProperty("clipSelector")]
public string? ClipSelector { get; set; }
[JsonProperty("clipElement")]
Expand All @@ -52,7 +53,8 @@ public CreateSnapshotFromWebDriverIn(
string? testName,
ElementIn[]? ignoredElements,
FullPageConfigIn? fullPageConfig,
DiffingOptionsIn? diffingOptions
DiffingOptionsIn? diffingOptions,
BaselineOverrideIn? baselineOverride
)
{
BuildUuid = buildUuid;
Expand All @@ -70,6 +72,7 @@ public CreateSnapshotFromWebDriverIn(
TestName = testName;
FullPageConfig = fullPageConfig;
DiffingOptions = diffingOptions;
BaselineOverride = baselineOverride;
}
}
}
11 changes: 11 additions & 0 deletions visual-dotnet/SauceLabs.Visual/Models/Browser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace SauceLabs.Visual.Models
{
public enum Browser
{
Chrome,
Edge,
Firefox,
PlaywrightWebkit,
Safari,
}
}
11 changes: 11 additions & 0 deletions visual-dotnet/SauceLabs.Visual/Models/OperatingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace SauceLabs.Visual.Models
{
public enum OperatingSystem
{
Android,
Ios,
Linux,
Macos,
Windows,
}
}
5 changes: 5 additions & 0 deletions visual-dotnet/SauceLabs.Visual/VisualCheckOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class VisualCheckOptions
/// </summary>
public string? TestName { get; set; }

/// <summary>
/// <c>BaselineOverride</c> override the baseline matching behavior for the test.
/// </summary>
public BaselineOverride? BaselineOverride { get; set; }

private bool HasCompleteTestContext()
{
return string.IsNullOrEmpty(SuiteName) & !string.IsNullOrEmpty(TestName);
Expand Down
4 changes: 3 additions & 1 deletion visual-dotnet/SauceLabs.Visual/VisualClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class VisualClient : IDisposable
private readonly List<string> _screenshotIds = new List<string>();
public VisualBuild Build { get; private set; }
public bool CaptureDom { get; set; } = false;
public BaselineOverride? BaselineOverride { get; set; }
private readonly ResiliencePipeline _retryPipeline;

private string? _previousSuiteName = null;
Expand Down Expand Up @@ -183,7 +184,8 @@ private async Task<string> VisualCheckAsync(string name, VisualCheckOptions opti
suiteName: options.SuiteName,
testName: options.TestName,
fullPageConfig: fullPageConfigIn,
diffingOptions: options.DiffingOptions?.ToDiffingOptionsIn()
diffingOptions: options.DiffingOptions?.ToDiffingOptionsIn(),
baselineOverride: (options.BaselineOverride ?? BaselineOverride)?.ToBaselineOverrideIn()
))).EnsureValidResponse();
result.Result.Diffs.Nodes.ToList().ForEach(d => _screenshotIds.Add(d.Id));
return result.Result.Id;
Expand Down

0 comments on commit b13b355

Please sign in to comment.