1
1
import * as path from 'path'
2
- import * as puppeteer from 'puppeteer '
2
+ import * as playwright from 'playwright '
3
3
4
4
describe ( 'lib/extend.ts' , ( ) => {
5
- let browser : puppeteer . Browser
6
- let page : puppeteer . Page
7
- let document : puppeteer . ElementHandle
5
+ let browser : playwright . ChromiumBrowser
6
+ let page : playwright . Page
7
+ let document : playwright . ElementHandle
8
8
9
9
it ( 'should require without error' , async ( ) => {
10
10
await import ( '../lib/extend' )
11
11
} )
12
12
13
- it ( 'should launch puppeteer ' , async ( ) => {
14
- browser = await puppeteer . launch ( { args : [ '--no-sandbox' , '--disable-setuid-sandbox' ] } )
13
+ it ( 'should launch playwright ' , async ( ) => {
14
+ browser = await playwright . chromium . launch ( { args : [ '--no-sandbox' , '--disable-setuid-sandbox' ] } )
15
15
page = await browser . newPage ( )
16
16
await page . goto ( `file://${ path . join ( __dirname , 'fixtures/page.html' ) } ` )
17
17
} )
18
18
19
- it ( 'should extend puppeteer ElementHandle' , async ( ) => {
19
+ it ( 'should extend playwright ElementHandle' , async ( ) => {
20
20
document = await page . getDocument ( )
21
21
expect ( typeof document . queryAllByAltText ) . toBe ( 'function' )
22
22
} )
@@ -25,21 +25,21 @@ describe('lib/extend.ts', () => {
25
25
const element = await document . queryByText ( 'Hello h1' )
26
26
expect ( element ) . toBeTruthy ( )
27
27
/* istanbul ignore next */
28
- expect ( await page . evaluate ( el => el . textContent , element ) ) . toEqual ( 'Hello h1' )
28
+ expect ( await page . evaluate ( el => el ? .textContent , element ) ) . toEqual ( 'Hello h1' )
29
29
} )
30
30
31
31
it ( 'should use the new v3 methods' , async ( ) => {
32
32
const element = await document . queryByRole ( 'presentation' )
33
33
expect ( element ) . toBeTruthy ( )
34
34
/* istanbul ignore next */
35
- expect ( await page . evaluate ( el => el . textContent , element ) ) . toContain ( 'Layout table' )
35
+ expect ( await page . evaluate ( el => el ? .textContent , element ) ) . toContain ( 'Layout table' )
36
36
} )
37
37
38
38
it ( 'should handle regex matching' , async ( ) => {
39
39
const element = await document . queryByText ( / H e L l O h ( 1 | 7 ) / i)
40
40
expect ( element ) . toBeTruthy ( )
41
41
/* istanbul ignore next */
42
- expect ( await page . evaluate ( el => el . textContent , element ) ) . toEqual ( 'Hello h1' )
42
+ expect ( await page . evaluate ( el => el ? .textContent , element ) ) . toEqual ( 'Hello h1' )
43
43
} )
44
44
45
45
it ( 'should handle the get* methods' , async ( ) => {
@@ -56,9 +56,7 @@ describe('lib/extend.ts', () => {
56
56
await scope ! . getByTitle ( 'missing' )
57
57
fail ( )
58
58
} catch ( err ) {
59
- err . message = err . message
60
- . replace ( / ( \s * a t .* ( \n | $ ) ) + / gm, '\n <stack>:X:X' )
61
- . replace ( 'TestingLibraryElementError' , 'Error' ) // Puppeteer 1.7 returns a generic error
59
+ err . message = err . message . replace ( / ( \s * a t .* ( \n | $ ) ) + / gm, '\n <stack>:X:X' )
62
60
expect ( err . message ) . toMatchSnapshot ( )
63
61
}
64
62
} )
@@ -86,7 +84,7 @@ describe('lib/extend.ts', () => {
86
84
const scope = await document . $ ( '#scoped' )
87
85
const element = await scope ! . queryByText ( / H e l l o / )
88
86
/* istanbul ignore next */
89
- expect ( await page . evaluate ( el => el . textContent , element ) ) . toEqual ( 'Hello h3' )
87
+ expect ( await page . evaluate ( el => el ? .textContent , element ) ) . toEqual ( 'Hello h3' )
90
88
} )
91
89
92
90
it ( 'should get text content' , async ( ) => {
0 commit comments