Class Attachment

java.lang.Object
io.cucumber.messages.types.Attachment

public final class Attachment extends Object
Represents the Attachment message in Cucumber's message protocol

Attachments (parse errors, execution errors, screenshots, links...)

An attachment represents any kind of data associated with a line in a [Source](#io.cucumber.messages.Source) file. It can be used for:

* Syntax errors during parse time * Screenshots captured and attached during execution * Logs captured and attached during execution

It is not to be used for runtime errors raised/thrown during execution. This is captured in `TestResult`.

  • Constructor Details

  • Method Details

    • getBody

      public String getBody()
      The body of the attachment. If `contentEncoding` is `IDENTITY`, the attachment is simply the string. If it's `BASE64`, the string should be Base64 decoded to obtain the attachment.
    • getContentEncoding

      public AttachmentContentEncoding getContentEncoding()
      Whether to interpret `body` "as-is" (IDENTITY) or if it needs to be Base64-decoded (BASE64).

      Content encoding is *not* determined by the media type, but rather by the type of the object being attached:

      - string: IDENTITY - byte array: BASE64 - stream: BASE64

    • getFileName

      public Optional<String> getFileName()
      Suggested file name of the attachment. (Provided by the user as an argument to `attach`)
    • getMediaType

      public String getMediaType()
      The media type of the data. This can be any valid [IANA Media Type](https://www.iana.org/assignments/media-types/media-types.xhtml) as well as Cucumber-specific media types such as `text/x.cucumber.gherkin+plain` and `text/x.cucumber.stacktrace+plain`
    • getSource

      public Optional<Source> getSource()
    • getTestCaseStartedId

      public Optional<String> getTestCaseStartedId()
      The identifier of the test case attempt if the attachment was created during the execution of a test step
    • getTestStepId

      public Optional<String> getTestStepId()
      The identifier of the test step if the attachment was created during the execution of a test step
    • getUrl

      public Optional<String> getUrl()
      A URL where the attachment can be retrieved. This field should not be set by Cucumber. It should be set by a program that reads a message stream and does the following for each Attachment message:

      - Writes the body (after base64 decoding if necessary) to a new file. - Sets `body` and `contentEncoding` to `null` - Writes out the new attachment message

      This will result in a smaller message stream, which can improve performance and reduce bandwidth of message consumers. It also makes it easier to process and download attachments separately from reports.

    • getTestRunStartedId

      public Optional<String> getTestRunStartedId()
      Not used; implementers should instead populate `testRunHookStartedId` if an attachment was created during the execution of a test run hook
    • getTestRunHookStartedId

      public Optional<String> getTestRunHookStartedId()
      The identifier of the test run hook execution if the attachment was created during the execution of a test run hook
    • getTimestamp

      public Optional<Timestamp> getTimestamp()
      When the attachment was created
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object