@@ -51,7 +51,7 @@ yarn add --dev playwright-testing-library
5151
5252``` js
5353const {webkit } = require (' playwright' ) // or 'firefox' or 'chromium'
54- const {getDocument , queries , waitFor } = require (' playwright-testing-library' )
54+ const {getDocument , queries } = require (' playwright-testing-library' )
5555
5656const {getByTestId , getByLabelText } = queries
5757
@@ -60,14 +60,17 @@ const page = await browser.newPage()
6060
6161// Grab ElementHandle for document
6262const $document = await getDocument (page)
63+
6364// Your favorite query methods are available
6465const $form = await getByTestId ($document, ' my-form' )
65- // returned elements are ElementHandles too!
66+
67+ // Returned elements are ElementHandles too!
6668const $email = await getByLabelText ($form, ' Email' )
67- // interact with playwright like usual
69+
70+ // Interact with playwright like usual
6871await $email .type (' playwright@example.com' )
69- // waiting works too!
70- await waitFor (() => getByText ($document, ' Loading ...' ))
72+
73+ // ...
7174```
7275
7376### 2b. Use _ extensions_
@@ -79,14 +82,20 @@ require('playwright-testing-library/extend')
7982const browser = await webkit .launch ()
8083const page = await browser .newPage ()
8184
82- deCall (' editor.action.formatDocument' )
83- // getDocument is added to prototype of Page
84- // getDocument is added to prototype of Page
85+ // Grab document with `getDocument`, which is added to the prototype of `Paqe`
8586const $document = await page .getDocument ()
86- // query methods are added directly to prototype of ElementHandle
87+
88+ // Query methods are added directly to prototype of `ElementHandle`
8789const $form = await $document .getByTestId (' my-form' )
88- // destructing works if you explicitly call getQueriesForElement
89- const {getByText } = $form .getQueriesForElement ()
90+
91+ // Scope queries with `getQueriesForElement`
92+ const {getByLabelText } = $form .getQueriesForElement ()
93+
94+ const $email = await getByLabelText (' Email' )
95+
96+ // Interact with Playwright like usual
97+ await $email .type (' playwright@example.com' )
98+
9099// ...
91100```
92101
0 commit comments