79675627

Date: 2025-06-23 04:51:18
Score: 0.5
Natty:
Report link
test('on paste should autofill', async ({ page, context }) => {
  // grant access to clipboard (you can also set this in the playwright.config.ts file)
  await context.grantPermissions(['clipboard-read', 'clipboard-write']);

  // focus on the input
  await page.locator('input').focus();

  // copy text to clipboard
  await page.evaluate(() => navigator.clipboard.writeText('123'));

  // Get clipboard content
  const handle = await page.evaluateHandle(() => navigator.clipboard.readText());
  const clipboardContent = await handle.jsonValue();

  // paste text from clipboard
  await page.locator(first).press('Meta+v');

  // check if the input has the value
  await expect(page.locator(input)).toHaveValue('123');
});

Taken from: https://www.adebayosegun.com/snippets/copy-paste-playwright

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: jmberon