wix / Detox

Gray box end-to-end testing and automation framework for mobile apps
https://wix.github.io/Detox/
MIT License
11.19k stars 1.92k forks source link

Option to overwrite artifacts if they exist #3311

Open SMJ93 opened 2 years ago

SMJ93 commented 2 years ago

Describe your idea

It would be great if we overwrite artifacts such as screenshots or videos by passing through a flag e.g. --overwrite-artifacts.

I've managed to get this working locally by adding the following patch to node_modules/detox/src/artifacts/templates/artifact/FileArtifact.js -> moveTemporaryFile method:

diff --git a/node_modules/detox/src/artifacts/templates/artifact/FileArtifact.js b/node_modules/detox/src/artifacts/templates/artifact/FileArtifact.js
index 7f07040..593662d 100644
--- a/node_modules/detox/src/artifacts/templates/artifact/FileArtifact.js
+++ b/node_modules/detox/src/artifacts/templates/artifact/FileArtifact.js
@@ -87,6 +87,12 @@ class FileArtifact extends Artifact {
       return true;
     }

+    if (await fs.exists(destination)) {
+      logger.debug({ event: 'MOVE_FILE_OVERWRITE' }, `moving "${source}" to ${destination}`);
+      await fs.move(source, destination, { overwrite: true });
+      return true;
+    }
+
     logger.warn({ event: 'MOVE_FILE_EXISTS' }, `cannot overwrite: "${source}" => "${destination}"`);
     await fs.remove(source);
     return false;

It checks if the file exists at the destination and then passes through the flag option overwrite: true to fs.move

noomorph commented 2 years ago

Could you explain your scenario a bit more? 🙏

SMJ93 commented 2 years ago

Hey @noomorph, sure.

I use Detox device.takeScreenshot to generate screenshots for my iOS and Android app:

I am currently uploading all 450 screenshots to the App Store and Google Play Store manually.

The plan is to automate the entire screenshot generation and upload process using Detox and fastlane deliver.

So I don't need to generate fresh screenshots each time I want to upload to the stores I commit the screenshots.

There are some scenarios where I want to overwrite these screenshots, for example a new design / feature. In this case I need the { overwrite: true } otherwise it fails at the following line:

     logger.warn({ event: 'MOVE_FILE_EXISTS' }, `cannot overwrite: "${source}" => "${destination}"`);
noomorph commented 2 years ago

Ah, hehe, interesting... I'll think. :)

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

stale[bot] commented 2 years ago

The issue has been closed for inactivity.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

stale[bot] commented 2 years ago

The issue has been closed for inactivity.