Skip to main content

Attachments (Screenshots) Guide

The Attachments feature allows you to add any file or screenshot to the test case logs. It can be useful for further test failure analysis.

An example of image attachment:

An example of file attachment:

How to log attachments (Screenshots) on Java agents?

Java agents have numerous methods to log attachments, the easiest one is calling ReportPortal#emitLog static method:

import com.epam.reportportal.listeners.LogLevel;
import com.epam.reportportal.service.ReportPortal;

import java.util.Date;
import java.io.File;

class Test {
public static void log(String message, File file) {
ReportPortal.emitLog(message, LogLevel.INFO.name(), new Date(), file);
}
}

If you don't want to put ReportPortal dependencies in your code, there is a way to pass attachments through your logger.

Check out our loggers' documentation:

How to log attachments (Screenshots) on Python agents?

To log attachments in Python you first need to configure a logger, depending on your current test framework. These are the instructions:

Then you can use common method to attach any files to logs which is described here.

How to log attachments (Screenshots) on JavaScript agents?

Attachment reports are supported by our client-javascript. The attachment file can be added as a part of a log request, see the link for details.

The implementation of attachments reporting varies from agent to agent.

agent-js-playwright: The attachment can be added via built-in playwright testInfo attachments or ReportingAPI.

agent-js-webdriverio: The attachment can be added via ReportingAPI, follow docs for details.

agent-js-testcafe: The attachment can be added via ReportingAPI, follow docs for details.

agent-js-codecept: The attachment can be added via ReportPortal plugin reportPortal.addLog, captured screenshots will be also attached to the report, see add-log-message.

agent-js-cucumber: The attachment can be added via this.attach Cucumber feature, captured screenshots will be also attached to the report, see attachments.

agent-js-cypress: The attachment can be added via ReportPortal logging custom commands for Cypress, see logging.

agent-js-mocha: The attachment can be added via PublicReportingAPI, follow docs for details.

agent-js-jasmine: The attachment can be added via PublicReportingAPI, follow docs for details.

agent-js-jest: There is no built-in capability to send attachments during test execution as the Jest Reporter works post-factum and does not allow to provide specific data to the report.

agent-js-postman: There is no built-in capability at the moment to send attachments during test execution due to the specifics of postman nature.

agent-js-nightwatch: The attachment can be added via ReportingAPI, follow docs for details.

An example for each agent can be found here.

How to log attachments (Screenshots) on .Net agents?

General documentation on this in .net-commons: https://github.com/reportportal/commons-net/blob/develop/docs/Logging.md

You can attach any binary content:

Context.Current.Log.Info("my binary", "image/png", bytes);
// where bytes is byte[] and image/png is mime type of content

Or use file instead:

Context.Current.Log.Info("my file", new FileInfo(filePath));
// where filePath is relative/absolute path to your file
// mime type is determined automatically