Practice Test Automation: https://commitquality.com
In this video, we learn how to output console logs in Playwright's UI tool traceviewer
and actions tab to facilitate debugging during test automation. Here are the steps followed in the tutorial:
Run the Playwright Test UI tool: Run the following command in the terminal: npx playwright test --ui
. This should open the Playwright Test UI tool.
Adding console output to a test: To add console output to a test, go back to the test file and use the page.evaluate()
method. For example, to output a static string, add the following code after an input action:
await page.evaluate(() => {
console.log('subscribe');
});
Viewing console output: Go back to the UI tool, and you should see a new page.evaluate
action right after the input action. Click on the page.evaluate
action, and you should see the static string (e.g., 'subscribe') in the console output.
Outputting dynamic values: To output dynamic values, such as input value or text content, create a locator for the element, and pass it through the page.evaluate()
method. For example, to output the input value of a text box:
// Create a locator for the input element
const inputLocator = page.locator('input[type="text"]');
// Get the input value
const inputValue = await inputLocator.inputValue();
// Pass the input value to page.evaluate()
await page.evaluate((val) => {
console.log('subscribe');
console.log(val);
}, inputValue);
After saving the changes, go back to the UI tool, click on the page.evaluate
action, and you should see the dynamic value (e.g., 'product2') in the console output.
In summary, this video demonstrates how to effectively use debugging outputs in Playwright's UI tool and traceviewer
to manage and troubleshoot running test cases.
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].