An attachment in Java code is simply a method annotated with @Attachment that returns either a String or byte[], which should be added to the report:
@Attachment public String performedActions(ActionSequence actionSequence) { return actionSequence.toString(); } @Attachment(value = "Page screenshot", type = "image/png") public byte[] saveScreenshot(byte[] screenShot) { return screenShot; }
If a method annotated with @Attachment return type differs from String or byte[] we call toString() on return value to get attachment contents.
You can specify exact MIME type for each attached file using type parameter of @Attachment annotation like shown above. However there's no need to explicitly specify attachment type for all attached files as Allure by default analyses attachment contents and can determine attachment type automatically. You usually need to specify attachment type when working with plain text files.
Removing attachments for passed test casesIn order to economize free disk space, you can remove attachments if the corresponding test case passed. To do this, use the allure.report.remove.attachments
system property. Simply set this property somewhere in the test code to a PCRE regular expression, and Allure will remove any attachment with a name that matches this regular expression. For example, if your test saves a lot of PNG screenshots and you don't want to store them for passed cases, set the system property allure.report.remove.attachments=.*\.png
. To apply this setting globally, you can put a file named allure.properties
in your classpath. See AllureConfig for a list of existing properties.
Attachment name supports the same placeholders as steps do.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4