New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RequestHook regressions with native automation #7640
Comments
Hi @Klaster1
Could you please describe why you need intercepting the |
The app under test works with HTTP and WebSocket endpoints, I have to mock data from all sources. Mocking only HTTP requests would results in inadequate coverage. During tests, instead of using RequestMock, I start a lightweight express mock app per test and redirect all API calls to it. The same express app is used during development. This approach proved much more flexible than basic RequestMock. |
@Klaster1, I was able to reproduce the RequestHook event modification issue. Let's focus on this issue in this thread for now. We still do not clearly understand why you need to intercept WebSocket handshakes. Why do you need some code coverage for handshakes? Please share more details with us and create a separate issue for this purpose. |
@AlexKamaev sure, here are more details about my setup. Parts involved:
As a FE-developer, I want to cover the FE with tests, which I use TestCafe for. I do not want to perform complete integration testing of FE+BE, so I create an instance of a tester for each test. The same thing's used for tests and development. Here's an excerpt of the integration layer that I use to instantiate a tester for each test:
I hope this makes the need to mock web sockets clearer. Standard TestCafe APIs, such as |
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. |
According to the changelog, the 2.6.0-rc1 addresses my problem, so I updated to it and run the suite again. The mocked requests are now getting blocked by something, resulting in Another thing I noticed is that my other hook I use to mock Stripe calls doesn't work under NA too:
|
@Klaster1 async onRequest(e: any) {
e.requestOptions.hostname = 'localhost';
e.requestOptions.host = `localhost:${this.port}`;
e.requestOptions.port = this.port.toString();
} The test code is here: |
@AlexKamaev here's a test that reproduces the Stripe hook regression. Works without native automation, and fails with. import { RequestMock, Selector } from 'testcafe';
fixture('Debug');
test('Debug', async (t) => {
const hook = RequestMock()
.onRequestTo({ url: /setup_intents/ })
.respond((req, res) => {
res.statusCode = 500;
res.headers = { 'Access-Control-Allow-Origin': '*' };
res.setBody(JSON.stringify({ error: 'Aborted by hook' }));
});
await t.addRequestHooks(hook);
await t.navigateTo('https://portal.gridgain.com');
await t.typeText(Selector('[gta="email_input"]'), 'iborisov+7640@gridgain.com');
await t.typeText(Selector('[gta="pwd_input"]'), '1');
await t.click(Selector('[gta="sign_in_btn"]'));
await t.expect(Selector('[gta="create-nebula-cluster-button"]').hasAttribute('disabled')).notOk();
await t.click(Selector('[gta="create-nebula-cluster-button"]'));
await t.expect(Selector('dialog-provision-cluster').exists).ok();
await t.click(Selector('.price__link'));
await t
.typeText(Selector(`[gta='dialog-update-credit-card__cardholder-name-input']`), 'Mighty Pirate')
.switchToIframe(Selector(`[gta='dialog-update-credit-card__card-number-input'] iframe`))
.typeText(Selector('input.Input'), '4242424242424242')
.switchToMainWindow()
.pressKey('tab')
.switchToIframe(Selector(`[gta='dialog-update-credit-card__card-expiry-input'] iframe`))
.typeText(Selector('input.Input'), '1030')
.switchToMainWindow()
.pressKey('tab')
.switchToIframe(Selector(`[gta='dialog-update-credit-card__card-cvc-input'] iframe`))
.typeText(Selector('input.Input'), '666')
.switchToMainWindow()
.pressKey('tab')
.typeText(Selector(`[gta='dialog-update-credit-card__street-address-input']`), 'Scumm bar')
.typeText(Selector(`[gta='dialog-update-credit-card__city-input']`), 'Melee Town')
.typeText(Selector(`[gta='dialog-update-credit-card__region-input']`), 'Melee Island')
.typeText(Selector(`[gta='dialog-update-credit-card__zip-input']`), '191040')
.click(Selector(`[gta='dialog-update-credit-card__country-input']`))
.click(Selector('mat-option').withText('Jamaica'))
.typeText(Selector(`[gta='dialog-update-credit-card__company-input']`), 'The Pirate Company')
.click(Selector(`[gta='dialog-update-credit-card__terms-input']`))
.click(Selector(`[gta='dialog-update-credit-card__submit-button']`));
await t.expect(Selector('.snackbar-error').textContent).contains('An unexpected error occurred');
}); As to the |
@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. |
The example from #7640 (comment) works correctly. |
@miherlosev I'm not sure what you mean. Did you manage to address the discrepancy between the regular and native automation modes in the Stripe request hook? To clarify, the request hook was supposed to intercept Stripe requests, preventing them from hitting the matching endpoints. That doesn't work in native automation. |
I'm still able to reproduce the described issue. I'll reopen it. |
@Klaster1 |
@AlexKamaev I've created a new test account, please update the fixture to use "iborisov+7640+2@gridgain.com" instead of "iborisov+7640@gridgain.com". If the same happens again, feel free to create another account. With the new build, Stripe iframes do not load at all with the NA enabled. The regular mode still works as expected. I can't tell if the fix helps because of a new regression.
|
@Klaster1, |
this should fix #7640 issue with request interception - implement the `attachedToTarget` event for iframes - call Fetch.enable for iframes - add the `Runtime.runIfWaitingForDebugger` call just to make this thing work (playwright does the same trick). - ignore typing errors for sessionId argument (cyrus-and/chrome-remote-interface#534) - I did not manage to create a test due to its complexity and unknown cause
Release v2.6.1-rc.1 addresses this. |
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?
WebSocket
handshakes.What is the Expected behavior?
WebSocket
handshakes.Same as without native automation, I expect for the hook to intercept all HTTP events, including
fetch
andWebSocket
handshakes, and successfully send requests to the web service instance assigned to the test instance.What is your TestCafe test code?
Steps to Reproduce
RequestHook
that rewrites the request destination, forfetch
requests and WebSocket handshakes.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
The text was updated successfully, but these errors were encountered: