appium / appium-uiautomator2-driver

Appium driver for Android UIAutomator2
Apache License 2.0
607 stars 177 forks source link

APK file being deleted after appium completes test run #797

Closed camoles closed 5 months ago

camoles commented 5 months ago

I noticed the APK file is being deleted after a test is run. After lots of bisecting, I was able to find out that this behavior starts happening with appium-uiautomator2-driver version 3.5.3. With the exact same configurations and code elsewhere, the problem does not happen with version 3.5.2. Tested with appium version 2.10.3, which is the latest release at the time of this report. I also tested all more recent versions of appium-uiautomator2-driver up to the latest and confirmed that the bug remains. namely versions 3.5.4, 3.5.5 and 3.5.6 which is the latest available now.

I also tried removing permissions to delete the file, by putting the file in read-only directory. in that case, the file is not deleted (as it would not be possible to delete), but I also do not get any error nor see any breakage. While that is a possible work-around, ideally the source code would be fixed so that no files are being deleted that shouldn't.

I tried npm installing the versions 3.5.2 and 3.5.3, and then running diff -r between the two node_modules folder. My first attempt was to look for some newly inserted unlink call, but there was none that was changed nor inserted between the versions. So I guess the problem is happening in some logic that builds paths to be deleted, but without knowing the codebase it was a bit too much for me to bisect further. That will probably be much easier for someone more familiar with the code and dependencies. Please let me know if you have problems reproducing the bug. I am available to help further. Thank you for your attention.

KazuCocoa commented 5 months ago

Do you have the appium server log for it?

If the given capabilities had a relative path for apk, potentially https://github.com/appium/appium/issues/20188#issuecomment-2182080800 could be the related one. https://github.com/appium/appium/pull/20276 will fix it in the case.

Relevant diff for this.

https://www.npmjs.com/package/appium-uiautomator2-driver/v/3.5.3?activeTab=code

    "node_modules/@appium/base-driver": {
      "version": "9.9.0",
      "resolved": "https://registry.npmjs.org/@appium/base-driver/-/base-driver-9.9.0.tgz",
      "integrity": "sha512-8NxLExpq6jS5+vEQT7elEvJGvlScv5BqAOqf80QNO2dYL5dMpTLDWmUarBnX9uWU4MJ/jFrVjCoGZsEwZ2xOfg==",
      "dependencies": {
        "@appium/support": "^4.5.0",

https://www.npmjs.com/package/appium-uiautomator2-driver/v/3.5.2?activeTab=code

    "node_modules/@appium/base-driver": {
      "version": "9.6.0",
      "resolved": "https://registry.npmjs.org/@appium/base-driver/-/base-driver-9.6.0.tgz",
      "integrity": "sha512-8+pqWHQ4tbvtwOxNCtHa5m0SUwQIvAwHTVKq/YUbgDn18ep4nGhz5rlryvvqyNpXEgEOhbLInIRma1KIrYdX8Q==",
      "dependencies": {
        "@appium/support": "^4.2.5",
        "@appium/types": "^0.17.0",
        "@colors/colors": "1.6.0",
mykola-mokhnach commented 5 months ago

I assume you need to wait until the next version of @appium/base-driver gets published and picked up by the driver

camoles commented 5 months ago

Thanks @KazuCocoa, I am glad the bug is already known and has been fixed. In my case I am indeed using the ./file.apk format, so that is most likely what is happening. I will wait for the next release of uiautomator2-driver where the fix is incorporated. If you still have any value in the server log, I can produce one with the error, please just let me know. Otherwise, thank you all very much.