有没有办法验证发送到 API 的请求和点击页面元素后的响应?

Is there way to verify the request sent to API and the response back on click of a page element?

在 UI 测试期间,单击按钮后是否可以使用 Node.js+Protractor[ 验证发送的请求是否正确以及 API 返回的响应是否正确

有一种方法,至少在 chrome 浏览器中,其他的不确定,但是很长很复杂

  1. 您需要将这些从配置文件传递到您的浏览器
chromeCapabilities.chromeOptions.perfLoggingPrefs = {
        enableNetwork: true,
        enablePage: false,
        traceCategories: 'browser,devtools.timeline,devtools',
    };
    chromeCapabilities.loggingPrefs = {
        performance: 'ALL',
        browser: 'ALL',
    };
  1. 获取日志
let logs = await browser
        .manage()
        .logs()
        .get('performance');
  1. 过滤它们以找到您要查找的内容。您从 #2 获得的日志将包括您发送的请求、您返回的响应等等,因此这是找到您需要的最困难的部分

如果您打算测试 API 响应,我会为此专门进行 API 测试,而不是在量角器中进行