Skip to content

Commit

Permalink
updates README with fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
vrknetha committed Dec 7, 2024
1 parent a54975d commit 79d8f00
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClipboardFixtures>({
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('<b>bold</b>');
}
});

### Basic Operations

```typescript
Expand Down

0 comments on commit 79d8f00

Please sign in to comment.