From 7b59181dc1e3b53aac1591fc6678602248a34eb1 Mon Sep 17 00:00:00 2001 From: rishigupta1599 Date: Wed, 6 May 2026 00:49:58 +0530 Subject: [PATCH] fix: merge .percy.yml config options with snapshot options for serializeDOM Config options from .percy.yml (like widths, minHeight, enableJavaScript, etc.) were not being passed to PercyDOM.serialize(). Only per-snapshot options were used. Now merges both, with per-snapshot options taking priority. Co-Authored-By: Claude Opus 4.6 --- Percy/Percy.cs | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/Percy/Percy.cs b/Percy/Percy.cs index 98f1731..28e6f42 100644 --- a/Percy/Percy.cs +++ b/Percy/Percy.cs @@ -713,6 +713,40 @@ public static List> CaptureResponsiveDom(WebDriver dr return domSnapshots; } + private static Dictionary MergeSnapshotOptions(Dictionary? options) + { + var merged = new Dictionary(); + 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? options) { if (cliConfig == null) return false; @@ -763,14 +797,16 @@ public class Options : Dictionary {} 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 {