[SOLVED] Appium 1.5.2 will not download Android application on subsequent sessions

Hi all,

As the title states, I’m having trouble getting Appium 1.5.2 to download an Android APK if the APK is given through an HTTP URL in the desired capabilities. I do not know what’s going on, but here are my machine specifications. I have 2 virtual machines with the following details:

CentOS 7
npm 3.8.6
node v5.11.0
Appium 1.5.2
Selenium Grid 2.53.0

The Grid Hub is running on one VM, and Appium is running as a node on a separate VM. Both VMS are on the same machine.

Here are my observations. When the /tmp directory of the Appium node VM does not hold another subdirectory generated by previous sessions of Appium (e.g. after I delete all of Appium’s /tmp files), then Appium will happily download, install, and run the application on my device. However, if I try to run this test again, Appium will again attempt to download the APK, but it will fail with the following message:

[JSONWP] Encountered internal error running command: Error: Problem downloading app from
url http://[REDACTED]/redacted.apk: Error: ENOENT: no
such file or directory, open '/tmp/2016325-2137-5kr6v8/appium-app.apk' at downloadApp$
(lib/helpers.js:59

Any ideas what’s going on?

I made additional observations and investigations. I believe this is a race condition in Appium that can more easily appear on machines with relatively low memory. My virtual machines are allocated 256 MiB each.

When I encountered this bug for the first time, my Selenium hub VM was also running an Appium node, and it was allocated 384 MiB. However, this beefier VM never ran into this bug. My guess for why this is the case is that the additional memory allowed the Linux kernel to more efficiently cache the filesystem and filesystem operations, so Appium was less likely to “miss” the temporary directory.

I’ve posted an issue report for this bug on Github: https://github.com/appium/appium-support/issues/38

My suggested workaround for now is to add the “await” keyword to the fs.mkdir(filePath) line referenced in the issue, and then re-transpile the updated Javascript code.

The fix is added in to the upstream project. If you are running into this issue and you would like to use Appium without running from source yourself, you can uninstall and reinstall Appium. It should pull in the updated package with the fix. e.g.

# npm uninstall -g appium
# npm install -g --no-shrinkwrap [email protected]

If you’re running from source, you can do something similar in the Appium’s root directory (assuming you’re on 1.5.2, or some recent branch):

$ rm -rf node_modules
$ npm install --no-shrinkwrap