Skip to content

Latest commit

 

History

History

check-downloaded-file-name-and-content

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Check the Downloaded File Name and Content

Test Code: index.js

This example shows how to check the name and the content of a file downloaded during a test.

During the test, TestCafe clicks the link that triggers the file download. To confirm download completion and obtain the file name and content, a RequestLogger is attached to the test with the t.requestHooks method.

The RequestLogger.contains method, combined with the t.expect.ok method, verifies the downloaded file name and content.

The Request Logger is set up to log all successful GET requests to a specific URL. The responses are then filtered to only contain a .txt file with the specified content.

The Request Logger has the following options enabled:

Option Effect
logResponseHeaders logs the response header
logResponseBody logs the response body
stringifyResponseBody converts the response body to a string

The file name is read from the content-disposition response header. The response body is added to the file content.