I am trying to send the data (in the following code case, test name or something) to another file using fs module of javascript. However, I seem to be unsuccessful for some reason. Can anybody help me figure this out?
const { test, expect } = require('@playwright/test');
var fs = require('fs');
async function appendToFile() {
await test.beforeEach(async ({ page }) => {
await page.goto('/example-4');
});
await test('should display the name of the most recently hovered item', async ({ page }, testInfo) => {
const box4ItemsList = await page.waitForSelector('[data-cy=box-4-items-list]');
const secondChild = await box4ItemsList.$(':nth-child(2)');
await secondChild.hover();
const box4SelectedName = await page.waitForSelector('[data-cy=box-4-selected-name]');
const selectedNameText = await box4SelectedName.innerText();
expect(selectedNameText).toEqual('Option Two');
console.log("Hello", testInfo.status)
try {
await fs.appendFile('mynewfile1.txt', 'Hello content!', (err) => {
if (err) {
console.error('Error appending to file:', err);
return;
}
console.log('Data appended successfully!');
});
} catch (err) {
console.error('Error appending to file:', err);
}
});
}
appendToFile()
The output:
Running 1 test using 1 worker
retry_folder/test_3.spec.js:14:11 › should display the name of the most recently hovered item
Hello passed
Data appended successfully!
1 passed (3.5s)
To open last HTML report run:
npx playwright show-report
Your help is highly appreciated!
This thread is trying to answer question "How to send data to another file using fs module in JavaScript?"
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].