Typescript 记录测试文件下载的HTTP请求失败

Typescript 记录测试文件下载的HTTP请求失败,typescript,automated-tests,e2e-testing,web-testing,testcafe,Typescript,Automated Tests,E2e Testing,Web Testing,Testcafe,我试图复制这一点: 我的目标页面有target=“\u blank”是否有方法更改属性以删除此target 所以测试失败了 不太清楚示例中的代码是做什么的。URL是否必须是下载链接所在页面的URL import { ClientFunction, t, Selector, RequestLogger } from 'testcafe' import * as fs from 'fs'; import * as path from 'path'; ... const forInvoice = n

我试图复制这一点:

我的目标页面有
target=“\u blank”
是否有方法更改属性以删除此
target

所以测试失败了

不太清楚示例中的代码是做什么的。URL是否必须是下载链接所在页面的URL

import { ClientFunction, t, Selector, RequestLogger } from 'testcafe'
import * as fs from 'fs';
import * as path from 'path';
...
const forInvoice = new ForInvoice()
const client = 'STRV s.r.o.'

const url = urlFor('?/timers/unbilledOverview')
const logger = RequestLogger({ url, method: 'post' }, {
logResponseHeaders: true,
logResponseBody:    true
});

fixture.only `For Invoicing`
   .requestHooks(logger);

test('Verify download of .xls and .pdf', async t => {
    await t.useRole(ADMIN_INVOICE)
    await forInvoice.navigateToForInvoicing()
    await forInvoice.filterClient(client)
    await t
        .click(Selector('a').filter('.sc-mini-icon-file.excel-file'))
        .expect(logger.contains(r => r.response.statusCode === 200)).ok();

    const filePath = path.join(__dirname, 'STRV-s-r-o-Attachment');

    console.log(filePath);
    console.log(logger.requests[0].response.headers);

    fs.writeFileSync(filePath, logger.requests[0].response.body);

})

我注意到,在提供的示例中,您没有指定夹具或测试的起始页。这可能是错误的原因

您提到的TestCafe示例执行以下操作:

  • 创建一个
    RequestLogger
    实例,该实例监视到测试启动所在页面的请求(标题和正文)
  • 单击按钮以启动文件下载
  • 等待服务器的成功响应
  • 将响应正文保存到文件中
  • filter对象中的
    url
    参数对应于请求发送到的页面(),不必与测试页面的url匹配

    您可以使用标准Web API修改页面上的元素。您可以使用以下代码开始:

    import { Selector, ClientFunction } from 'testcafe'
    
    const link = Selector('a');
    
    const removeTarget = ClientFunction(() => {
        link().removeAttribute('target');
    }, { dependencies: { link } })
    
    fixture`Fixture name`
        .page`https://your_page.com/`;
    
    test('Remove target', async t => {
        await removeTarget();
    });
    

    你能提供你方抛出的错误的文本吗?