class Cucumber::Messages::Attachment
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`.
Attributes
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.
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
Suggested file name of the attachment. (Provided by the user as an argument to âattach`)
The media type of the data. This can be any valid [IANA Media Type](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`
The identifier of the test case attempt if the attachment was created during the execution of a test step
The identifier of the test run hook execution if the attachment was created during the execution of a test run hook
Not used; implementers should instead populate âtestRunHookStartedId` if an attachment was created during the execution of a test run hook
The identifier of the test step if the attachment was created during the execution of a test step
When the attachment was created
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.
Deprecated; use ExternalAttachment instead.
Public Class Methods
Source
# File lib/cucumber/messages/attachment.rb, line 133 def self.from_h(hash) return nil if hash.nil? new( body: hash[:body], content_encoding: hash[:contentEncoding], file_name: hash[:fileName], media_type: hash[:mediaType], source: Source.from_h(hash[:source]), test_case_started_id: hash[:testCaseStartedId], test_step_id: hash[:testStepId], url: hash[:url], test_run_started_id: hash[:testRunStartedId], test_run_hook_started_id: hash[:testRunHookStartedId], timestamp: Timestamp.from_h(hash[:timestamp]) ) end
Returns a new Attachment from the given hash. If the hash keys are camelCased, they are properly assigned to the corresponding snake_cased attributes.
Cucumber::Messages::Attachment.from_h(some_hash) # => #<Cucumber::Messages::Attachment:0x... ...>
Source
# File lib/cucumber/messages/attachment.rb, line 99 def initialize( body: '', content_encoding: AttachmentContentEncoding::IDENTITY, file_name: nil, media_type: '', source: nil, test_case_started_id: nil, test_step_id: nil, url: nil, test_run_started_id: nil, test_run_hook_started_id: nil, timestamp: nil ) @body = body @content_encoding = content_encoding @file_name = file_name @media_type = media_type @source = source @test_case_started_id = test_case_started_id @test_step_id = test_step_id @url = url @test_run_started_id = test_run_started_id @test_run_hook_started_id = test_run_hook_started_id @timestamp = timestamp super() end