Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
docs: fix deprecated Playwright API usage in running-code.md (#39403)
William Oliveiraad06412e0335
diff --git a/packages/playwright-core/src/skill/references/running-code.md b/packages/playwright-core/src/skill/references/running-code.mdindex 7d6d22fd09..8b35e9a41d 100644--- a/packages/playwright-core/src/skill/references/running-code.md+++ b/packages/playwright-core/src/skill/references/running-code.md@@ -87,7 +87,7 @@ playwright-cli run-code "async page => {# Wait for specific elementplaywright-cli run-code "async page => {- await page.waitForSelector('.loading', { state: 'hidden' });+ await page.locator('.loading').waitFor({ state: 'hidden' });}"# Wait for function to return true@@ -97,7 +97,7 @@ playwright-cli run-code "async page => {# Wait with timeoutplaywright-cli run-code "async page => {- await page.waitForSelector('.result', { timeout: 10000 });+ await page.locator('.result').waitFor({ timeout: 10000 });}"```@@ -122,10 +122,9 @@ playwright-cli run-code "async page => {```bash# Handle file downloadplaywright-cli run-code "async page => {- const [download] = await Promise.all([- page.waitForEvent('download'),- page.click('a.download-link')- ]);+ const downloadPromise = page.waitForEvent('download');+ await page.getByRole('link', { name: 'Download' }).click();+ const download = await downloadPromise;await download.saveAs('./downloaded-file.pdf');return download.suggestedFilename();}"@@ -197,7 +196,7 @@ playwright-cli run-code "async page => {# Try-catch in run-codeplaywright-cli run-code "async page => {try {- await page.click('.maybe-missing', { timeout: 1000 });+ await page.getByRole('button', { name: 'Submit' }).click({ timeout: 1000 });return 'clicked';} catch (e) {return 'element not found';@@ -211,9 +210,9 @@ playwright-cli run-code "async page => {# Login and save stateplaywright-cli run-code "async page => {await page.goto('https://example.com/login');- await page.fill('input[name=email]', '[email protected]');- await page.fill('input[name=password]', 'secret');- await page.click('button[type=submit]');+ await page.getByRole('textbox', { name: 'Email' }).fill('[email protected]');+ await page.getByRole('textbox', { name: 'Password' }).fill('secret');+ await page.getByRole('button', { name: 'Sign in' }).click();await page.waitForURL('**/dashboard');await page.context().storageState({ path: 'auth.json' });return 'Login successful';