Search code examples
testingautomated-testsreporte2e-testingtestcafe

Is there a way to specify a dynamic report filename in TestCafe


I am writing the output of my TestCafe to file. I was wondering if it can be a dynamic path like a screenshot path.

I tried using something like the values listed here, but I think this is only for screenshots and videos.

https://devexpress.github.io/testcafe/documentation/using-testcafe/common-concepts/screenshots-and-videos.html#path-pattern-placeholders

Here is what works, but is just not dynamic:

testcafe chrome test.testcafe -r json:report.json

Here is what I would like to do:

testcafe chrome test.testcafe -r json:T:\Logs\ -p ${DATE}/${TIME}/${FIXTURE}/${TEST}/${FILE_INDEX}.json

EDIT 1: Should have said this, but I am using TestCafe Studio. I can use the built-in Function action, but I'm stuck with the limited functionality of Studio.


Solution

  • I suggest you use the programming interface to customize your reporter output:

    run.js:

    const createTestCafe = require('testcafe');
    let testcafe         = null;
    
    createTestCafe('localhost', 1337, 1338)
        .then(tc => {
            testcafe     = tc;
            const runner = testcafe.createRunner();
    
            const config = { key1: 'value1', key2: 'value2' }; // you can specify it as a date, etc.
    
            return runner
                .src(['d:/***/test.js'])
                .browsers(['chrome'])
                .reporter('xunit', `reports/${config.key1}/out-${config.key2}.xml`)
                .run();
        })
        .then(failedCount => {
            console.log('Tests failed: ' + failedCount);
            testcafe.close();
        });
    
    

    Command:

    node run.js