Skip to content
Open
Changes from 3 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
25 changes: 22 additions & 3 deletions src/main/java/io/percy/selenium/Percy.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,25 @@ public JSONObject snapshot(String name, Map<String, Object> options) {

Object domSnapshot = null;

// Merge .percy.yml config options with snapshot options (snapshot options take priority)
Map<String, Object> mergedOptions = new HashMap<>();
if (cliConfig != null && cliConfig.has("snapshot") && !cliConfig.isNull("snapshot")) {
JSONObject snapshotConfig = cliConfig.getJSONObject("snapshot");
for (String key : snapshotConfig.keySet()) {
mergedOptions.put(key, snapshotConfig.get(key));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Low] Config-supplied widths becomes a JSONArray, not a List

snapshotConfig.get(key) returns org.json native types. A widths array from .percy.yml is copied into mergedOptions as a JSONArray; Java-side consumers that branch on instanceof List would silently ignore it (the serialize/POST new JSONObject(options) path is unaffected).

Suggestion: convert JSONArray values to List when copying, or add a test confirming config-supplied widths flow through.

Reviewer: stack:code-review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium] Config values land in mergedOptions as raw org.json types

snapshotConfig.get(key) puts JSONObject/JSONArray instances into mergedOptions. buildSnapshotJS re-wraps via new JSONObject(options) so serialization is fine, but extractResponsiveWidths checks instanceof List<?> and resolveReadinessConfig checks instanceof Map — a widths/readiness value sourced from .percy.yml would be a JSONArray/JSONObject and silently miss those branches.

Suggestion: Seed from fully-unwrapped Java types, e.g. mergedOptions.putAll(snapshotConfig.toMap());

Reviewer: stack:code-reviewer

}
}
if (options != null) {
// Only overlay non-null per-call options so a null value (set by the
// positional snapshot() overloads for unset params) does not clobber a
// real value coming from .percy.yml config.
for (Map.Entry<String, Object> entry : options.entrySet()) {
if (entry.getValue() != null) {
mergedOptions.put(entry.getKey(), entry.getValue());
}
}
}

try {
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript(fetchPercyDOM());
Expand All @@ -383,10 +402,10 @@ public JSONObject snapshot(String name, Map<String, Object> options) {
} catch(Exception e) {
log("Cookie collection failed " + e.getMessage(), "debug");
}
if (isCaptureResponsiveDOM(options)) {
domSnapshot = captureResponsiveDom(driver, cookies, options);
if (isCaptureResponsiveDOM(mergedOptions)) {
domSnapshot = captureResponsiveDom(driver, cookies, mergedOptions);
} else {
domSnapshot = getSerializedDOM(jse, cookies, options);
domSnapshot = getSerializedDOM(jse, cookies, mergedOptions);
}
} catch (WebDriverException e) {
// For some reason, the execution in the browser failed.
Expand Down
Loading