declare const PLAYWRIGHT_BEST_PRACTICES = "\n# Playwright Guidelines\n\n## 1. **Start waiting for API responses before triggering actions or use Promise.all()**\n\nStart listening for the expected network response **before** performing actions like button clicks to avoid race conditions.\n\n**\u2705 Do:**\n\n```jsx\nconst [response] = await Promise.all([\n  page.waitForResponse(\"api/submit\"),\n  page.getByRole('button', { name: 'Submit' }).click(),\n]);\n\nexpect(response.status()).toBe(200);\n// next steps\n```\n\n**\u2705 Do:**\n\n```jsx\nconst response = page.waitForResponse(\"api/submit\"); // notice no await here, start listening first\nawait page.getByRole('button', { name: 'Submit' }).click(); // then perform the action\nawait response; // wait for the response to complete\n```\n\nBoth of the above approaches are valid and good practice. But the following is a bad practice:\n\n**\uD83D\uDEAB Don\u2019t:**\n\n```jsx\nawait page.getByRole('button', { name: 'Submit' }).click();\nawait page.waitForResponse(\"api/submit\"); // Too late \u2014 response might have already returned\n```\n\n---\n\n## 2. **Use `test.slow()` or `test.setTimeout()` for longer tests**\n\nFor longer or more complex flows, use `test.slow()` or `test.setTimeout()` to increase timeout without causing unnecessary failures in CI.\n\n```jsx\ntest('generates invoice after third-party sync', async ({ page }) => {\n  test.slow(); // Extends (3x) timeout for this test\n\n  await page.click('button:has-text(\"Sync with Xero\")');\n  await expect(page.getByText('Invoice generated')).toBeVisible();\n});\n\n```\n\n---\n\n## 3. Include cleanup logic using `afterAll`\n\nUse `afterAll` to clean up any test data created during the test suite. This keeps the environment clean and prevents leftover test artifacts. It also serves as a test for delete functionality.\n\n**\u2705 Example:**\n\n```jsx\nlet userId: string;\n\ntest('creates a user', async ({ page }) => {});\n\nafterAll(async ({ request }) => {\n  if (userId) {\n    const res = await request.delete(`/api/users/${userId}`);\n    expect(res.ok()).toBeTruthy(); // Optional assertion\n  }\n});\n```\n\n**\uD83D\uDD0E Why this matters:**\n\n- Ensures test-created entities are removed after execution\n- Keeps test environments clean for future runs\n- Helps catch issues in delete endpoints as well\n\n---\n\n## 4. **Use `pressSequentially` for more human-like typing**\n\nInstead of using `fill()`, consider using `pressSequentially()` when simulating text input, especially if you're recording or showcasing tests, it mimics a real user typing, making playback more natural.\n\n**\u2705 Do:**\n\n```jsx\nawait page.locator('#email').pressSequentially('test@example.com');\n```\n\n**\uD83D\uDEAB Don\u2019t:**\n\n```jsx\nawait page.fill('#email', 'test@example.com'); // Instant fill, less realistic in playback\n```\n\n---\n\n## 6. Never use magic timeouts\n\nTimeouts like `await page.waitForTimeout()` are a big reason behind flaky tests. Do not use them unless there is a very good reason behind it. Try to use other hooks like `waitFor()` or `waitForResponse()` to smartly wait for elements to appear / disappear or API calls to complete. In general, avoid `page.waitForTimeout()`.\n\n## 7. Never use page.waitForLoadState('networkidle')\n\nUsing `page.waitForLoadState('networkidle')` is an anti-pattern that can lead to flaky tests. Instead, use more specific waits like `waitForResponse()` or `waitForSelector()` to ensure the necessary conditions are met before proceeding.\n";
export default PLAYWRIGHT_BEST_PRACTICES;
