Skip to content

Commit c7dcb1b

Browse files
fix: Override getScreenshotAs to support the legacy base64 encoding (#1787)
1 parent b5c9e39 commit c7dcb1b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.openqa.selenium.Capabilities;
3232
import org.openqa.selenium.ImmutableCapabilities;
3333
import org.openqa.selenium.MutableCapabilities;
34+
import org.openqa.selenium.OutputType;
3435
import org.openqa.selenium.SessionNotCreatedException;
3536
import org.openqa.selenium.WebDriverException;
3637
import org.openqa.selenium.remote.CapabilityType;
@@ -270,4 +271,24 @@ public Response execute(String driverCommand, Map<String, ?> parameters) {
270271
public Response execute(String command) {
271272
return super.execute(command, Collections.emptyMap());
272273
}
274+
275+
@Override
276+
public <X> X getScreenshotAs(OutputType<X> outputType) {
277+
// TODO: Eventually we should not override this method.
278+
// TODO: Although, we have a legacy burden,
279+
// TODO: so it's impossible to do it the other way as of Oct 29 2022.
280+
// TODO: See https://github.com/SeleniumHQ/selenium/issues/11168
281+
return super.getScreenshotAs(new OutputType<X>() {
282+
@Override
283+
public X convertFromBase64Png(String base64Png) {
284+
String rfc4648Base64 = base64Png.replaceAll("\\r?\\n", "");
285+
return outputType.convertFromBase64Png(rfc4648Base64);
286+
}
287+
288+
@Override
289+
public X convertFromPngBytes(byte[] png) {
290+
return outputType.convertFromPngBytes(png);
291+
}
292+
});
293+
}
273294
}

0 commit comments

Comments
 (0)