79676533

Date: 2025-06-23 17:11:32
Score: 4.5
Natty:
Report link

I am having the same problem. Here is some sample code. As can be seen from the results, the code outside of the test is called twice. Once before the actual test is run and once after. Only on the second pass will the code inside the test scope is executed. I assume that this is due to Playwright scanning for tests before executing the actual tests.

Like Drashty, I am creating parameterized tests so the parameter data has to come from outside of the test block. The problem with this double pass is that the parameter retrieval routines are being called twice.

I have not been able to tap on the internal context to prevent a second call to the retrieve parameter data routine. As can be seen below, the context does not seem to be preserved across the two passes (the iterator value is the same).

Question: how can I tap into the Playwright context so that I can set a boolean flag that will prevent pre-test code from executing twice?

import { test } from '@playwright/test';

let iterator: number = 0;
console.log(`Pre Test step: ${iterator}`);
iterator = iterator + 1;

test(`testing with id: a test`, () => {
  console.log(`dummy step`);
});

Results:

enter image description here

Reasons:
  • Blacklisted phrase (0.5): how can I
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): I am having the same problem
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: herbey zepeda