Skip to content
Open
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
44 changes: 40 additions & 4 deletions Percy/Percy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@
};
public class Region
{
public RegionElementSelector elementSelector { get; set; }

Check warning on line 210 in Percy/Percy.cs

View workflow job for this annotation

GitHub Actions / Test

Non-nullable property 'elementSelector' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public RegionPadding padding { get; set; }

Check warning on line 211 in Percy/Percy.cs

View workflow job for this annotation

GitHub Actions / Test

Non-nullable property 'padding' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string algorithm { get; set; }

Check warning on line 212 in Percy/Percy.cs

View workflow job for this annotation

GitHub Actions / Test

Non-nullable property 'algorithm' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public RegionConfiguration configuration { get; set; }

Check warning on line 213 in Percy/Percy.cs

View workflow job for this annotation

GitHub Actions / Test

Non-nullable property 'configuration' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public RegionAssertion assertion { get; set; }

Check warning on line 214 in Percy/Percy.cs

View workflow job for this annotation

GitHub Actions / Test

Non-nullable property 'assertion' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

// Rename the nested class to RegionElementSelector or another unique name
public class RegionElementSelector
Expand Down Expand Up @@ -713,6 +713,40 @@
return domSnapshots;
}

private static Dictionary<string, object> MergeSnapshotOptions(Dictionary<string, object>? options)
{
var merged = new Dictionary<string, object>();
if (cliConfig != null)
{
try
{
JsonElement config = (JsonElement)cliConfig;
if (config.TryGetProperty("snapshot", out JsonElement snapshotElement) &&
snapshotElement.ValueKind == JsonValueKind.Object)
{
foreach (JsonProperty prop in snapshotElement.EnumerateObject())
{
merged[prop.Name] = prop.Value.ValueKind switch
{
JsonValueKind.True => true,
JsonValueKind.False => false,
JsonValueKind.Number => prop.Value.TryGetInt32(out int intVal) ? intVal : (object)prop.Value.GetDouble(),
JsonValueKind.String => prop.Value.GetString(),
_ => prop.Value
};
}
}
}
catch (Exception) { }
}
if (options != null)
{
foreach (var kvp in options)
merged[kvp.Key] = kvp.Value;
}
return merged;
}

private static bool isResponsiveSnapshotCapture(Dictionary<string, object>? options)
{
if (cliConfig == null) return false;
Expand Down Expand Up @@ -763,14 +797,16 @@
if (_dom == null)
_dom = GetPercyDOM();

// Merge .percy.yml config options with snapshot options (snapshot options take priority)
var mergedOptions = MergeSnapshotOptions(options);

var cookies = driver.Manage().Cookies.AllCookies;
string opts = JsonSerializer.Serialize(options);
dynamic domSnapshot = null;

if (isResponsiveSnapshotCapture(options)) {
domSnapshot = CaptureResponsiveDom(driver, cookies, options);
if (isResponsiveSnapshotCapture(mergedOptions)) {
domSnapshot = CaptureResponsiveDom(driver, cookies, mergedOptions);
} else {
domSnapshot = getSerializedDom(driver, cookies, options, _dom);
domSnapshot = getSerializedDom(driver, cookies, mergedOptions, _dom);
}

Options snapshotOptions = new Options {
Expand Down
Loading