Skip to content

Commit

Permalink
Merge branch 'main' into migrate-js-clients
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-kerem committed May 16, 2024
2 parents a851bad + 0608956 commit b058188
Show file tree
Hide file tree
Showing 23 changed files with 945 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal class CreateSnapshotFromWebDriverIn
public string BuildUuid { get; }
[JsonProperty("diffingMethod")]
public DiffingMethod DiffingMethod { get; }
[JsonProperty("diffingOptions")]
public DiffingOptionsIn? DiffingOptions { get; set; }
[JsonProperty("ignoreRegions")]
public RegionIn[] IgnoreRegions { get; }
[JsonProperty("jobId")]
Expand Down Expand Up @@ -43,7 +45,8 @@ public CreateSnapshotFromWebDriverIn(
string? clipSelector,
string? suiteName,
string? testName,
FullPageConfigIn? fullPageConfig
FullPageConfigIn? fullPageConfig,
DiffingOptionsIn? diffingOptions
)
{
BuildUuid = buildUuid;
Expand All @@ -58,6 +61,7 @@ public CreateSnapshotFromWebDriverIn(
SuiteName = suiteName;
TestName = testName;
FullPageConfig = fullPageConfig;
DiffingOptions = diffingOptions;
}
}
}
30 changes: 30 additions & 0 deletions visual-dotnet/SauceLabs.Visual/GraphQL/DiffingOptionsIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Newtonsoft.Json;

namespace SauceLabs.Visual.GraphQL
{
public class DiffingOptionsIn
{
[JsonProperty("content")]
public bool Content { get; set; }
[JsonProperty("dimensions")]
public bool Dimensions { get; set; }
[JsonProperty("position")]
public bool Position { get; set; }
[JsonProperty("structure")]
public bool Structure { get; set; }
[JsonProperty("style")]
public bool Style { get; set; }
[JsonProperty("visual")]
public bool Visual { get; set; }

public DiffingOptionsIn(bool defaultValue)
{
Content = defaultValue;
Dimensions = defaultValue;
Position = defaultValue;
Structure = defaultValue;
Style = defaultValue;
Visual = defaultValue;
}
}
}
19 changes: 19 additions & 0 deletions visual-dotnet/SauceLabs.Visual/GraphQL/RegionIn.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using OpenQA.Selenium;
using SauceLabs.Visual.Models;
using SauceLabs.Visual.Utils;

namespace SauceLabs.Visual.GraphQL
{
Expand All @@ -16,6 +17,8 @@ internal class RegionIn
public int Width { get; }
[JsonProperty("height")]
public int Height { get; }
[JsonProperty("diffingOptions")]
public DiffingOptionsIn? DiffingOptions { get; }

public RegionIn(int x, int y, int width, int height)
{
Expand All @@ -29,10 +32,26 @@ public RegionIn(string name, int x, int y, int width, int height) : this(x, y, w
Name = name;
}

public RegionIn(int x, int y, int width, int height, DiffingOptionsIn diffingOptions) : this(x, y, width, height)
{
DiffingOptions = diffingOptions;
}
public RegionIn(IWebElement input) : this(input.Location.X, input.Location.Y, input.Size.Width, input.Size.Height)
{ }

public RegionIn(IWebElement input, DiffingOptionsIn? options) : this(input.Location.X, input.Location.Y,
input.Size.Width, input.Size.Height)
{
DiffingOptions = options;
}

public RegionIn(IgnoreRegion input) : this(input.X, input.Y, input.Width, input.Height)
{ }

public RegionIn(SauceLabs.Visual.Models.Region input, DiffingOptionsIn? options) : this(input.X, input.Y, input.Width,
input.Height)
{
DiffingOptions = options;
}
}
}
3 changes: 2 additions & 1 deletion visual-dotnet/SauceLabs.Visual/Models/DiffingMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace SauceLabs.Visual.Models
public enum DiffingMethod
{
Simple,
Experimental
Experimental,
Balanced,
}
}
16 changes: 16 additions & 0 deletions visual-dotnet/SauceLabs.Visual/Models/DiffingOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace SauceLabs.Visual.Models
{
[Flags]
public enum DiffingOption
{
None = 0,
Content = 1 << 0,
Dimensions = 1 << 1,
Position = 1 << 2,
Structure = 1 << 3,
Style = 1 << 4,
Visual = 1 << 5,
}
}
18 changes: 18 additions & 0 deletions visual-dotnet/SauceLabs.Visual/Models/Region.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace SauceLabs.Visual.Models
{
public class Region
{
public int X { get; }
public int Y { get; }
public int Width { get; }
public int Height { get; }

public Region(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
}
}
99 changes: 99 additions & 0 deletions visual-dotnet/SauceLabs.Visual/Models/SelectiveRegion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using OpenQA.Selenium;
using SauceLabs.Visual.GraphQL;
using SauceLabs.Visual.Utils;

namespace SauceLabs.Visual.Models
{
/// <summary>
/// SelectiveRegion describe a region where change kind can be filtered.
/// </summary>
[Obsolete("WARNING: This API is currently unstable. It may be changed at anytime")]
public class SelectiveRegion
{
internal Region? Region { get; }
internal IWebElement? Element { get; }

internal DiffingOption? EnableOnly { get; }
internal DiffingOption? DisableOnly { get; }

private SelectiveRegion(IWebElement element, DiffingOption? enableOnly, DiffingOption? disableOnly)
{
Element = element;
EnableOnly = enableOnly;
DisableOnly = disableOnly;
}

private SelectiveRegion(Region region, DiffingOption? enableOnly, DiffingOption? disableOnly)
{
Region = region;
EnableOnly = enableOnly;
DisableOnly = disableOnly;
}

[Obsolete("WARNING: This API is currently unstable. It may be changed at anytime")]
public static SelectiveRegion EnabledFor(IWebElement element)
{
return new SelectiveRegion(element, null, null);
}

[Obsolete("WARNING: This API is currently unstable. It may be changed at anytime")]
public static SelectiveRegion EnabledFor(IWebElement element, DiffingOption flags)
{
return new SelectiveRegion(element, flags, null);
}

[Obsolete("WARNING: This API is currently unstable. It may be changed at anytime")]
public static SelectiveRegion EnabledFor(Region region)
{
return new SelectiveRegion(region, DiffingOption.None, null);
}

[Obsolete("WARNING: This API is currently unstable. It may be changed at anytime")]
public static SelectiveRegion EnabledFor(Region region, DiffingOption flags)
{
return new SelectiveRegion(region, flags, null);
}

[Obsolete("WARNING: This API is currently unstable. It may be changed at anytime")]
public static SelectiveRegion DisabledFor(IWebElement element)
{
return new SelectiveRegion(element, null, DiffingOption.None);
}

[Obsolete("WARNING: This API is currently unstable. It may be changed at anytime")]
public static SelectiveRegion DisabledFor(IWebElement element, DiffingOption flags)
{
return new SelectiveRegion(element, null, flags);
}

[Obsolete("WARNING: This API is currently unstable. It may be changed at anytime")]
public static SelectiveRegion DisabledFor(Region region)
{
return new SelectiveRegion(region, null, DiffingOption.None);
}

[Obsolete("WARNING: This API is currently unstable. It may be changed at anytime")]
public static SelectiveRegion DisabledFor(Region region, DiffingOption flags)
{
return new SelectiveRegion(region, null, flags);
}

internal RegionIn ToRegionIn()
{
var diffingOptions = DiffingOptionsInHelper.CreateFromEnableOnlyDisable(EnableOnly, DisableOnly);
if (Region != null)
{
return new RegionIn(Region, diffingOptions);
}

if (Element != null)
{
return new RegionIn(Element, diffingOptions);
}

throw new VisualClientException("No Element nor Region has been passed");
}
}
}
2 changes: 1 addition & 1 deletion visual-dotnet/SauceLabs.Visual/SauceLabs.Visual.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<language>en-US</language>
<NeutralLanguage>en</NeutralLanguage>
<PackageId>SauceLabs.Visual</PackageId>
<Version>0.4.0</Version>
<Version>0.6.0</Version>
<Title>Sauce Labs Visual Binding</Title>
<PackageTags>saucelabs sauce labs visual testing screenshot capture dom</PackageTags>
<RepositoryUrl>https://github.com/saucelabs/visual-sdks</RepositoryUrl>
Expand Down
64 changes: 64 additions & 0 deletions visual-dotnet/SauceLabs.Visual/Utils/DiffingOptionsInHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using SauceLabs.Visual.GraphQL;
using SauceLabs.Visual.Models;

namespace SauceLabs.Visual.Utils
{
public static class DiffingOptionsInHelper
{
internal static DiffingOptionsIn SetOptions(DiffingOptionsIn opts, DiffingOption flags, bool value)
{
if (flags.HasFlag(DiffingOption.Content))
{
opts.Content = value;
}

if (flags.HasFlag(DiffingOption.Dimensions))
{
opts.Dimensions = value;
}

if (flags.HasFlag(DiffingOption.Position))
{
opts.Position = value;
}

if (flags.HasFlag(DiffingOption.Structure))
{
opts.Structure = value;
}

if (flags.HasFlag(DiffingOption.Style))
{
opts.Style = value;
}

if (flags.HasFlag(DiffingOption.Visual))
{
opts.Visual = value;
}

return opts;
}

internal static DiffingOptionsIn? CreateFromEnableOnlyDisable(DiffingOption? enableOnly, DiffingOption? disableOnly)
{
if (enableOnly.HasValue)
{
var options = new DiffingOptionsIn(false);
options = SetOptions(options, enableOnly.Value, true);
return options;
}

if (disableOnly.HasValue)
{
var options = new DiffingOptionsIn(true);
options = SetOptions(options, disableOnly.Value, false);
return options;
}

return null;
}
}
}
59 changes: 59 additions & 0 deletions visual-dotnet/SauceLabs.Visual/VisualCheckDiffingOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Diagnostics;
using System.Linq;
using OpenQA.Selenium;
using SauceLabs.Visual.GraphQL;
using SauceLabs.Visual.Models;
using SauceLabs.Visual.Utils;

namespace SauceLabs.Visual
{
public class VisualCheckDiffingOptions
{
private enum DiffingOptionMode
{
EnableOnly,
DisableOnly
}

private readonly DiffingOptionMode _mode;
private readonly DiffingOption _flags;

private VisualCheckDiffingOptions(DiffingOptionMode mode, DiffingOption flags)
{
_mode = mode;
_flags = flags;
}

/// <summary>
/// <c>EnableOnly</c> sets which change types to check for.
/// Compatible only with <c>DiffingMethod.Balanced</c>
/// </summary>
public static VisualCheckDiffingOptions EnableOnly(DiffingOption flags)
{
return new VisualCheckDiffingOptions(DiffingOptionMode.EnableOnly, flags);
}

/// <summary>
/// <c>DisableOnly</c> sets which change types to ignore.
/// Compatible only with <c>DiffingMethod.Balanced</c>
/// </summary>
public static VisualCheckDiffingOptions DisableOnly(DiffingOption flags)
{
return new VisualCheckDiffingOptions(DiffingOptionMode.DisableOnly, flags);
}

internal DiffingOptionsIn ToDiffingOptionsIn()
{
DiffingOptionsIn options;
if (_mode == DiffingOptionMode.EnableOnly)
{
options = DiffingOptionsInHelper.SetOptions(new DiffingOptionsIn(false), _flags, true);
}
else
{
options = DiffingOptionsInHelper.SetOptions(new DiffingOptionsIn(true), _flags, false);
}
return options;
}
}
}
Loading

0 comments on commit b058188

Please sign in to comment.