java-client
java-client copied to clipboard
Unable to push a zip file to my Android device
Description
I am trying to push a zip file of 900 MB size to my Android device.
Command:
driver.pushFile("/sdcard/Android/data/com.example.demoapp/files/file.zip", new File("C:\\Users\\rajdeep.dodiya\\resources\\apk\\file.zip"))
I am getting the below error:
uncaughtException: Invalid string length
RangeError: Invalid string length
at IncomingMessage.onData (C:\Users\rajdeep.dodiya\AppData\Roaming\npm\node_modules\appium\node_modules\raw-body\index.js:259:25)
at IncomingMessage.emit (node:events:527:28)
at addChunk (node:internal/streams/readable:315:12)
at readableAddChunk (node:internal/streams/readable:289:9)
at IncomingMessage.Readable.push (node:internal/streams/readable:228:10)
at HTTPParser.parserOnBody (node:_http_common:141:24)
[HTTP] <-- POST /session/12fb49f1-fe10-4ba8-b828-cefc939c5e8c/appium/device/push_file - - ms - -
[HTTP]
BadRequestError: request aborted
at IncomingMessage.onAborted (C:\Users\rajdeep.dodiya\AppData\Roaming\npm\node_modules\appium\node_modules\raw-body\index.js:238:10)
at IncomingMessage.emit (node:events:527:28)
at IncomingMessage._destroy (node:_http_incoming:179:10)
at _destroy (node:internal/streams/destroy:102:25)
at IncomingMessage.destroy (node:internal/streams/destroy:64:5)
at abortIncoming (node:_http_server:602:9)
at socketOnClose (node:_http_server:596:3)
at Socket.emit (node:events:539:35)
at TCP.<anonymous> (node:net:709:12)
ERROR: Error communicating with the remote browser. It may have died.
Build info: version: '4.7.0', revision: '0a5b49d16f'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '18'
Driver info: io.appium.java_client.android.AndroidDriver
Environment
* Java client build version: 8.3.0
* Appium server version:: 2.0.0-beta.52
* Node.js version: v16.15.1
* Mobile platform/version under test: API 33
* Real device or emulator/simulator: Real device
Any help? Is it because my file size is too big? I tried driver.pushFile() for a smaller zip file and it worked.
It definitely could be the file is too big. Selenium protocol requires all data to be transferred in JSON format. Probably, we are just hitting some internal memory limitations for storing such a long base64-encoded string
Any idea how I can by-pass this? We are automating a soon to go live app and the file size would be around 900 MB.
I opened a SO thread for possible work-arounds. https://stackoverflow.com/questions/75215539/appium-run-non-shell-adb-command
One possible solution would be to split the file, push separate parts and then merge it on the device
In order to split the binary on the client you could, for example, use split and then use adb shell cat on the device to merge the parts back into a single file: https://linuxhint.com/combine-binary-files-linux/
Is there any possibility of increasing the internal memory limitations to store the base64-encoded string?
I'd don't think this is possible. Node.js (V8) has a hardcoded string length limit as described in https://sgfault.com/post/2022/07/2022-07-20-node-mem-overflow/
Another work-around would be to execute a script.
This doc shows instructions how to run adb shell commands on Appium clients.
Do you know if we can run a non-shell adb command using this executeScript() method.