-
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.
Add Support for IWebElement natively (#81)
- Loading branch information
Showing
9 changed files
with
112 additions
and
8 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
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
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,29 @@ | ||
using Newtonsoft.Json; | ||
using OpenQA.Selenium; | ||
using SauceLabs.Visual.Models; | ||
using SauceLabs.Visual.Utils; | ||
|
||
namespace SauceLabs.Visual.GraphQL | ||
{ | ||
internal class ElementIn | ||
{ | ||
[JsonProperty("name")] | ||
public string? Name { get; } | ||
[JsonProperty("id")] | ||
public string Id { get; } | ||
|
||
[JsonProperty("diffingOptions")] | ||
public DiffingOptionsIn? DiffingOptions { get; } | ||
|
||
public ElementIn(IWebElement element, DiffingOptionsIn opts) : this(element, null, opts) | ||
{ | ||
} | ||
|
||
public ElementIn(IWebElement element, string? name = null, DiffingOptionsIn? diffingOptions = null) | ||
{ | ||
Id = element.GetElementId(); | ||
Name = name; | ||
DiffingOptions = diffingOptions; | ||
} | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
visual-dotnet/SauceLabs.Visual/Utils/IWebElementExtension.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,21 @@ | ||
using System.Reflection; | ||
using OpenQA.Selenium; | ||
|
||
namespace SauceLabs.Visual.Utils | ||
{ | ||
internal static class IWebElementExtension | ||
{ | ||
internal static string GetElementId(this IWebElement element) | ||
{ | ||
var bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; | ||
var field = element.GetType().GetField("elementId", bindingFlags); | ||
var id = (string?)field?.GetValue(element); | ||
|
||
if (id == null) | ||
{ | ||
throw new VisualClientException("Unable to retrieve Id from WebElement"); | ||
} | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using OpenQA.Selenium; | ||
using SauceLabs.Visual.GraphQL; | ||
using SauceLabs.Visual.Models; | ||
|
||
namespace SauceLabs.Visual.Utils | ||
{ | ||
internal class IgnoredRegions | ||
{ | ||
internal RegionIn[] RegionsIn; | ||
Check warning on line 11 in visual-dotnet/SauceLabs.Visual/Utils/IgnoredRegions.cs GitHub Actions / build
|
||
internal ElementIn[] ElementsIn; | ||
Check warning on line 12 in visual-dotnet/SauceLabs.Visual/Utils/IgnoredRegions.cs GitHub Actions / build
|
||
|
||
|
||
internal static IgnoredRegions SplitIgnoredRegions(SelectiveRegion[]? regions, IgnoreRegion[]? ignoreRegions, IWebElement[]? ignoreElements) | ||
{ | ||
var emptyRegions = regions?.Any(r => r.Region == null && r.Element == null); | ||
if (emptyRegions != null && emptyRegions != false) | ||
{ | ||
throw new VisualClientException("Some ignore regions have Element nor Region"); | ||
} | ||
|
||
var ignoredRegions = new List<RegionIn>(); | ||
ignoredRegions.AddRange(ignoreRegions?.Select(r => new RegionIn(r)) ?? new List<RegionIn>()); | ||
ignoredRegions.AddRange(regions?.Where(r => r.Region != null).Select(r => r.ToRegionIn()) ?? new List<RegionIn>()); | ||
|
||
var ignoredElements = new List<ElementIn>(); | ||
ignoredElements.AddRange(ignoreElements?.Select(elem => new ElementIn(elem)) ?? new List<ElementIn>()); | ||
ignoredElements.AddRange(regions?.Where(r => r.Element != null).Select(r => r.ToElementIn()) ?? new List<ElementIn>()); | ||
|
||
return new IgnoredRegions { RegionsIn = ignoredRegions.ToArray(), ElementsIn = ignoredElements.ToArray() }; | ||
} | ||
} | ||
} |
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