allure-framework / allure-java

Allure integrations for Java test frameworks
Apache License 2.0
355 stars 224 forks source link

Added customization of source file name pattern #963

Closed ar4development closed 10 months ago

ar4development commented 1 year ago

Context

Currently the attachment filename pattern is hardcoded in AllureLifecycle#prepareAttachment method. Despite it if perfectly matches io.qameta.allure.AllureResultsWriter#write(java.lang.String, java.io.InputStream) specification in some cases we might need to customize the value.

For example: we have tests with numbers of steps where all those steps return same result. We do not want to keep different files for all those attachments since it overloads storage and network. So we would like to use some logic that would evaluate the attachment name depending on the content so that same content would be stored in the same file.

I understand that current implementation of io.qameta.allure.FileSystemResultsWriter does not allow to use attachment files with the same name. However I keep that out of the scope of current PR since I expect that whoever addressing the use case like mine would use their own writer which would be able to overwrite existing attachment files.

Checklist

CLAassistant commented 1 year ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Alexey Razgulyaev seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

baev commented 10 months ago

The attachments API is designed not to expose file names to end users. The reason is that there are so many other features that rely on the naming convention, for example, real-time reporting & attachment filtering features from Allure TestOps.

The recommended way to optimise the storage space is to post-process the results and remove/merge/override attachments by using the LifecycleListener extensions.

Hint: override io.qameta.allure.listener.TestLifecycleListener#beforeTestWrite, then iterate over TestResult and remove all the unnecessary attachment files