-
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.
- Loading branch information
Showing
5 changed files
with
94 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using SauceLabs.Visual.GraphQL; | ||
using SauceLabs.Visual.Models; | ||
using SauceLabs.Visual.Utils; | ||
|
||
namespace SauceLabs.Visual | ||
{ | ||
public abstract class AbstractVisualClient | ||
{ | ||
protected readonly List<string> ScreenshotIds = new List<string>(); | ||
public bool CaptureDom { get; set; } = false; | ||
public BaselineOverride? BaselineOverride { get; set; } | ||
|
||
internal async Task<string> VisualCheckBaseAsync(VisualApi api, VisualBuild build, string name, | ||
VisualCheckOptions options, string jobId, string sessionId, string? sessionMetadataBlob) | ||
{ | ||
var ignoredRegions = | ||
IgnoredRegions.SplitIgnoredRegions(options.Regions, options.IgnoreRegions, options.IgnoreElements); | ||
|
||
FullPageConfigIn? fullPageConfigIn = null; | ||
if (options.FullPage == true) | ||
{ | ||
fullPageConfigIn = (options.FullPageConfig ?? new FullPageConfig()).ToFullPageConfigIn(); | ||
} | ||
|
||
var result = (await api.CreateSnapshotFromWebDriver(new CreateSnapshotFromWebDriverIn( | ||
buildUuid: build.Id, | ||
name: name, | ||
jobId: jobId, | ||
diffingMethod: options.DiffingMethod ?? DiffingMethod.Balanced, | ||
regions: ignoredRegions.RegionsIn, | ||
ignoredElements: ignoredRegions.ElementsIn, | ||
sessionId: sessionId, | ||
sessionMetadata: sessionMetadataBlob ?? "", | ||
captureDom: options.CaptureDom ?? CaptureDom, | ||
clipElement: options.ClipElement?.GetElementId(), | ||
suiteName: options.SuiteName, | ||
testName: options.TestName, | ||
fullPageConfig: fullPageConfigIn, | ||
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; | ||
} | ||
} | ||
} |
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
27 changes: 19 additions & 8 deletions
27
visual-dotnet/SauceLabs.Visual/Utils/DictionaryExtensions.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 |
---|---|---|
@@ -1,22 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SauceLabs.Visual.Utils | ||
{ | ||
internal static class DictionaryExtensions | ||
{ | ||
public static async Task<TValue> GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, Func<TKey, Task<TValue>> valueProvider) | ||
private static readonly SemaphoreSlim Semaphore = new SemaphoreSlim(1, 1); | ||
|
||
public static async Task<TValue> GetOrAddAsync<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key, Func<TKey, Task<TValue>> valueProvider) | ||
{ | ||
if (dict == null) throw new ArgumentNullException(nameof(dict)); | ||
if (key == null) throw new ArgumentNullException(nameof(key)); | ||
if (valueProvider == null) throw new ArgumentNullException(nameof(valueProvider)); | ||
await Semaphore.WaitAsync(); | ||
try | ||
{ | ||
if (dict == null) throw new ArgumentNullException(nameof(dict)); | ||
if (key == null) throw new ArgumentNullException(nameof(key)); | ||
if (valueProvider == null) throw new ArgumentNullException(nameof(valueProvider)); | ||
|
||
if (dict.TryGetValue(key, out var foundValue)) | ||
return foundValue; | ||
if (dict.TryGetValue(key, out var foundValue)) | ||
return foundValue; | ||
|
||
dict[key] = await valueProvider(key); | ||
return dict[key]; | ||
dict[key] = await valueProvider(key); | ||
return dict[key]; | ||
} | ||
finally | ||
{ | ||
Semaphore.Release(); | ||
} | ||
} | ||
} | ||
} |
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