playwright-indexeddb
v1.0.0
Published
Access and manipulate IndexedDB within Playwright tests
Downloads
84
Maintainers
Readme
playwright-indexeddb
A powerful and type-safe library for interacting with IndexedDB in Playwright tests.
Features
- 🎭 Seamless integration with Playwright
- 📦 Full TypeScript support
- 🔄 Complete CRUD operations
- 🧪 Comprehensive test coverage
- 🚀 Promise-based API
- 💪 Type-safe operations
Installation
npm install playwright-indexeddb
Usage
import { test } from "@playwright/test";
import { PlaywrightIndexedDB } from "playwright-indexeddb";
test("example test", async ({ page }) => {
// Initialize IndexedDB
const db = new PlaywrightIndexedDB(page, {
dbName: "myDatabase",
storeName: "myStore",
version: 1, // optional, defaults to 1
});
// Put an item
await db.putItem({ id: 1, name: "Test Item" }, 1);
// Get an item
const item = await db.getItem(1);
// Get all items
const allItems = await db.getAllItems();
// Delete an item
await db.deleteItem(1);
// Clear all items
await db.clear();
});
API Reference
Constructor
new PlaywrightIndexedDB(page: Page, options: IndexedDBOptions)
Options
dbName
: string - Name of the IndexedDB databasestoreName
: string - Name of the object storeversion?
: number - Database version (optional, defaults to 1)
Methods
getAllItems<T>()
Returns all items from the store as an array of type T.
getItem<T>(key: IDBValidKey)
Returns a single item of type T for the given key, or null if not found.
putItem<T>(item: T, key?: IDBValidKey)
Stores an item in the database. If key is provided, it will be used as the item's key.
deleteItem(key: IDBValidKey)
Deletes the item with the specified key.
clear()
Removes all items from the store.
Development
# Install dependencies
npm install
# Run tests
npm test
# Run linter
npm run lint
# Build package
npm run build
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
MIT
Support
If you find any bugs or have feature requests, please create an issue in the GitHub repository.