From 2901097d2ffc02186224781af3599cf149493f0f Mon Sep 17 00:00:00 2001 From: Chinmay Maheshwari Date: Sun, 29 Sep 2024 01:15:14 +0530 Subject: [PATCH] Fix for null pointer errors --- src/main/java/io/percy/selenium/Percy.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/percy/selenium/Percy.java b/src/main/java/io/percy/selenium/Percy.java index 457973c..e765b23 100644 --- a/src/main/java/io/percy/selenium/Percy.java +++ b/src/main/java/io/percy/selenium/Percy.java @@ -180,6 +180,7 @@ private boolean isCaptureResponsiveDOM(Map options) { } boolean responsiveSnapshotCaptureCLI = false; + if (eligibleWidths == null) { return false; } if (CLIconfig.getJSONObject("snapshot").has("responsiveSnapshotCapture")) { responsiveSnapshotCaptureCLI = CLIconfig.getJSONObject("snapshot").getBoolean("responsiveSnapshotCapture"); } @@ -192,7 +193,7 @@ public JSONObject snapshot(String name, Map options) { if (!isPercyEnabled) { return null; } if ("automate".equals(sessionType)) { throw new RuntimeException("Invalid function call - snapshot(). Please use screenshot() function while using Percy with Automate. For more information on usage of PercyScreenshot, refer https://www.browserstack.com/docs/percy/integrate/functional-and-visual"); } - List> domSnapshot = new ArrayList<>(); + Object domSnapshot = null; try { JavascriptExecutor jse = (JavascriptExecutor) driver; @@ -206,7 +207,7 @@ public JSONObject snapshot(String name, Map options) { if (isCaptureResponsiveDOM(options)) { domSnapshot = captureResponsiveDom(driver, cookies, options); } else { - domSnapshot.add(getSerializedDOM(jse, cookies, options)); + domSnapshot = getSerializedDOM(jse, cookies, options); } } catch (WebDriverException e) { // For some reason, the execution in the browser failed. @@ -373,7 +374,7 @@ private String fetchPercyDOM() { * @param percyCSS Percy specific CSS that is only applied in Percy's browsers */ private JSONObject postSnapshot( - List> domSnapshot, + Object domSnapshot, String name, String url, Map options