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

getScreenshotAs as BASE64 produces string with new line characters #14684

Closed
pashidlos opened this issue Aug 27, 2020 · 5 comments
Closed

getScreenshotAs as BASE64 produces string with new line characters #14684

pashidlos opened this issue Aug 27, 2020 · 5 comments

Comments

@pashidlos
Copy link

pashidlos commented Aug 27, 2020

The problem

String generated by getScreenshotAs method is not valid base64 string

((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64)

Environment

  • Appium version (or git revision) that exhibits the issue: 1.18.1
  • Last Appium version that did not exhibit the issue (if applicable): don't know (
  • Desktop OS/version used to run Appium: iOS Catalina 10.15.6
  • Node.js version (unless using Appium.app|exe): 12.18.1
  • Npm or Yarn package manager: npm
  • Mobile platform/version under test: iOS
  • Real device or emulator/simulator: emulator
  • Appium CLI or Appium.app|exe: Appium CLI

Details

1

Code To Reproduce Issue [ Good To Have ]

https://github.com/pashidlos/appium-issue-14684/blob/master/src/test/java/TestExample.java

@pashidlos pashidlos changed the title e getScreenshotAs as BASE64 produces string with new line characters Aug 27, 2020
@KazuCocoa
Copy link
Member

KazuCocoa commented Aug 28, 2020

The format is valid for format like RFC 2045, while RFC 4648 is not.
(Ruby also has two methods to encode base64. One is encode64 and another is strict_encode64. The former is rfc 2045 compatible style)

Appium encodes data to base64 string with Buffer.from(data, 'base64')
https://nodejs.org/api/buffer.html
It seems it has new line per 64 characters.

I'm not sure the exact reason why they keep the style, but maybe some historical reasons to keep the compatibility of older stuff. Thus, it is reasonable to keep current format for me.
https://stackoverflow.com/questions/19952621/is-it-ok-to-remove-newline-in-base64-encoding/20065991#20065991

@pashidlos
Copy link
Author

thanks for quick response

@szprutamich
Copy link

How comes it's not a bug, while

      <groupId>io.appium</groupId>
      <artifactId>java-client</artifactId>

has a dependency to selenium libs and org.openqa.selenium.OutputType uses Base64.getDecoder().decode(base64Png) which basically fails for RFC 2045 and Base64.getMimeDecoder().decode(base64Png) would work.
The format should be changed to RFC 4648 if you use a lib which requires it.

@valfirst
Copy link

valfirst commented Oct 24, 2022

Selenium Java client follows RFC4648 starting from 4.5.1: SeleniumHQ/selenium#11107 (I'm not sure about other clients). Is it something to be handled on Appium server side? Or Appium Java client side?

@KazuCocoa
Copy link
Member

KazuCocoa commented Oct 25, 2022

Could you create an issue in the Java client?
We maybe update server side to not have \n but potentially old Android/chrome (for example) needs the old one. WinAppDriver, for example, as well. So, at least Appium client may need to keep the old one still.

[append]
https://github.com/appium/WebDriverAgent/search?q=base64EncodedStringWithOptions it seems like... the method in appium/WDA was fastest in 10 times average in each options on my local. (0.01 or less tho). Hm..

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

No branches or pull requests

5 participants