1
- # playwright-testing-library
1
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
2
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3
+
4
+ - [ playwright-testing-library] ( #playwright-testing-library )
5
+ - [ ✨ Features] ( #-features )
6
+ - [ 🌱 Getting Started] ( #-getting-started )
7
+ - [ 1. Install] ( #1-install )
8
+ - [ 2a. Use _ standalone queries_ ] ( #2a-use-_standalone-queries_ )
9
+ - [ 2b. Use _ extensions_ ] ( #2b-use-_extensions_ )
10
+ - [ 🔌 API] ( #-api )
11
+ - [ Known Limitations] ( #known-limitations )
12
+ - [ Special Thanks] ( #special-thanks )
13
+ - [ Related Playwright Test Utilities] ( #related-playwright-test-utilities )
14
+ - [ LICENSE] ( #license )
15
+
16
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
17
+
18
+ <div align =" center " >
19
+ <br >
20
+ <header >
21
+ <img src="https://user-images.githubusercontent.com/288160/126050717-dd76eb80-ef06-40e0-97e8-72c20c9f8f20.png" height="64" />
22
+ </header >
23
+ <br >
24
+ <h1 >playwright-testing-library</h1 >
25
+ <p >🔍 Find elements in <strong >playwright</strong > like your users will with <strong >@testing-libary/dom</strong ></p >
26
+ </div >
27
+
28
+ <div align =" center " >
2
29
3
30
[ ![ Package Version] [ npm-badge ]] [ npm-link ]
4
31
[ ![ Build Status] [ travis-badge ]] [ travis-link ]
5
32
[ ![ Test Coverage] [ codecov-badge ]] [ codecov-link ]
6
33
[ ![ Dependencies Status] [ david-badge ]] [ david-link ]
34
+ [ ![ MIT License] [ license-badge ]] [ license-link ] <br >
35
+ [ ![ Code Style] [ prettier-badge ]] [ prettier-link ]
7
36
[ ![ Conventional Commits] [ conventional-commits-badge ]] [ conventional-commits-link ]
37
+ [ ![ Maintenance] [ maintenance-badge ]] [ maintenance-link ]
38
+
39
+ </div >
8
40
9
- [ playwright ] ( https://github.com/microsoft/playwright ) + [ @ testing-library/dom ] ( https://github.com/testing-library/dom-testing-library ) = 💖
41
+ < br >
10
42
11
- All your favorite user-centric querying functions from ** @ testing-library/react ** & ** @ testing-library/library ** available from Playwright!
43
+ ## ✨ Features
12
44
13
45
> ⚠️ Note: this is a fork of [ pptr-testing-library] ( https://github.com/testing-library/pptr-testing-library ) modified to accomodate for some subtle API differences.
14
46
15
- ## Contents
47
+ All of your favorite user-centric querying functions from ** @ testing-library/react ** and ** @ testing-library/dom ** available from Playwright!
16
48
17
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
18
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
49
+ - Standalone queries — ** ` playwright-testing-library ` ** or...
50
+ - Playwright extensions — ** ` playwright-testing-library/extend ` **
51
+ - Asynchronous assertion helper (via ** [ wait-for-expect] ( https://github.com/TheBrainFamily/wait-for-expect ) ** )
19
52
20
- - [ Install] ( #install )
21
- - [ Use] ( #use )
22
- - [ API] ( #api )
23
- - [ Known Limitations] ( #known-limitations )
24
- - [ Special Thanks] ( #special-thanks )
25
- - [ Related Playwright Test Utilities] ( #related-playwright-test-utilities )
26
- - [ LICENSE] ( #license )
53
+ ## 🌱 Getting Started
27
54
28
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
55
+ ### 1. Install
56
+
57
+ ``` bash
58
+ npm install --save-dev playwright-testing-library
59
+ ```
29
60
30
- ## Install
61
+ or
31
62
32
- ` npm install --save-dev playwright-testing-library `
63
+ ``` bash
64
+ yarn add --dev playwright-testing-library
65
+ ```
33
66
34
- ## Use
67
+ ### 2a. Use _ standalone queries _
35
68
36
69
``` js
37
70
const {webkit } = require (' playwright' ) // or 'firefox' or 'chromium'
54
87
await waitFor (() => getByText ($document, ' Loading...' ))
55
88
```
56
89
57
- A little too un-playwright for you? We've got prototype-mucking covered too :)
90
+ ### 2b. Use _ extensions _
58
91
59
92
``` js
60
93
const {webkit } = require (' playwright' ) // or 'firefox' or 'chromium'
@@ -63,6 +96,8 @@ require('playwright-testing-library/extend')
63
96
const browser = await webkit .launch ()
64
97
const page = await browser .newPage ()
65
98
99
+ deCall (' editor.action.formatDocument' )
100
+ // getDocument is added to prototype of Page
66
101
// getDocument is added to prototype of Page
67
102
const $document = await page .getDocument ()
68
103
// query methods are added directly to prototype of ElementHandle
@@ -72,16 +107,29 @@ const {getByText} = $form.getQueriesForElement()
72
107
// ...
73
108
```
74
109
75
- ## API
110
+ ## 🔌 API
111
+
112
+ Unique methods, not part of ** @testing-library/dom **
76
113
77
- Unique methods, not part of ` @testing-library/dom `
114
+ - Get an ` ElementHandle ` for the document
78
115
79
- - ` getDocument(page: playwright.Page): ElementHandle ` - get an ElementHandle for the document
80
- - ` wait(conditionFn: () => {}): Promise<{}> ` - wait for the condition to not throw (wrapper around ` waitForExpect ` )
116
+ ``` ts
117
+ getDocument (page : playwright .Page ): ElementHandle
118
+ ```
119
+
120
+ - Wait for an assertion (wrapper around [ wait-for-expect] ( https://github.com/TheBrainFamily/wait-for-expect ) )
121
+
122
+ ``` ts
123
+ waitFor (
124
+ expectation : () => void | Promise < void > ,
125
+ timeout ?: number ,
126
+ interval ?: number
127
+ ): Promise < {}>
128
+ ```
81
129
82
130
---
83
131
84
- [ @testing-library/dom API ] ( https://github.com/testing-library/dom-testing-library#usage ) . All ` get* ` / ` query* ` methods are supported.
132
+ The ** [ @testing-library/dom ] ( https://github.com/testing-library/dom-testing-library#usage ) ** — All ** ` get* ` ** and ** ` query* ` ** methods are supported.
85
133
86
134
- ` getQueriesForElement(handle: ElementHandle): ElementHandle & QueryUtils ` - extend the input object with the query API and return it
87
135
- ` getNodeText(handle: ElementHandle): Promise<string> ` - get the text content of the element
@@ -150,13 +198,19 @@ Unique methods, not part of `@testing-library/dom`
150
198
151
199
MIT
152
200
153
- [ npm-link ] : https://www.npmjs.com/package/playwright-testing-library
154
- [ npm-badge ] : https://img.shields.io/npm/v/playwright-testing-library
155
- [ travis-link ] : https://travis-ci.org/github/hoverinc/playwright-testing-library
156
- [ travis-badge ] : https://travis-ci.org/hoverinc/playwright-testing-library.svg?branch=main
157
- [ codecov-link ] : https://codecov.io/gh/hoverinc/playwright-testing-library
158
201
[ codecov-badge ] : https://codecov.io/gh/hoverinc/playwright-testing-library/branch/main/graph/badge.svg
159
- [ conventional-commits- link] : https://conventionalcommits.org
202
+ [ codecov- link] : https://codecov.io/gh/hoverinc/playwright-testing-library
160
203
[ conventional-commits-badge ] : https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg
161
- [ david- link] : https://david-dm .org/hoverinc/playwright-testing-library
204
+ [ conventional-commits- link] : https://conventionalcommits .org
162
205
[ david-badge ] : https://david-dm.org/hoverinc/playwright-testing-library.svg
206
+ [ david-link ] : https://david-dm.org/hoverinc/playwright-testing-library
207
+ [ license-badge ] : https://img.shields.io/npm/l/@hover/javascript.svg
208
+ [ license-link ] : https://github.com/hoverinc/hover-javascript/blob/master/LICENSE
209
+ [ maintenance-badge ] : https://img.shields.io/badge/maintenance-active-247ddc?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAcCAYAAACUJBTQAAAB1ElEQVRIibWWPUtdQRCGH0VNF/wCCVjYCxr/gZWdhYVgLQYbm/wACTYxxA8SSBDtbKwUbfQWkiJFAgkkmHBBY6U2CXaCGlDDG1buxePOnt17bsgD28zOzjtnZvbuRVKR1SFpVdKepEe1njOGnOWCz0q60B1lSa05/oVE2iTNSfqdCZ7lSyWB0NmkSJekeUmXJqzlayWZUJxckUUTJs23mFAjlhNjSdMHfAQ6g54hZUnDdXyN44ek7iKNH4w0PMaeX7pQ8Ox6HQkWww3Dw1hPWoAJ4BxoB4aNR5oB4APQ5vekUdITSceZDLcreyORrGPcfpEL0CBpVNJRwLmUSWLS7NbGpju8FXEteT2qR+jQ9aS3QK2XgUljjXPpRC6iLpYV4KmxRghNVy28Aqb+t4jjLbBhrAH+RcRxZSwBUiINxlIHKZE/xlIHTTlHBDwHjoDPwHtgF/gEnBnvFJVfzSrXkpYyfxKGvIu14F3ONXP1LOWmzEPjpuWl92j55XyQyDnEjRN5AbwD9gMOPkV7tAPMOJE3ZuuOFmOpjS3gGfCdQDl8fgGnGVtzwt8F7wdGqgKOvOmq4iarB3gMjAFlb78qug5MAwehIO4tKViJe4wDP4FSrgfwF/ntR8JxRSf3AAAAAElFTkSuQmCC
210
+ [ maintenance-link ] : https://github.com/hoverinc/hover-javascript#maintenance
211
+ [ npm-badge ] : https://img.shields.io/npm/v/playwright-testing-library
212
+ [ npm-link ] : https://www.npmjs.com/package/playwright-testing-library
213
+ [ prettier-badge ] : https://img.shields.io/badge/code_style-prettier-ff69b4.svg?logo=prettier
214
+ [ prettier-link ] : https://prettierjs.org/en/download/
215
+ [ travis-badge ] : https://travis-ci.org/hoverinc/playwright-testing-library.svg?branch=main
216
+ [ travis-link ] : https://travis-ci.org/github/hoverinc/playwright-testing-library
0 commit comments