DevExpress / testcafe

A Node.js tool to automate end-to-end web testing.
https://testcafe.io
MIT License
9.82k stars 670 forks source link

Conflicting RequestLogger hooks do not record Response after logResponseBody #8102

Closed codambro closed 9 months ago

codambro commented 10 months ago

What is your Scenario?

Native Automation DIsabled. We are trying to have a global request logger, as well as adding addition request loggers in specific tests. The global request logger is correct recording all requests. But the local logger is not collecting all responses.

What is the Current behavior?

The downstream RequestLogger hook will not record a response if a previous RequestLogger hook captured a request with logResponseBody: true. If logResponseBody: false or not set, the local RequestLogger WILL have the response recorded.

Local RequestLogger hook requests:
[
  {
    "id": "PrQEpjbNQ",
    "testRunId": "EJtzFOcNE",
    "userAgent": "Chrome 119.0.0.0 / macOS 10.15.7",
    "request": {
      "timestamp": 1702396844662,
      "url": "https://youtube.com/",
      "method": "get"
    }
  }
]
Global RequestLogger hook requests:
[
  {
    "id": "PrQEpjbNQ",
    "testRunId": "EJtzFOcNE",
    "userAgent": "Chrome 119.0.0.0 / macOS 10.15.7",
    "request": {
      "timestamp": 1702396844662,
      "url": "https://youtube.com/",
      "method": "get"
    },
    "response": {
      "statusCode": 301,
      "timestamp": 1702396844853,
      "body": {
        "type": "Buffer",
        "data": []
      }
    }
  }
]

What is the Expected behavior?

I expect the response to appear in all request logger hooks.

What is the public URL of the test page? (attach your complete example)

https://youtube.com

What is your TestCafe test code?

import { RequestLogger } from "testcafe";

const url = "https://youtube.com";

const globalRequestLogger = RequestLogger(url, { logResponseBody: true });

fixture("Fixture").requestHooks(globalRequestLogger).afterEach(async t => {
    console.log("Global RequestLogger hook requests:");
    console.log(JSON.stringify(globalRequestLogger.requests, undefined, 2));
});

test("TEST", async t => {
    const localLogger = RequestLogger(url)
    await t.addRequestHooks(localLogger);
    await t.navigateTo(url);
    await t.wait(10000); // ensure all requests are complete
    console.log(JSON.stringify(localLogger.requests, undefined, 2));
    await t.removeRequestHooks(localLogger);
})

Your complete configuration file

disableNativeAutomation: true

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

1. 2. 3.

TestCafe version

3.1.0

Node.js version

v18.17.1

Command-line arguments

using api launcher

Browser name(s) and version(s)

chrome

Platform(s) and version(s)

No response

Other

It appears adding logResponseBody: true to the local request logger too also resolves it. This is the workaround we are using for now, but as we don't need the response body and just the status code, its a bit of unecessary logging.

Can also remove the logResponseBody option from the global logger to see it work:

Local RequestLogger hook requests:
[
  {
    "id": "eWv5ipdKQ",
    "testRunId": "nfUmS59WV",
    "userAgent": "Chrome 119.0.0.0 / macOS 10.15.7",
    "request": {
      "timestamp": 1702397002673,
      "url": "https://youtube.com/",
      "method": "get"
    },
    "response": {
      "statusCode": 301,
      "timestamp": 1702397002828
    }
  }
]
Global RequestLogger hook requests:
[
  {
    "id": "eWv5ipdKQ",
    "testRunId": "nfUmS59WV",
    "userAgent": "Chrome 119.0.0.0 / macOS 10.15.7",
    "request": {
      "timestamp": 1702397002673,
      "url": "https://youtube.com/",
      "method": "get"
    },
    "response": {
      "statusCode": 301,
      "timestamp": 1702397002828
    }
  }
]
github-actions[bot] commented 10 months ago

We appreciate you taking the time to share information about this issue. We reproduced the bug and added this ticket to our internal task queue. We'll update this thread once we have news.

Bayheck commented 9 months ago

We discussed it with the team and decided to close the issue. The scope of this issue is very narrow. Besides, there are multiple working workarounds for this scenario. Moreover, the link you shared has the 301 response status code (moved permanently). So, it's not necessary to pass the ‘logResponseBody’ option because the body will be empty. For your specific scenario, you can use a direct link (‘https://www.youtube.com/’) instead of ‘https://youtube.com’ for your loggers to work as you expect.

The implementation of your scenario will take a lot of resources because of its complexity. Unfortunately, we do not see a chance that we start working on this feature soon.