{"id":46593607,"url":"https://github.com/umutayb/pw-element-repository","last_synced_at":"2026-03-10T17:01:04.676Z","repository":{"id":342083753,"uuid":"1172669482","full_name":"Umutayb/pw-element-repository","owner":"Umutayb","description":"A lightweight, robust package that decouples your Playwright UI selectors from your test code. ","archived":false,"fork":false,"pushed_at":"2026-03-06T10:05:12.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-09T18:41:22.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/pw-element-repository?activeTab=readme","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Umutayb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-04T15:12:09.000Z","updated_at":"2026-03-09T10:21:27.000Z","dependencies_parsed_at":"2026-03-09T16:00:34.821Z","dependency_job_id":null,"html_url":"https://github.com/Umutayb/pw-element-repository","commit_stats":null,"previous_names":["umutayb/pw-element-repository"],"tags_count":2,"template":true,"template_full_name":null,"purl":"pkg:github/Umutayb/pw-element-repository","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umutayb%2Fpw-element-repository","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umutayb%2Fpw-element-repository/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umutayb%2Fpw-element-repository/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umutayb%2Fpw-element-repository/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Umutayb","download_url":"https://codeload.github.com/Umutayb/pw-element-repository/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Umutayb%2Fpw-element-repository/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30343720,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T15:55:29.454Z","status":"ssl_error","status_checked_at":"2026-03-10T15:54:58.440Z","response_time":106,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-03-07T14:09:11.384Z","updated_at":"2026-03-10T17:01:04.668Z","avatar_url":"https://github.com/Umutayb.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Playwright Element Repository\n\n[![NPM Version](https://img.shields.io/npm/v/pw-element-repository?color=rgb(88%2C%20171%2C%2070))](https://www.npmjs.com/package/pw-element-repository)\n\nA lightweight, robust package that decouples your Playwright UI selectors from your test code. By externalizing locators into a central JSON repository, you make your test automation framework cleaner, easier to maintain, and accessible to non-developers.\n\n## 📦 Installation\n\nInstall the package via your preferred package manager:\n\n```bash\nnpm i pw-element-repository\n```\n\n**Peer Dependencies:**\nThis package requires `@playwright/test` or `playwright` to be installed in your project.\n\n## 🚀 What is it good for?\n\n* **Zero Hardcoded Selectors:** Keep your Page Objects and Step Definitions completely free of complex DOM queries.\n* **Dynamic Parsing:** Automatically converts your JSON configuration into native Playwright CSS, XPath, ID, or Text selectors.\n* **Smart Locators:** Built-in methods for handling arrays, randomized element selection (great for catalog/PLP testing), and text-filtering.\n* **Soft Waiting:** Seamlessly waits for elements to attach and become visible before returning a locator to prevent flake.\n\n## 🏗️ Configuration\n\nCreate a JSON file in your project to hold your selectors. The file must adhere to the standard schema:\n\n**`locators.json`**\n\n```json\n{\n  \"pages\": [\n    {\n      \"name\": \"HomePage\",\n      \"elements\": [\n        {\n          \"elementName\": \"search-input\",\n          \"selector\": { \"css\": \"input[name='search']\" }\n        },\n        {\n          \"elementName\": \"submit-button\",\n          \"selector\": { \"id\": \"btn-submit\" }\n        }\n      ]\n    },\n    {\n      \"name\": \"ProductList\",\n      \"elements\": [\n        {\n          \"elementName\": \"product-cards\",\n          \"selector\": { \"xpath\": \"//article[@class='product']\" }\n        }\n      ]\n    }\n  ]\n}\n\n```\n\n## 💻 Usage\n\nYou can initialize the `ElementRepository` either by passing the **file path** to your JSON, or by passing the **parsed JSON object** directly.\n\n### Initialization\n\n```typescript\nimport { test } from '@playwright/test';\nimport { ElementRepository } from 'pw-element-repository';\n\n// Option A: Pass the path to your JSON (relative to your project root)\nconst repo = new ElementRepository('tests/data/locators.json', 15000);\n\n// Option B: Import the JSON directly (requires resolveJsonModule in tsconfig)\nimport locatorData from '../data/locators.json';\nconst repo = new ElementRepository(locatorData, 15000);\n\n```\n\n### Retrieving Elements\n\nThe repository exposes clean, asynchronous methods that return Playwright `Locator` objects, ready for interaction.\n\n```typescript\ntest('Search and select random product', async ({ page }) =\u003e {\n  await page.goto('/');\n\n  // 1. Get a standard element\n  const searchInput = await repo.get(page, 'HomePage', 'search-input');\n  await searchInput.fill('Trousers');\n\n  const submitBtn = await repo.get(page, 'HomePage', 'submit-button');\n  await submitBtn.click();\n\n  // 2. Select a random element from a list\n  const randomProduct = await repo.getRandom(page, 'ProductList', 'product-cards');\n  await randomProduct?.click();\n  \n  // 3. Find a specific element by text within a list\n  const specificProduct = await repo.getByText(page, 'ProductList', 'product-cards', 'Blue Chinos');\n  await specificProduct?.click();\n});\n\n```\n\n## 🛠️ API Reference\n\n### `get(page, pageName, elementName)`\n\nReturns a single Playwright Locator. Waits for the selector to attach to the DOM based on your configured timeout.\n\n### `getAll(page, pageName, elementName)`\n\nReturns an array of resolved Locator handles (`Locator[]`). Useful when you need to iterate over multiple elements.\n\n### `getRandom(page, pageName, elementName, strict?)`\n\nCounts the matching elements and randomly selects one. Safely waits for the specific randomized element to become visible.\n\n### `getByText(page, pageName, elementName, desiredText, strict?)`\n\nReturns the first Locator matching the mapped selector that also contains the `desiredText`.\n\n### `getSelector(pageName, elementName)`\n\nReturns the raw string selector mapped to the given element (e.g., \"css=input[name='search']\" or \"xpath=//div\"). This is a synchronous method primarily useful for debugging, custom logging, or passing raw selector strings directly into native Playwright APIs that require strings instead of Locator objects.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumutayb%2Fpw-element-repository","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumutayb%2Fpw-element-repository","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumutayb%2Fpw-element-repository/lists"}