From 79d8f001d31617deeaba855a4705b66880d4b41e Mon Sep 17 00:00:00 2001 From: vrknetha Date: Sun, 8 Dec 2024 01:06:42 +0530 Subject: [PATCH] updates README with fixtures --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index c2e9c6a..f3dc1ea 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,52 @@ npm install --save-dev playwright-clipboard ## Examples +### Using with Fixtures + +```typescript +import { test as base, expect } from '@playwright/test'; +import { PlaywrightClipboard } from 'playwright-clipboard'; + +// Extend the base test fixture with clipboard +interface ClipboardFixtures { + clipboard: PlaywrightClipboard; +} + +const test = base.extend({ + clipboard: async ({ page }, use) => { + const clipboard = new PlaywrightClipboard(page); + await use(clipboard); + }, +}); + +// Now use clipboard in your tests +test('using clipboard fixture', async ({ page, clipboard }) => { + await page.goto('http://localhost:8080'); + + // Use clipboard methods directly + await clipboard.copy('#source'); + await clipboard.paste('#target'); + + const result = await page.inputValue('#target'); + expect(result).toBe('Hello World'); +}); + +// Test rich text with browser context +test('rich text with browser context', async ({ page, clipboard, browserName }) => { + await page.goto('http://localhost:8080'); + + await clipboard.copyRichText('#richSource'); + await clipboard.pasteRichText('#richTarget'); + + if (browserName === 'webkit') { + const text = await page.$eval('#richTarget', el => el.textContent?.trim() || ''); + expect(text).toBe('This is bold text'); + } else { + const html = await page.$eval('#richTarget', el => el.innerHTML.trim()); + expect(html).toContain('bold'); + } +}); + ### Basic Operations ```typescript