Skip to content

Commit

Permalink
Fix null pointer while running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmay-browserstack committed Sep 28, 2024
1 parent e6006f8 commit cda5986
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/percy/selenium/Percy.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public JSONObject snapshot(String name, @Nullable List<Integer> widths, Integer
* @param scope A CSS selector to scope the screenshot to
*/
public JSONObject snapshot(String name, @Nullable List<Integer> widths, Integer minHeight, boolean enableJavaScript, String percyCSS, String scope) {
return snapshot(name, widths, minHeight, enableJavaScript, percyCSS, scope);
return snapshot(name, widths, minHeight, enableJavaScript, percyCSS, scope, null);
}

public JSONObject snapshot(String name, @Nullable List<Integer> widths, Integer minHeight, boolean enableJavaScript, String percyCSS, String scope, @Nullable Boolean sync) {
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/io/percy/selenium/SdkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ public void takeScreenshot() {
when(commandExecutor.getAddressOfRemoteServer()).thenReturn(new URL("https://hub-cloud.browserstack.com/wd/hub"));
} catch (Exception e) {
}
percy = spy(new Percy(mockedDriver));
percy.sessionType = "automate";
Percy mockedPercy = spy(new Percy(mockedDriver));
mockedPercy.sessionType = "automate";
when(mockedDriver.getSessionId()).thenReturn(new SessionId("123"));
when(mockedDriver.getCommandExecutor()).thenReturn(commandExecutor);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "Chrome");
when(mockedDriver.getCapabilities()).thenReturn(capabilities);
percy.screenshot("Test");
verify(percy).request(eq("/percy/automateScreenshot"), any(), eq("Test"));
mockedPercy.screenshot("Test");
verify(mockedPercy).request(eq("/percy/automateScreenshot"), any(), eq("Test"));
}

@Test
Expand All @@ -176,8 +176,8 @@ public void takeScreenshotWithOptions() {
when(commandExecutor.getAddressOfRemoteServer()).thenReturn(new URL("https://hub-cloud.browserstack.com/wd/hub"));
} catch (Exception e) {
}
percy = spy(new Percy(mockedDriver));
percy.sessionType = "automate";
Percy mockedPercy = spy(new Percy(mockedDriver));
mockedPercy.sessionType = "automate";
when(mockedDriver.getSessionId()).thenReturn(new SessionId("123"));
when(mockedDriver.getCommandExecutor()).thenReturn(commandExecutor);
DesiredCapabilities capabilities = new DesiredCapabilities();
Expand All @@ -189,8 +189,8 @@ public void takeScreenshotWithOptions() {
when(mockedElement.getId()).thenReturn("1234");
when(mockedConsiderElement.getId()).thenReturn("5678");
options.put("ignore_region_selenium_elements", Arrays.asList(mockedElement));
percy.screenshot("Test", options);
verify(percy).request(eq("/percy/automateScreenshot"), any() , eq("Test"));
mockedPercy.screenshot("Test", options);
verify(mockedPercy).request(eq("/percy/automateScreenshot"), any() , eq("Test"));
}

@Test
Expand All @@ -203,8 +203,8 @@ public void takeSnapshotThrowErrorForPOA() {
@Test
public void takeScreenshotThrowErrorForWeb() {
RemoteWebDriver mockedDriver = mock(RemoteWebDriver.class);
percy = spy(new Percy(mockedDriver));
Throwable exception = assertThrows(RuntimeException.class, () -> percy.screenshot("Test"));
Percy mockedPercy = spy(new Percy(mockedDriver));
Throwable exception = assertThrows(RuntimeException.class, () -> mockedPercy.screenshot("Test"));
assertEquals("Invalid function call - screenshot(). Please use snapshot() function for taking screenshot. screenshot() should be used only while using Percy with Automate. For more information on usage of snapshot(), refer doc for your language https://www.browserstack.com/docs/percy/integrate/overview", exception.getMessage());
}
}

0 comments on commit cda5986

Please sign in to comment.