클립보드 내용 검증

Prev Next

일부 웹사이트에서는 사용자가 버튼(예: “클립보드에 복사”)을 클릭하여 URL 또는 텍스트 값을 클립보드에 복사할 수 있도록 지원합니다.

다음 스니펫을 사용하면 정확한 값이 실제로 복사되었는지 확인할 수 있습니다.

설정 방법

  1. “복사” 버튼을 클릭하는 스텝 다음에, Playwright 코드 스텝을 추가하세요.

  2. 아래 코드를 Playwright 코드 스텝에 붙여 넣으세요.

// Grant clipboard permissions for reading and writing
context.grantPermissions([
  'clipboard-write',
  'clipboard-read',
]);

// Read the clipboard content
const result = await page.evaluate(async () => {
  return await navigator.clipboard.readText();
});

// Verify that the clipboard contains the expected text
expect(result).toContain('expected_copied_text_value');

// Optional: Log the clipboard value to the browser console
await page.evaluate(r => console.log(r), result);
  1. Replace expected_copied_text_value with the expected value you want to assert against.

이 스텝이 실행되는 동안 컴퓨터에서 다른 복사/붙여넣기 작업을 수행하면, 해당 내용이 캡처될 수 있습니다.