Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vrknetha committed Dec 7, 2024
0 parents commit 030e102
Show file tree
Hide file tree
Showing 14 changed files with 3,719 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
root: true,
env: {
browser: true,
es2021: true,
node: true
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: './tsconfig.json'
},
plugins: ['@typescript-eslint', 'prettier'],
rules: {
'@typescript-eslint/explicit-function-return-type': ['error', {
allowExpressions: true,
allowTypedFunctionExpressions: true
}],
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-unused-vars': 'error',
'prettier/prettier': 'error'
},
ignorePatterns: ['dist/**', 'node_modules/**', '*.js']
};
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Install Playwright browsers
run: npx playwright install --with-deps

- name: Build
run: npm run build

- name: Lint
run: npm run lint

- name: Run tests
run: npm test

- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: playwright-report/
retention-days: 30
37 changes: 37 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Publish Package

on:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Lint
run: npm run lint

- name: Test
run: |
npx playwright install --with-deps
npm test
- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Dependencies
node_modules/

# Build output
dist/

# Playwright
test-results/
playwright-report/
playwright/.cache/
/blob-report/
/test-results/
/playwright/.auth/

# IDE
.vscode/
.idea/
*.iml

# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# OS
.DS_Store
Thumbs.db

# Coverage
coverage/

# Environment variables
.env
.env.local
.env.*.local

# Temporary files
*.swp
*.swo
*~

# Package files
*.tgz
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"arrowParens": "avoid"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 playwright-clipboard

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
133 changes: 133 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Playwright Clipboard

A comprehensive solution for testing clipboard operations in web applications using Playwright. This package provides both standard clipboard operations and precise word-level text manipulation capabilities.

## Installation

```bash
npm install --save-dev playwright-clipboard
```

## Features

- Basic clipboard operations (copy, paste, cut)
- Text selection operations
- Word-level operations
- Clipboard content management
- Cross-browser compatibility
- TypeScript support

## Usage

### Basic Operations

```typescript
import { test } from '@playwright/test';
import { PlaywrightClipboard } from 'playwright-clipboard';

test('basic clipboard operations', async ({ page }) => {
const clipboard = new PlaywrightClipboard(page);

// Copy text from source
await clipboard.copy('#source');

// Paste text to target
await clipboard.paste('#target');

// Cut text
await clipboard.cut('#editor');

// Get clipboard content
const content = await clipboard.getClipboardContent();

// Set clipboard content
await clipboard.setClipboardContent('Hello World');
});
```

### Word-Level Operations

```typescript
test('word-level operations', async ({ page }) => {
const clipboard = new PlaywrightClipboard(page);

// Copy specific words
await clipboard.copyBetweenWords('#editor', 1, 3);

// Paste after a specific word
await clipboard.pasteAfterWord('#editor', 2);

// Paste before a specific word
await clipboard.pasteBeforeWord('#editor', 0);

// Replace a word
await clipboard.replaceWord('#editor', 1);
});
```

### Selection Operations

```typescript
test('selection operations', async ({ page }) => {
const clipboard = new PlaywrightClipboard(page);

// Select all text
await clipboard.selectAll('#editor');

// Select specific range
await clipboard.select('#editor', 0, 10);

// Select word range
await clipboard.selectWordRange('#editor', 1, 3);

// Get selected text
const selectedText = await clipboard.getSelectedWords();
});
```

## API Reference

### Constructor

```typescript
constructor(page: Page, options?: ClipboardOptions)
```

### Methods

- `copy(selector: string): Promise<void>`
- `paste(selector: string): Promise<void>`
- `cut(selector: string): Promise<void>`
- `getClipboardContent(): Promise<string>`
- `setClipboardContent(text: string): Promise<void>`
- `selectAll(selector: string): Promise<void>`
- `select(selector: string, start: number, end: number): Promise<void>`
- `copyBetweenWords(selector: string, startWordIndex: number, endWordIndex: number): Promise<void>`
- `pasteAfterWord(selector: string, wordIndex: number): Promise<void>`
- `pasteBeforeWord(selector: string, wordIndex: number): Promise<void>`
- `replaceWord(selector: string, wordIndex: number): Promise<void>`
- `selectWordRange(selector: string, startIndex: number, endIndex: number): Promise<void>`
- `getSelectedWords(): Promise<string>`
- `getWordBoundaries(selector: string, wordIndex: number): Promise<{ start: number; end: number }>`

## Error Handling

The package includes comprehensive error handling with specific error types:

- `COPY_ERROR`
- `PASTE_ERROR`
- `CLIPBOARD_ACCESS_DENIED`
- `SELECTION_FAILED`
- `INVALID_WORD_INDEX`
- `WORD_BOUNDARY_ERROR`
- `EMPTY_SELECTION`
- `PASTE_POSITION_ERROR`

## Requirements

- Node.js >= 18.0.0
- Playwright >= 1.40.0

## License

MIT
Loading

0 comments on commit 030e102

Please sign in to comment.