Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET: Enhance VisualCheckOptions #45

Merged
merged 5 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SauceLabs.Visual.Utils
{
public static class DiffingOptionsInHelper
{
private static DiffingOptionsIn SetOptions(DiffingOptionsIn opts, DiffingOption flags, bool value)
internal static DiffingOptionsIn SetOptions(DiffingOptionsIn opts, DiffingOption flags, bool value)
{
if (flags.HasFlag(DiffingOption.Content))
{
Expand Down
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)
FriggaHel marked this conversation as resolved.
Show resolved Hide resolved
{
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;
}
}
}
9 changes: 2 additions & 7 deletions visual-dotnet/SauceLabs.Visual/VisualCheckOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@
public string? ClipSelector { get; set; }

/// <summary>
/// <c>EnableOnly</c> allows to specify which changes to consider globaly.
/// <c>DiffingOptions</c> set which kind of changes should be considered.
/// </summary>
public DiffingOption? EnableOnly { get; set; }

/// <summary>
/// <c>Disable</c> allows to specify which changes to ignore globally.
/// </summary>
public DiffingOption? DisableOnly { get; set; }
public VisualCheckDiffingOptions? DiffingOptions { get; set; }

/// <summary>
/// <c>Regions</c> allows to specify what kind of checks needs to be done in a specific region.
/// </summary>
public SelectiveRegion[]? Regions { get; set; }

Check warning on line 30 in visual-dotnet/SauceLabs.Visual/VisualCheckOptions.cs

View workflow job for this annotation

GitHub Actions / build

'SelectiveRegion' is obsolete: 'WARNING: This API is currently unstable. It may be changed at anytime'

Check warning on line 30 in visual-dotnet/SauceLabs.Visual/VisualCheckOptions.cs

View workflow job for this annotation

GitHub Actions / build

'SelectiveRegion' is obsolete: 'WARNING: This API is currently unstable. It may be changed at anytime'

Check warning on line 30 in visual-dotnet/SauceLabs.Visual/VisualCheckOptions.cs

View workflow job for this annotation

GitHub Actions / build

'SelectiveRegion' is obsolete: 'WARNING: This API is currently unstable. It may be changed at anytime'

Check warning on line 30 in visual-dotnet/SauceLabs.Visual/VisualCheckOptions.cs

View workflow job for this annotation

GitHub Actions / build

'SelectiveRegion' is obsolete: 'WARNING: This API is currently unstable. It may be changed at anytime'

/// <summary>
/// <c>SuiteName</c> manually set the SuiteName of the Test.
Expand Down
2 changes: 1 addition & 1 deletion visual-dotnet/SauceLabs.Visual/VisualClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
/// <param name="region">the Sauce Labs region to connect to</param>
/// <param name="username">the Sauce Labs username</param>
/// <param name="accessKey">the Sauce Labs access key</param>
private VisualClient(WebDriver wd, Region region, string username, string accessKey)

Check warning on line 95 in visual-dotnet/SauceLabs.Visual/VisualClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Build' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 95 in visual-dotnet/SauceLabs.Visual/VisualClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Build' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 95 in visual-dotnet/SauceLabs.Visual/VisualClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Build' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 95 in visual-dotnet/SauceLabs.Visual/VisualClient.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Build' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
{
if (StringUtils.IsNullOrEmpty(username) || StringUtils.IsNullOrEmpty(accessKey))
{
Expand Down Expand Up @@ -165,7 +165,7 @@
suiteName: options.SuiteName,
testName: options.TestName,
fullPageConfig: fullPageConfigIn,
diffingOptions: DiffingOptionsInHelper.CreateFromEnableOnlyDisable(options.EnableOnly, options.DisableOnly)
diffingOptions: options.DiffingOptions?.ToDiffingOptionsIn()
))).EnsureValidResponse();
result.Result.Diffs.Nodes.ToList().ForEach(d => _screenshotIds.Add(d.Id));
return result.Result.Id;
Expand Down