Download Files in IE

Important

TestCafe 3.0 and up does not support Internet Explorer.

To download files in Internet Explorer, you need to manually process unskippable native dialogs.

IE popup

Consider the following markup:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form method="get" action="../src/file.txt">
        <button id="downloadButton" type="submit">Download!</button>
    </form>
</body>
</html>

This page includes a button that triggers a file download. To skip the native dialog in IE, and successfully download the file, use a RequestLogger:

import { RequestLogger } from 'testcafe';

const fileDownloadLogger = RequestLogger(new RegExp('src/file.txt'), {
    logResponseBody:       true,
    stringifyResponseBody: true,
});

fixture`Interact With the Page`
    .page`../pages/index.html`
    .requestHooks(fileDownloadLogger);

test('Download a file in IE and verify contents', async t => {
    await t
        .click('#downloadButton')
        .expect(fileDownloadLogger.contains(r => {
            console.log(r.response.body);
            return /File contents here/.test(r.response.body) && //verify response body
                   r.response.statusCode === 200; //verify response status code
        })).ok();
});

We know the location of the target file, so we can monitor requests to that file with a RequestLogger, and verify the response with a regular expression.

Note

Server responses are binary. Use the RequestLogger‘s stringifyResponseBody option to decode them.