testcafe: RequestHook regressions with native automation

What is your Scenario?

All my tests run against a fake service which I redirect requests to with a RequestHook.

What is the Current behavior?

  1. The hook does not intercept WebSocket handshakes.
  2. Request option changes (port, host, hostname, url) no longer affect the requests.

What is the Expected behavior?

  1. The hook intercepts WebSocket handshakes.
  2. Request option changes (port, host, hostname, url) affect the requests.

Same as without native automation, I expect for the hook to intercept all HTTP events, including fetch and WebSocket handshakes, and successfully send requests to the web service instance assigned to the test instance.

What is your TestCafe test code?

  async onRequest(e: any) {
    e.requestOptions.hostname = 'localhost';
    e.requestOptions.host = `localhost:${this.port}`;
    e.requestOptions.port = this.port.toString();
  }

Steps to Reproduce

  1. Add RequestHook that rewrites the request destination, for fetch requests and WebSocket handshakes.
  2. Check that it works without native automation.
  3. Check that it doesn’t with native automation.

TestCafe version

2.5.0

Node.js version

18.15.0

Command-line arguments

testcafe chrome fixture.ts --test=“Test anme” --live --native-automation

Browser name(s) and version(s)

Chrome 112

Platform(s) and version(s)

Windows 10 19045.2846

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Release v2.6.1-rc.1 addresses this.

I’m still able to reproduce the described issue. I’ll reopen it.

@Klaster1 Thank you for sharing your code. I have managed to reproduce the issue. It looks like for some reason the mock code is not called in Native Automation mode.

@Klaster1,

Thank you for sharing your usage scenario. Please create a separate issue about WebSockets in the Native Automation mode. Let’s keep this thread only for the Request Hook redirect issue.