Hiruthere
Hiruthere

Reputation: 119

Download file - Save popup in Internet Explorer using TestCafe

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.

Upvotes: 2

Views: 1251

Answers (2)

Alex Kamaev
Alex Kamaev

Reputation: 6318

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

Upvotes: 3

hdorgeval
hdorgeval

Reputation: 3030

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.

Upvotes: 2

Related Questions