diff --git a/java/src/org/openqa/selenium/OutputType.java b/java/src/org/openqa/selenium/OutputType.java index 9640f5fd74c7b..099869cd6e390 100644 --- a/java/src/org/openqa/selenium/OutputType.java +++ b/java/src/org/openqa/selenium/OutputType.java @@ -55,7 +55,13 @@ public String toString() { OutputType BYTES = new OutputType() { @Override public byte[] convertFromBase64Png(String base64Png) { - return Base64.getDecoder().decode(base64Png); + + // https://github.com/SeleniumHQ/selenium/issues/11168: + // Workaround for drivers non-compliant with RFC4648 (e.g. Appium). + // To be removed in future in order to meet W3C WebDriver spec requirements. + String rfc4648CompliantBase64Png = base64Png.replaceAll("\r?\n", ""); + + return Base64.getDecoder().decode(rfc4648CompliantBase64Png); } @Override diff --git a/java/test/org/openqa/selenium/OutputTypeTest.java b/java/test/org/openqa/selenium/OutputTypeTest.java index f0b3b3b88697e..108e32a28e5d6 100644 --- a/java/test/org/openqa/selenium/OutputTypeTest.java +++ b/java/test/org/openqa/selenium/OutputTypeTest.java @@ -44,6 +44,17 @@ void testBytes() { } } + @Test + void testBytesWorkaround() { + // https://github.com/SeleniumHQ/selenium/issues/11168 + byte[] bytes = OutputType.BYTES + .convertFromBase64Png("ABA\r\nDA\nB\r\n\r\nAD\r\n"); + assertThat(bytes).hasSameSizeAs(TEST_BYTES); + for (int i = 0; i < TEST_BYTES.length; i++) { + assertThat(TEST_BYTES[i]).as("index " + i).isEqualTo(bytes[i]); + } + } + @Test void testFiles() { File tmpFile = OutputType.FILE.convertFromBase64Png(TEST_BASE64);