Skip to content

Commit

Permalink
Merge branch 'main' into env-var-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-kerem committed May 16, 2024
2 parents 708707d + 0608956 commit b8d8246
Show file tree
Hide file tree
Showing 27 changed files with 1,000 additions and 88 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ This repository contains the SDKs for Sauce Labs Visual.

- [C#](./visual-dotnet)
- [Java](./visual-java)
- [Python](./visual-python)
8 changes: 4 additions & 4 deletions visual-dotnet/SauceLabs.Visual/BuildFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ private static async Task<VisualBuild> Create(VisualApi api, CreateBuildOptions
options.CustomId ??= EnvVars.CustomId;
var result = (await api.CreateBuild(new CreateBuildIn
{
Name = StringUtils.ValueOrDefault(EnvVars.BuildName, options.Name),
Project = StringUtils.ValueOrDefault(EnvVars.Project, options.Project),
Branch = StringUtils.ValueOrDefault(EnvVars.Branch, options.Branch),
DefaultBranch = StringUtils.ValueOrDefault(EnvVars.DefaultBranch, options.DefaultBranch),
Name = StringUtils.ValueOrDefault(options.Name, EnvVars.BuildName),
Project = StringUtils.ValueOrDefault(options.Project, EnvVars.Project),
Branch = StringUtils.ValueOrDefault(options.Branch, EnvVars.Branch),
DefaultBranch = StringUtils.ValueOrDefault(options.DefaultBranch, EnvVars.DefaultBranch),
CustomId = options.CustomId,
})).EnsureValidResponse();

Expand Down
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.3.1</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;
}
}
}
Loading

0 comments on commit b8d8246

Please sign in to comment.