Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenshots not working: Illegal base64 character a #1783

Closed
algernon28 opened this issue Oct 26, 2022 · 21 comments
Closed

Screenshots not working: Illegal base64 character a #1783

algernon28 opened this issue Oct 26, 2022 · 21 comments

Comments

@algernon28
Copy link

The problem

Whenever I try to take screenshots with Android driver, I get this error in my cucumber hook.
java.lang.IllegalArgumentException: Illegal base64 character a
at java.base/java.util.Base64$Decoder.decode0(Base64.java:847)
at java.base/java.util.Base64$Decoder.decode(Base64.java:566)
at java.base/java.util.Base64$Decoder.decode(Base64.java:589)
at org.openqa.selenium.OutputType$2.convertFromBase64Png(OutputType.java:58)
at org.openqa.selenium.OutputType$2.convertFromBase64Png(OutputType.java:55)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:335)
at com.watermelon.mobile.hooks.MobileHooks.takeScreenshot(MobileHooks.java:85)
at com.watermelon.mobile.hooks.MobileHooks.screenshot(MobileHooks.java:56)

Might be useful to say that I open the app with a deepLink https://.page.link/tggE

Environment

  • Appium version (or git revision) that exhibits the issue: both 1.22.3 and app 1.22.3-4
  • Last Appium version that did not exhibit the issue (if applicable):
  • Desktop OS/version used to run Appium: Windows 10
  • Node.js version (unless using Appium.app|exe):16.8.0 (but same problem with exe)
  • Npm or Yarn package manager:
  • Mobile platform/version under test: Appium client 8.2.0, selenium-support 4.5.0, testng 7.6.1, cucumber-java 7.8.1, cluecumber-report-plugin 2.9.3
  • Real device or emulator/simulator: emulator Android 12.0 x86_64 "Pixel 4", graphics: automatic, cold-boot. Chrome v. 91
  • Appium CLI or Appium.app|exe: 1.22.3-4

Details

If necessary, describe the problem you have been experiencing in more detail.

Link to Appium logs

https://gist.github.com/algernon28/6e067391b94026e3051abc0779774a3c

Code To Reproduce Issue [ Good To Have ]

Capabilities:
{
"platformName": "Android",
"appium:platformVersion": "12.0",
"appium:automationName": "UiAutomator2",
"appium:deviceName": "emulator-5554",
"appium:deviceOrientation": "portrait",
"appium:avd": "A12",
"appium:newCommandTimeout": "120",
"appium:browserName": "Chrome"
}

the app is installed thru a @before hook
@before(order = 1)
public void startUp() {
InteractsWithApps ad = ((InteractsWithApps) driver);
String appFile = System.getProperty(MobileConstants.OPTION_APPFILE);
String appID = System.getProperty(MobileConstants.OPTION_APPID);
if(driver.getCapabilities().getCapability("app") != null)
return;
if (!ad.isAppInstalled(appID)) {
ad.installApp(Paths.get(appFile).toAbsolutePath().toString());
} else {
ad.removeApp(appID);
ad.installApp(Paths.get(appFile).toAbsolutePath().toString());
}

}

I access the app with this code:
driver.get(deeplink url);
-- Deep link gets opened via Chrome
((AndroidDriver) driver).context("NATIVE_APP");
-- follows test code --

the screenshot is taken after each step
screenshot = driver.getScreenshotAs(OutputType.BYTES);
When debugging, it seems to fail where the driver tries to convert the png to base64

@mykola-mokhnach mykola-mokhnach transferred this issue from appium/appium Oct 26, 2022
@mykola-mokhnach
Copy link
Contributor

mykola-mokhnach commented Oct 26, 2022

This is happening because of SeleniumHQ/selenium#11168
Consider downgrading the selenium library to workaround the issue

@algernon28
Copy link
Author

algernon28 commented Oct 26, 2022

This is happening because of SeleniumHQ/selenium#11168 Consider downgrading the selenium library to workaround the issue

This is happening because of SeleniumHQ/selenium#11168 Consider downgrading the selenium library to workaround the issue

Thanks, I tried downgrading up to 4.0.0, but still same issue. I'd rather avoid to downgrade to Selenium 3.x alltogether, any other option?

@valfirst
Copy link
Collaborator

The issue is relevant for Selenium Java client 4.5.1 and higher (4.5.2 and 4.5.3 for the current moment). The issue is not reproduced for Selenium Java client 4.5.0 and less.

@algernon28
Copy link
Author

The issue is relevant for Selenium Java client 4.5.1 and higher (4.5.2 and 4.5.3 for the current moment). The issue is not reproduced for Selenium Java client 4.5.0 and less.

I'm sorry, but as I said, even with Selenium 4.0.0 I'm facing the same problem
I created another gist with the new Appium log:
https://gist.github.com/algernon28/6e067391b94026e3051abc0779774a3c

@algernon28
Copy link
Author

The issue is relevant for Selenium Java client 4.5.1 and higher (4.5.2 and 4.5.3 for the current moment). The issue is not reproduced for Selenium Java client 4.5.0 and less.

Right now I ran a dependency:tree on the pom, and it seems Appium java client still downloads selenium remote driver 4.5.3 as transitive dependency.
Below the whole tree of my project:

[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar (575 kB at 1.4 MB/s)
[INFO] testng-cucumber:watermelon:jar:0.0.1-SNAPSHOT
[INFO] +- org.testng:testng:jar:7.6.1:compile
[INFO] | +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] | +- com.beust:jcommander:jar:1.82:compile
[INFO] | - org.webjars:jquery:jar:3.6.0:runtime
[INFO] +- org.assertj:assertj-core:jar:3.23.1:compile
[INFO] | - net.bytebuddy:byte-buddy:jar:1.12.10:compile
[INFO] +- com.google.inject:guice:jar:5.1.0:compile
[INFO] | +- javax.inject:javax.inject:jar:1:compile
[INFO] | - aopalliance:aopalliance:jar:1.0:compile
[INFO] +- io.cucumber:cucumber-java:jar:7.8.1:compile
[INFO] | +- io.cucumber:cucumber-core:jar:7.8.1:compile
[INFO] | | +- io.cucumber:cucumber-gherkin:jar:7.8.1:compile
[INFO] | | +- io.cucumber:cucumber-gherkin-messages:jar:7.8.1:compile
[INFO] | | | - io.cucumber:gherkin:jar:24.0.0:compile
[INFO] | | +- io.cucumber:messages:jar:19.1.4:compile
[INFO] | | +- io.cucumber:tag-expressions:jar:4.1.0:compile
[INFO] | | +- io.cucumber:cucumber-expressions:jar:16.0.0:compile
[INFO] | | +- io.cucumber:datatable:jar:7.8.1:compile
[INFO] | | +- io.cucumber:cucumber-plugin:jar:7.8.1:compile
[INFO] | | +- io.cucumber:docstring:jar:7.8.1:compile
[INFO] | | +- io.cucumber:html-formatter:jar:20.1.0:compile
[INFO] | | - io.cucumber:ci-environment:jar:9.1.0:compile
[INFO] | - org.apiguardian:apiguardian-api:jar:1.1.2:compile
[INFO] +- io.cucumber:cucumber-testng:jar:7.8.1:compile
[INFO] +- io.cucumber:cucumber-guice:jar:7.8.1:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.24:provided
[INFO] +- org.yaml:snakeyaml:jar:1.33:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.36:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.2.11:compile
[INFO] | - ch.qos.logback:logback-core:jar:1.2.11:compile
[INFO] +- io.appium:java-client:jar:8.2.0:compile
[INFO] | +- org.seleniumhq.selenium:selenium-api:jar:4.5.3:compile (version selected from constraint [4.4.0,5.0))
[INFO] | +- org.seleniumhq.selenium:selenium-remote-driver:jar:4.5.3:compile (version selected from constraint [4.4.0,5.0))
[INFO] | | +- io.netty:netty-buffer:jar:4.1.84.Final:compile
[INFO] | | +- io.netty:netty-codec-http:jar:4.1.84.Final:compile
[INFO] | | | +- io.netty:netty-codec:jar:4.1.84.Final:compile
[INFO] | | | - io.netty:netty-handler:jar:4.1.84.Final:compile
[INFO] | | +- io.netty:netty-common:jar:4.1.84.Final:compile
[INFO] | | +- io.netty:netty-transport-classes-epoll:jar:4.1.84.Final:compile
[INFO] | | +- io.netty:netty-transport-classes-kqueue:jar:4.1.84.Final:compile
[INFO] | | +- io.netty:netty-transport-native-epoll:jar:4.1.84.Final:linux-x86_64
[INFO] | | +- io.netty:netty-transport-native-kqueue:jar:4.1.84.Final:osx-x86_64
[INFO] | | +- io.netty:netty-transport-native-unix-common:jar:4.1.84.Final:compile
[INFO] | | +- io.netty:netty-transport:jar:4.1.84.Final:compile
[INFO] | | | - io.netty:netty-resolver:jar:4.1.84.Final:compile
[INFO] | | +- io.opentelemetry:opentelemetry-api:jar:1.19.0:compile
[INFO] | | +- io.opentelemetry:opentelemetry-context:jar:1.19.0:compile
[INFO] | | +- io.opentelemetry:opentelemetry-exporter-logging:jar:1.19.0:compile
[INFO] | | | +- io.opentelemetry:opentelemetry-sdk-metrics:jar:1.19.0:compile
[INFO] | | | - io.opentelemetry:opentelemetry-sdk-logs:jar:1.19.0-alpha:compile
[INFO] | | | - io.opentelemetry:opentelemetry-api-logs:jar:1.19.0-alpha:compile
[INFO] | | +- io.opentelemetry:opentelemetry-sdk-common:jar:1.19.0:compile
[INFO] | | +- io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:jar:1.19.0:compile
[INFO] | | +- io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:jar:1.19.0-alpha:compile
[INFO] | | | - io.opentelemetry:opentelemetry-exporter-common:jar:1.19.0:runtime
[INFO] | | +- io.opentelemetry:opentelemetry-sdk-trace:jar:1.19.0:compile
[INFO] | | +- io.opentelemetry:opentelemetry-sdk:jar:1.19.0:compile
[INFO] | | +- io.opentelemetry:opentelemetry-semconv:jar:1.19.0-alpha:compile
[INFO] | | +- io.ous:jtoml:jar:2.0.0:compile
[INFO] | | +- org.apache.commons:commons-exec:jar:1.3:compile
[INFO] | | +- org.asynchttpclient:async-http-client:jar:2.12.3:compile
[INFO] | | | +- org.asynchttpclient:async-http-client-netty-utils:jar:2.12.3:compile
[INFO] | | | +- io.netty:netty-codec-socks:jar:4.1.60.Final:compile
[INFO] | | | +- io.netty:netty-handler-proxy:jar:4.1.60.Final:compile
[INFO] | | | +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.60.Final:compile
[INFO] | | | +- io.netty:netty-transport-native-kqueue:jar:osx-x86_64:4.1.60.Final:compile
[INFO] | | | +- org.reactivestreams:reactive-streams:jar:1.0.3:compile
[INFO] | | | +- com.typesafe.netty:netty-reactive-streams:jar:2.0.4:compile
[INFO] | | | - com.sun.activation:jakarta.activation:jar:1.2.2:compile
[INFO] | | - org.seleniumhq.selenium:selenium-http:jar:4.5.3:compile
[INFO] | | - dev.failsafe:failsafe:jar:3.3.0:compile
[INFO] | +- com.google.code.gson:gson:jar:2.9.1:compile
[INFO] | +- commons-codec:commons-codec:jar:1.15:compile
[INFO] | +- cglib:cglib:jar:3.3.0:runtime
[INFO] | | - org.ow2.asm:asm:jar:7.1:runtime
[INFO] | +- commons-validator:commons-validator:jar:1.7:runtime
[INFO] | | +- commons-beanutils:commons-beanutils:jar:1.9.4:runtime
[INFO] | | +- commons-digester:commons-digester:jar:2.1:runtime
[INFO] | | +- commons-logging:commons-logging:jar:1.2:runtime
[INFO] | | - commons-collections:commons-collections:jar:3.2.2:runtime
[INFO] | +- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] | - commons-io:commons-io:jar:2.11.0:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.13.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.13.3:compile
[INFO] | - com.fasterxml.jackson.core:jackson-annotations:jar:2.13.3:compile
[INFO] +- org.seleniumhq.selenium:selenium-support:jar:4.4.0:compile
[INFO] | +- com.google.auto.service:auto-service-annotations:jar:1.0.1:compile
[INFO] | +- com.google.auto.service:auto-service:jar:1.0.1:compile
[INFO] | | - com.google.auto:auto-common:jar:1.2:compile
[INFO] | +- com.google.guava:guava:jar:31.1-jre:compile
[INFO] | | +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] | | +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] | | +- org.checkerframework:checker-qual:jar:3.12.0:compile
[INFO] | | +- com.google.errorprone:error_prone_annotations:jar:2.11.0:compile
[INFO] | | - com.google.j2objc:j2objc-annotations:jar:1.3:compile
[INFO] | - org.seleniumhq.selenium:selenium-json:jar:4.4.0:compile
[INFO] - io.github.bonigarcia:webdrivermanager:jar:5.2.1:compile
[INFO] +- com.github.docker-java:docker-java:jar:3.2.13:compile
[INFO] | +- com.github.docker-java:docker-java-core:jar:3.2.13:compile
[INFO] | | +- com.github.docker-java:docker-java-api:jar:3.2.13:compile
[INFO] | | +- org.apache.commons:commons-compress:jar:1.21:compile
[INFO] | | - org.bouncycastle:bcpkix-jdk15on:jar:1.64:compile
[INFO] | | - org.bouncycastle:bcprov-jdk15on:jar:1.64:compile
[INFO] | - org.slf4j:jcl-over-slf4j:jar:1.7.30:compile
[INFO] +- com.github.docker-java:docker-java-transport-httpclient5:jar:3.2.13:compile
[INFO] | +- com.github.docker-java:docker-java-transport:jar:3.2.13:compile
[INFO] | - net.java.dev.jna:jna:jar:5.8.0:compile
[INFO] +- org.brotli:dec:jar:0.1.2:compile
[INFO] - org.apache.httpcomponents.client5:httpclient5:jar:5.1.3:compile
[INFO] +- org.apache.httpcomponents.core5:httpcore5:jar:5.1.3:compile
[INFO] - org.apache.httpcomponents.core5:httpcore5-h2:jar:5.1.3:compile

@valfirst
Copy link
Collaborator

@algernon28 just add explicit Selenium dependencies

@algernon28
Copy link
Author

@valfirst I added the two libraries to dependency management to resolve.
Things work now, I just wanted to point out that transitive dependency.

Thanks

@nvn27
Copy link

nvn27 commented Oct 28, 2022

Thanks @algernon28 , I was facing the same issue. This thread saved me :)

@ravibabu101143
Copy link

xplicit Selenium dependencies

I am also having same issue. Can you help how you resolved?

@algernon28
Copy link
Author

algernon28 commented Oct 28, 2022

xplicit Selenium dependencies

I am also having same issue. Can you help how you resolved?

Sure,
As I said i added the libraries to the dependency management of Maven.

Summarizing:

Make sure you have selenium not above 4.5.0

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>4.5.0</version>
        </dependency>
  • That won't suffice, since Appium java client brings in the latest selenium remotedriver as transitive dependency, so you use dependency management adding the following section to your pom.xml:
     <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-remote-driver</artifactId>
                <version>4.5.0</version>
            </dependency>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-api</artifactId>
                <version>4.5.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

That way you are making 4.5.0 explicit and your libraries will stick to those.

@ravibabu101143
Copy link

Thank you . It is working with above work around and it saved my day.

@kajalpal2021
Copy link

Hi,

I am facing java.lang.IllegalArgumentException: Illegal base64 character.

Environment details :

Appium version: 1.15.1,1.22.0
npm version : 8.19.2
node version- v16.18.0
Desktop OS/version used to run Appium: Mac version 12.6
Emulator : Pixel_2_API_33

Dependencies am using :

io.appium java-client 8.1.1 org.testng testng 6.14.3 ru.sbtqa.tag page-factory 1.3.0 org.seleniumhq.selenium selenium-support 4.5.0 com.aventstack extentreports 4.1.3 org.seleniumhq.selenium selenium-java 3.14.0 com.relevantcodes extentreports 2.41.2

I am facing below Exception while trying to capture screenshot on Test Failure:

[RemoteTestNG] detected TestNG version 7.4.0
FAILED CONFIGURATION: @AfterMethod tearDown([TestResult name=homePageVerificationTestCase status=FAILURE method=HomePageTest.homePageVerificationTestCase()[pri:0, instance:reifyhealth.HomePageTest@72cc7e6f] output={null}])
java.lang.IllegalArgumentException: Illegal base64 character a
at java.base/java.util.Base64$Decoder.decode0(Base64.java:847)
at java.base/java.util.Base64$Decoder.decode(Base64.java:566)
at java.base/java.util.Base64$Decoder.decode(Base64.java:589)
at org.openqa.selenium.OutputType$2.convertFromBase64Png(OutputType.java:58)
at org.openqa.selenium.OutputType$2.convertFromBase64Png(OutputType.java:55)
at org.openqa.selenium.OutputType$3.convertFromBase64Png(OutputType.java:78)
at org.openqa.selenium.OutputType$3.convertFromBase64Png(OutputType.java:75)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:335)
at utils.AppiumUtils.screenShot(AppiumUtils.java:28)
at reifyhealth.HomePageTest.tearDown(HomePageTest.java:32)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:700)
at org.testng.internal.TestInvoker.runAfterGroupsConfigurations(TestInvoker.java:676)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:660)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

@mykola-mokhnach mykola-mokhnach pinned this issue Nov 3, 2022
@ravibabu101143
Copy link

@kajalpal2021, Did you tried above work around suggested by @algernon28. It worked for me after excluding libraries in Appium java client dependency. Refer above two posts.

@Phoenix124
Copy link

@algernon28 I had the same problem
exclude selenium libs from appium and add selenium-java:4.3.0
for me worked
This is Selenium issue

@algernon28
Copy link
Author

@algernon28 I had the same problem
exclude selenium libs from appium and add selenium-java:4.3.0
for me worked
This is Selenium issue

No this is an Appium java client issue, as stated in the discussion.
For old drivers the problem involves selenium remotedriver 4.5+
Since Appium takes the latest version as transitive dependency, you have either to exclude them as you did (you can use up to 4.5), or enforce 4.5 as I said.
Both approaches work

@ashokreddy-k
Copy link

ashokreddy-k commented Nov 8, 2022

I have used the two methods.the error is gone but extent report is not generated.any suggestions?

@algernon28
Copy link
Author

algernon28 commented Nov 8, 2022 via email

@mykola-mokhnach
Copy link
Contributor

The issue has been addressed since v 8.2.1

mattonem added a commit to mattonem/testng-appium-app-browserstack that referenced this issue Dec 1, 2022
@pabloFuente
Copy link

pabloFuente commented Jan 9, 2023

Using Selenium 4.7.0 and io.appium:java-client 8.3.0, this issue is still present.

Just so you can see that there are no conflicts at all with the dependencies included with java-client:8.3.0, here it is a screenshot of my IDE dependency resolver. The selenium dependencies in use are those brought by java-client, and no others:

image

The error message when running this code ...

byte[] bytes = appiumDriver.findElement(AppiumBy.id("myId").getScreenshotAs(OutputType.BYTES);

... looks like this:

java.lang.IllegalArgumentException: Illegal base64 character a
	at java.base/java.util.Base64$Decoder.decode0(Base64.java:847)
	at java.base/java.util.Base64$Decoder.decode(Base64.java:566)
	at java.base/java.util.Base64$Decoder.decode(Base64.java:589)
	at org.openqa.selenium.OutputType$2.convertFromBase64Png(OutputType.java:58)
	at org.openqa.selenium.OutputType$2.convertFromBase64Png(OutputType.java:55)
	at org.openqa.selenium.remote.RemoteWebElement.getScreenshotAs(RemoteWebElement.java:395)
	at my.app.....

Edit
I got around this problem as best I could with the following code:

String base64 = appiumDriver.findElement(AppiumBy.id("myId")..getScreenshotAs(OutputType.BASE64);
base64 = base64.replaceAll("[\n\r]", "");
byte[] bytes = Base64.getDecoder().decode(base64);

@i-lovelife
Copy link

Using Selenium 4.7.0 and io.appium:java-client 8.3.0, this issue is still present.

Just so you can see that there are no conflicts at all with the dependencies included with java-client:8.3.0, here it is a screenshot of my IDE dependency resolver. The selenium dependencies in use are those brought by java-client, and no others:

image

The error message when running this code ...

byte[] bytes = appiumDriver.findElement(AppiumBy.id("myId").getScreenshotAs(OutputType.BYTES);

... looks like this:

java.lang.IllegalArgumentException: Illegal base64 character a
	at java.base/java.util.Base64$Decoder.decode0(Base64.java:847)
	at java.base/java.util.Base64$Decoder.decode(Base64.java:566)
	at java.base/java.util.Base64$Decoder.decode(Base64.java:589)
	at org.openqa.selenium.OutputType$2.convertFromBase64Png(OutputType.java:58)
	at org.openqa.selenium.OutputType$2.convertFromBase64Png(OutputType.java:55)
	at org.openqa.selenium.remote.RemoteWebElement.getScreenshotAs(RemoteWebElement.java:395)
	at my.app.....

Edit I got around this problem as best I could with the following code:

String base64 = appiumDriver.findElement(AppiumBy.id("myId")..getScreenshotAs(OutputType.BASE64);
base64 = base64.replaceAll("[\n\r]", "");
byte[] bytes = Base64.getDecoder().decode(base64);

I meet a similar issue, then I downgrade java-client version to 8.1.1 and it works

@martijnhjk
Copy link

@mykola-mokhnach latest comments suggests the issue still persists in 8.3.0, please advise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.