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?
- The hook does not intercept
WebSocket
handshakes. - Request option changes (port, host, hostname, url) no longer affect the requests.
What is the Expected behavior?
- The hook intercepts
WebSocket
handshakes. - 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
- Add
RequestHook
that rewrites the request destination, forfetch
requests and WebSocket handshakes. - Check that it works without native automation.
- 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
- attempt to fix missing requests (#7640) (#7712) this should fix #7640 issue with request interception - implement the `attachedToTarget` event for iframes - call Fetch.enable for iframes - add t... — committed to DevExpress/testcafe by AlexKamaev a year ago
- add missing functional tests for #7770 and #7640 (#7778) Tests fail now, because the Native Automation task is in non-graphic mode. Tests should pass after merge. — committed to DevExpress/testcafe by AlexKamaev a year ago
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.