Although embedding inline screenshots and file downloads is easiest to do using either the Dashboard or CLI, it can all be done using the API directly. First you must upload the file's metadata to Rainforest, then upload the file to AWS, and finally, properly format the arguments to the step variable you intend on using (either file.screenshot or file.download).

Step 1: Uploading to Rainforest

Make a POST request using the following format:

URL:
https://app.rainforestqa.com/api/1/tests/[TEST ID]/files 

Headers:
CLIENT_TOKEN - Your API token found in integration settings. 

Body:

mime_type - Mime type of your file

size - size of your file in bytes

name - The name of your file and the extension. A file at ~/Applications/Documents/MyFile.txt would have the name MyFile.txt

digest (optional) - MD5 message digest for the file contents. This is used to verify whether the same file has been uploaded for this test before. To see which files have been uploaded for this test, make a GET request to this same URL.

A successful POST request will return the following parameters (in JSON):

file_id: Integer
file_signature
: String
aws_url:
String          
aws_key
: String        
aws_access_id
: String
aws_policy
: String
aws_acl
: String
aws_signature
: String

Step 2: Uploading to AWS

Using the information returned above, make a Multipart POST to AWS.

Note that, attributes that looks like response[file_id] reference the value returned from Rainforest in step 1.

URL:
response[aws_url]

Headers:
Content-Type = "multipart/form-data"

Form Data:

key - response[aws_key]

AWSAccessKeyID - response[aws_access_id]

acl - response[aws_acl]

policy - response[aws_policy]

signature - response[aws_signature]

Content-Type - Same as mime type above

file - Your file's contents

Step 3: Embedding your file

The final step is to manually write in your new variable in the desired step! For screenshots, use file.screenshot and for file downloads, use file.download.

file_id - The file_id attribute returned in step 1
signature
- The first 6 character of the file_signature attribute returned in step 1
file_name
- The name of your file and the extension. A file at ~/Applications/Documents/MyFile.txt would have the name MyFile.txt

  • Screenshots: {{ file.screenshot(file_id, signature) }}
  • Downloads: {{ file.screenshot(file_id, signature, file_name) }}

Did this answer your question?