下载文件-使用TestCafe在Internet Explorer中保存弹出窗口 [英] Download file - Save popup in Internet Explorer using TestCafe

查看:93
本文介绍了下载文件-使用TestCafe在Internet Explorer中保存弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Internet Explorer中,每当下载文件窗口要求提供三个选项时1.打开2.保存3.关闭

In Internet Explorer, whenever a download file window is asking for three options 1. Open 2. Save 3. Close

由于公司政策的原因,无法禁用弹出窗口.但是,在TestCafe自动化中需要处理相同的内容.单击什么将另存为"选项?

Due to company policy, can't disable popup. However, need to handle same in TestCafe automation. What to click save/save as option?

请求解决方案.

推荐答案

除了禁用设置中的弹出窗口外,没有其他方法可以解决此问题.解决方法是,我建议您使用 requestHooks功能下载文件.请在IE中尝试以下示例:

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.

请参考以下文章,以阅读有关钩子的更多信息:> 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

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

这篇关于下载文件-使用TestCafe在Internet Explorer中保存弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆