问题
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