Skip to content

Commit

Permalink
[java] Fix getScreenshotAs: avoid unnecessary conversions (#9308)
Browse files Browse the repository at this point in the history
* [java] Fix getScreenshotAs: avoid unnecessary conversions

* fix as per sonar comments
  • Loading branch information
alb-i986 authored Mar 22, 2021
1 parent cf3f36a commit 5004ca8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.openqa.selenium.remote.CapabilityType.LOGGING_PREFS;
import static org.openqa.selenium.remote.CapabilityType.PLATFORM;
Expand Down Expand Up @@ -358,8 +357,7 @@ public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException
String base64EncodedPng = (String) result;
return outputType.convertFromBase64Png(base64EncodedPng);
} else if (result instanceof byte[]) {
String base64EncodedPng = new String((byte[]) result, UTF_8);
return outputType.convertFromBase64Png(base64EncodedPng);
return outputType.convertFromPngBytes((byte[]) result);
} else {
throw new RuntimeException(String.format("Unexpected result for %s command: %s",
DriverCommand.SCREENSHOT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
import java.util.Map;
import java.util.stream.Collectors;

import static java.nio.charset.StandardCharsets.UTF_8;

public class RemoteWebElement implements WebElement, WrapsDriver, TakesScreenshot, Locatable {

private String foundBy;
Expand Down Expand Up @@ -376,8 +374,7 @@ public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException
String base64EncodedPng = (String) result;
return outputType.convertFromBase64Png(base64EncodedPng);
} else if (result instanceof byte[]) {
String base64EncodedPng = new String((byte[]) result, UTF_8);
return outputType.convertFromBase64Png(base64EncodedPng);
return outputType.convertFromPngBytes((byte[]) result);
} else {
throw new RuntimeException(String.format(
"Unexpected result for %s command: %s",
Expand Down

0 comments on commit 5004ca8

Please sign in to comment.