Skip to content
This repository has been archived by the owner on Jan 14, 2019. It is now read-only.

Attachments

Andrey Stolyarov edited this page Feb 24, 2016 · 13 revisions

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 cases

In 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.

Placeholders

Attachment name supports the same placeholders as steps do.