edit: When I added URL Filter to Hook, it's works - so case is only without it.
I'm trying to add custom HTTP header without any URL filter to few fixtures or tests.
The whole fixture couldn't load and hang on TestCafe splash screen with CONNECTED information. When I removed .requestHooks(hook); from fixture or test chain, it's work as expected.
When we'll check network info during loading, TestCafe is still sending requests to browser heartbeat (Request URL: http://192.168.1.183:52055/browser/heartbeat/7bPNpzU) and get 200 OK with response but without url property value:
{
"code":"ok",
"url":""
}
Fixture or test with .requestHooks(hook); method should load and execute properly.
I'm using your example test and example HTTP request hook to easily allow to reproduce it.
Your website URL (or attach your complete example): http://devexpress.github.io/testcafe/example
Your complete test code (or attach your test files):
import { Selector, RequestHook } from 'testcafe';
class MyHeaderHook extends RequestHook {
constructor() { // btw. TestCafe crew, you could remove constructor from your docs here, it's useless when you're not passing requestFilterRules or responseEventConfigureOpts
// No URL filtering applied to this hook
// so it will be used for all requests.
super();
}
onRequest(requestEvent) {
requestEvent.requestOptions.headers['MyHeader'] = 'MyHeader value';
}
}
const myHeaderHook = new MyHeaderHook();
fixture`Getting Started`
.page`http://devexpress.github.io/testcafe/example`
.requestHooks(myHeaderHook);
test('My first test', async (t) => {
await t
.typeText('#developer-name', 'John Smith')
.click('#submit-button')
// Use the assertion to check if the actual header text is equal to the expected one
.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');
});
Your complete test report:
$ ./node_modules/.bin/testcafe scenarios/hook-test.js
The "src" option from the configuration file will be ignored.
Running tests in:
- Chrome 74.0.3729 / Mac OS X 10.14.4
Getting Started
^CStopping TestCafe...
I forced exit due to few minutes without any result.
Screenshots:

Config file:
{
"browsers": [ "chrome" ],
"src": "scenarios",
"reporter": [
{
"name": "spec"
}
],
"screenshotPath": "screenshots",
"takeScreenshotsOnFails": true,
"screenshotPathPattern": "${DATE}_${TIME}/${TEST}/${USERAGENT}/${FILE_INDEX}.png"
}
.testcaferc.json$ ./node_modules/.bin/testcafe1.1.4v10.14.2Chrome 74.0.3729Mac OS X 10.14.4I was able to reproduce the issue. I think it's not a valid scenario to pass nothing to the RequestHook constructor. Anyway, TestCafe should not hang in this case, so I think it is a bug and we'll discuss a possible solution with the team. Thank you for your report.
Thanks @AlexKamaev. If passing nothing to RequestHook is not valid scenario, please also fix this docs example which is invalid: https://devexpress.github.io/testcafe/documentation/test-api/intercepting-http-requests/#creating-a-custom-http-request-hook
class JwtBearerAuthorization extends RequestHook {
constructor () {
// No URL filtering applied to this hook
// so it will be used for all requests.
super();
}
onRequest (e) {
e.requestOptions.headers['Authorization'] = 'generate token here';
}
}
Thanks in advance!
Best regards,
Marcin
We have not discussed this issue with the team yet. Once we study the case, we will correct the description given in the documentation if required. Thank you for pointing this out.
I discussed the issue with the team and it looks that it's valid to pass nothing to the Request Hook constructor. Sorry for this misstatement. Your code hangs because you do not override the onResponse method, since it should be implemented (at least it can be empty).
Obviously the example from the docs is incorrect so we'll fix it as well.
聽
Thanks for clarification 馃憦
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.