How to check downloaded file name?

大城市里の小女人 提交于 2021-02-10 14:21:57

问题


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.


回答1:


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']);
});


来源:https://stackoverflow.com/questions/58657559/how-to-check-downloaded-file-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!