{"id":19845381,"url":"https://github.com/qavajs/po-playwright","last_synced_at":"2025-05-01T21:30:31.113Z","repository":{"id":60844084,"uuid":"540427577","full_name":"qavajs/po-playwright","owner":"qavajs","description":"library for plain-english access to page object","archived":false,"fork":false,"pushed_at":"2024-09-17T09:18:37.000Z","size":312,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-17T11:53:23.757Z","etag":null,"topics":["qa","test-automation","testing"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qavajs.png","metadata":{"files":{"readme":"README.MD","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2022-09-23T12:23:33.000Z","updated_at":"2024-09-17T09:18:20.000Z","dependencies_parsed_at":"2024-03-16T16:23:58.637Z","dependency_job_id":"f5e5a1d4-ce5b-4e25-a8ae-9a30f0c46d57","html_url":"https://github.com/qavajs/po-playwright","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qavajs%2Fpo-playwright","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qavajs%2Fpo-playwright/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qavajs%2Fpo-playwright/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qavajs%2Fpo-playwright/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qavajs","download_url":"https://codeload.github.com/qavajs/po-playwright/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224278484,"owners_count":17285080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["qa","test-automation","testing"],"created_at":"2024-11-12T13:07:32.804Z","updated_at":"2025-05-01T21:30:31.103Z","avatar_url":"https://github.com/qavajs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## @qavajs/po-playwright\n\n@qavajs library provides the ability to create hierarchical page objects and access elements using plain-english selectors.\nWorks on top of Playwright.\n\n`npm install @qavajs/po-playwright`\n\n## Usage\n\nLib provides getElement method that resolves plain-english selector and return playwright locator.\n```javascript\nconst { po } = require('@qavajs/po-playwright');\n\nWhen(/^click '(.+)'$/, async function (alias) {\n    const element = await po.getElement(alias);\n    await element.click();\n});\n```\n\n```gherkin\nWhen click '#1 of Multiple Component \u003e Child Item'\n```\n\nLib provides capability to get single element from collection by index (#index of Collection) or inner text (#text in Collection).\n\n## Create page object\n\nLib provides two methods $ and $$ that allow registering elements and collections.\nAn element can be defined in form of webdriverIO selector or as an instance of the component class. \n\nEach not top-level component should have selector element in form of webdriverIO selector.\n```javascript\nconst { $, $$ } = require('@qavajs/po-playwright');\n\nclass MultipleComponent {\n    selector = '.list-components li';\n    ChildItem = $('div');\n}\n\nclass SingleComponent {\n    selector = '.container';\n    ChildItem = $('.child-item');\n}\n\nclass App {\n    SingleElement = $('.single-element');\n    List = $$('.list li');\n    SingleComponent = $(new SingleComponent());\n    MultipleComponents = $$(new MultipleComponent());\n}\n\nmodule.exports = new App();\n```\n## Register PO\nBefore using po object need to be initiated and hierarchy of elements needs to be registered\nThe best place to do it is cucumber-js Before hook\n\n```javascript\nconst { po } = require('@qavajs/po-playwright');\nconst pos = require('./app.js');\nBefore(async function() {\n    po.init(page, { timeout: 10000 });  // page is an instance of playwright page\n    po.register(pos); // pos is page object hierarchy\n});\n```\n\n## Ignore hierarchy\nIn case if child element and parent component doesn't have hierarchy dependency\nit's possible to pass extra parameter _ignoreHierarchy_ parameter to start traverse from root\n\n```javascript\nclass ComponentThatDescribesNotWellDesignedDOMTree {\n    selector = '.container';\n    //ignoreHierarchy will ignore component selector .container and start traverse from root\n    ChildItem = $('.child-item', { ignoreHierarchy: true }); \n}\n```\n\n## Optional selector property\nIf selector property is not provided for Component then parent element will be returned\n\n```javascript\nclass ParentComponent {\n    selector = '.container';\n    ChildComponent = $(new ChildComponent()); \n}\n\nclass ChildComponent {\n    //Element will be searched in parent .container element\n    Element = $('.someElement');\n}\n```\n\n## Dynamic selectors\nIn case you need to generate selector based on some data you can use dynamic selectors\n\n```javascript\nconst { Selector } = require('@qavajs/po-playwright');\n\nclass Component {\n    selector = '.container';\n    Element = $(Selector((index =\u003e `div:nth-child(${index})`))); // function should return valid selector \n}\n```\n\nThen you can pass parameter to this function from Gherkin file\n\n```gherkin\nWhen I click 'Component \u003e Element (2)'\n```\n\n## Native framework selectors\nIt is also possible to use driver-built capabilities to return element. You can pass handler that has access to\ncurrent `page` and current locator. \n\n```javascript\nconst { NativeSelector } = require('@qavajs/po-playwright');\n\nclass Component {\n    selector = '.container';\n    Element = $(NativeSelector(page =\u003e page.getByText(`some text`)));\n    IFrame = $(NativeSelector((_, parent) =\u003e parent.frameLocator('#iframe').getByText(`some text`)));\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqavajs%2Fpo-playwright","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqavajs%2Fpo-playwright","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqavajs%2Fpo-playwright/lists"}