1

We are trying to track down a network issue in our company which causes a Browser Disconnect General Error. I want to use RequestLogger timestamp to help us highlight when this intermittent issue occurs and also any additional request/response information at that time.

In the Request Logger documentation the .requestHooks(logger) is initiated at every test case level. And then console.log(logRecord.X.X) is used to log the record at that specific time.

But how can I have a continuous logging throughout my whole test framework without using console.log(logRecord.X.X) on every line?

Is it somehow possible to have the RequestLogger continuously running via my test-runner function?

if(nodeConfig.util.getEnv('NODE_ENV') == "jenkins-ci")
        {
            // @ts-ignore
            // createTestCafe("localhost", port1, port2).then(tc => {
            createTestCafe().then(tc => {
                this.testcafe = tc;
                this.runner = this.testcafe.createRunner();

                return this.runner
                    .src(testPath)
                    .filter(filterSettings)
                    .browsers(environment.browserToLaunch)
                    .concurrency(environment.concurrencyAmount)
                    .reporter(reporterSettings)
                    .run(runSettingsCi);
            })
            .then(failedCount => {
                console.log('Location ' + testPath + ' tests failed: ' + failedCount);
                this.testcafe.close();
                process.exit(0);
            })
            .catch((err) => {
                console.log('Location ' + testPath + ' General Error');
                console.log(err);
                this.testcafe.close();
                process.exit(1);
            });
        }
Vladimir A.
  • 2,202
  • 2
  • 10
  • 28
Benny Meade
  • 602
  • 10
  • 25

2 Answers2

4

TestCafe doesn't allow attaching request hooks with the test runner class. At the same time, you can attach it to each fixture. RequestLogger will collect information about all requests.

For example:

import { Selector, RequestLogger } from 'testcafe';

const logger = RequestLogger();

fixture `Log all requests`
    .page`devexpress.github.io/testcafe`
    .requestHooks(logger)
    .afterEach(() => console.log(logger.requests));

test('Test 1', async t => {
    await t
        .click(Selector('span').withText('Docs'))
        .click(Selector('a').withText('Using TestCafe'))
        .click(Selector('a').withText('Test API'));
});

test('Test 2', async t => {
    await t
        .click(Selector('span').withText('Docs'))
        .click(Selector('a').withText('Continuous Integration'))
        .click(Selector('a').withText('How It Works'));
});
Vladimir A.
  • 2,202
  • 2
  • 10
  • 28
Dmitry Ostashev
  • 2,305
  • 1
  • 5
  • 21
1

Previously, TestCafe allowed you to attach request hooks to one test or fixture at a time. In the new TestCafe v1.19.0, you can also define global request hooks in a JavaScript configuration file .testcaferc.js to attach them to all fixtures and tests within a test run. You can learn more here: Global Request Hooks.

Please note that you can use the configFile option in CLI and program API to specify the path to a config file.

For the initial usage scenario, you can use the following example:

const { RequestLogger } = require('testcafe');
 
const logger = RequestLogger();
 
module.exports = {
   hooks: {
       request: logger,
   },
};

Helen Dikareva
  • 1,026
  • 6
  • 7