-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into migrate-js-clients
- Loading branch information
Showing
23 changed files
with
945 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
visual-dotnet/SauceLabs.Visual/GraphQL/DiffingOptionsIn.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ namespace SauceLabs.Visual.Models | |
public enum DiffingMethod | ||
{ | ||
Simple, | ||
Experimental | ||
Experimental, | ||
Balanced, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
visual-dotnet/SauceLabs.Visual/Utils/DiffingOptionsInHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
59
visual-dotnet/SauceLabs.Visual/VisualCheckDiffingOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.