【问题标题】:Intercepting a HTTP request in the middle of a test in Testcafe在 Testcafe 的测试过程中拦截 HTTP 请求
【发布时间】:2022-11-10 22:21:10
【问题描述】:

我正在使用 Testcafe 编写功能测试。测试场景如下,有一个切换按钮,可根据 API 调用激活/停用

当我打开我的应用程序时,会进行一个返回值 ON/OFF 的 API 调用;基于此,拨动开关被激活或停用。

当用户再次单击该切换按钮时,我想拦截该呼叫。

长话短说:

  • 用户登录
  • XYZ API 被调用,它给出了响应
  • 基于该响应,切换按钮被激活
  • 然后用户将点击切换按钮
  • 现在应该再次调用 XYZ API,这将返回 OFF
    await t.navigateTo(`${url}`);
    await t
        .click(myPage.toggleSwitch)
    .addRequestHooks(myPage.xyzAPI.respond([{ valueBar: "ON" }
    ]))
    .expect(myPage.toggleSwitch.checked)
    .eql(true);

});```

【问题讨论】:

    标签: testing automated-tests testcafe functional-testing


    【解决方案1】:

    当用户再次单击该切换按钮时,我想拦截该呼叫。

    您需要在 click 操作之前添加目标请求挂钩。此外,在click 操作之前,应该断开操作链。

        await t.navigateTo(`${url}`);
    
        await t.addRequestHooks(<hook that caught the API calls>);
        
        await t
            .click(myPage.toggleSwitch)
        .expect(myPage.toggleSwitch.checked).eql(true);
    

    【讨论】:

      猜你喜欢
      • 2013-01-31
      • 2017-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-02
      • 2019-07-14
      • 1970-01-01
      相关资源
      最近更新 更多