Benas.S
Benas.S

Reputation: 45

How to check downloaded file name?

I wrote a test that downloads the export file, but I also need to send this file through email. The problem is that filename is always different and I don't know how to look it up during the test.

Upvotes: 1

Views: 762

Answers (1)

mlosev
mlosev

Reputation: 5227

You can retrieve the dynamic downloaded filename from the 'content-disposition' header.

import { Selector, RequestLogger } from 'testcafe';

const url = 'https://demos.devexpress.com/ASPxGridViewDemos/Exporting/Exporting.aspx';

const logger = RequestLogger({ url, method: 'post' }, {
    logResponseHeaders: true
});

fixture `Export`
    .page(url)
    .requestHooks(logger);

test('export to csv', async t => {
    const exportToCSVButton = Selector('span').withText('Export to CSV');

    await t
        .click(exportToCSVButton)
        .expect(logger.contains(r => r.response.statusCode === 200)).ok();

    console.log(logger.requests[0].response.headers['content-disposition']);
});

See also: Check the Downloaded File Name and Content

Upvotes: 3

Related Questions