Home > Blockchain >  Can I get the network requests in testcafe from the beforeEach?
Can I get the network requests in testcafe from the beforeEach?

Time:02-12

I saw this page from testcafe documentation, but it all points toward tests.

import { RequestLogger } from 'testcafe';
const logger = RequestLogger({ logResponseBody: true, logRequestBody: true });
const methodCallInBeforeEach = async => {console.log(logger.requests)}

Every time my logger is empty, as if I had no requests. This works if I try to get the info from a test, but didn't manage to do it from the beforeEach. Is that even possible or am I missing something?

CodePudding user response:

I prepared a sample that demonstrates that the logger.requests works as expected inside the beforeEach hook:

import { RequestLogger, Selector } from 'testcafe';

const headerLogger = RequestLogger(/testcafe/, {
    logRequestHeaders:  true,
    logResponseHeaders: true,
});

fixture `f`
    .page `https://testcafe.io`
    .requestHooks(headerLogger)
    .beforeEach(async t => {
        await t.click(Selector('a').withText('Docs'));

        console.log(headerLogger.requests.map(r => r.request.url));
    });

test(`t`, async t => {

});

  • Related