问题
In Internet Explorer, whenever a download file window is asking for three options 1. Open 2. Save 3. Close
Due to company policy, can't disable popup. However, need to handle same in TestCafe automation. What to click save/save as option?
Request for a solution.
回答1:
There is no way to overcome this issue, except for disabling the popup in settings. As a workaround, I can suggest you use the requestHooks
feature to download the file. Please try the following example in IE:
import fs from 'fs';
import { Selector, RequestHook } from 'testcafe';
class MyHook extends RequestHook {
constructor (requestFilterRules, responseEventConfigureOpts) {
super(requestFilterRules, responseEventConfigureOpts);
}
onRequest (event) {
}
onResponse (event) {
const path = 'file.zip';
fs.writeFileSync(path, event.body);
}
}
fixture `fixture`
.page `https://github.com/AlexKamaev/match-url-wildcard`;
test.requestHooks(new MyHook('https://codeload.github.com/AlexKamaev/match-url-wildcard/zip/master', {
includeHeaders: true,
includeBody: true
}))(`test`, async t => {
await t.click(Selector('summary').withText('Clone or download'));
await t.click(Selector('a').withText('Download ZIP'));
await t.wait(10000);
});
When the browser finishes downloading, the hook gets the response and saves it to the file system.
Please refer to the following articles to read more information about hooks: https://devexpress.github.io/testcafe/documentation/test-api/intercepting-http-requests/ https://devexpress.github.io/testcafe/documentation/test-api/intercepting-http-requests/creating-a-custom-http-request-hook.html
回答2:
I fear there is no solution. I faced same problem on my side and choose to run TestCafe with Chrome for that kind of test.
来源:https://stackoverflow.com/questions/54284722/download-file-save-popup-in-internet-explorer-using-testcafe