Write text to a file using testcafe

913 Views Asked by At

I was wondering if there's a way I can create a file and save the data in a file using testcafe.

test('copy data', async t => {
  await someAction(t);
  const data = RequestLogger(data, { logRequestBody: true, stringifyRequestBody: true });
  await t.clearContent('data/output.js');
  await t.writeText('data/output.js', data);
});

I have written some dummy test to explain what I need. Is it possible to do something of this sort in testcafe? How could we do that?

1

There are 1 best solutions below

1
On BEST ANSWER

You can safely treat a testcafe test as a nodejs application where you can use any standard nodejs API and/or any other third-party modules to write/read files:

How do I write files in Node.js?

Import Third-Party Modules