@@ -22,6 +22,7 @@ const readFileAsync = util.promisify(fs.readFile);
22
22
const rmAsync = util . promisify ( require ( 'rimraf' ) ) ;
23
23
const mkdtempAsync = util . promisify ( fs . mkdtemp ) ;
24
24
const statAsync = util . promisify ( fs . stat ) ;
25
+ const { makeUserDataDir, removeUserDataDir } = require ( '../utils' ) ;
25
26
26
27
const TMP_FOLDER = path . join ( os . tmpdir ( ) , 'pw_tmp_folder-' ) ;
27
28
@@ -33,24 +34,60 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
33
34
const { it, fit, xit, dit} = testRunner ;
34
35
const { beforeAll, beforeEach, afterAll, afterEach} = testRunner ;
35
36
36
- describe ( 'CrPlaywright' , function ( ) {
37
- describe ( 'Playwright.launch webSocket option' , function ( ) {
38
- it ( 'should support the remote-debugging-port argument' , async ( ) => {
39
- const options = Object . assign ( { } , defaultBrowserOptions ) ;
40
- const browserServer = await playwright . launchServer ( { ...options , port : 0 } ) ;
41
- const browser = await playwright . connect ( { wsEndpoint : browserServer . wsEndpoint ( ) } ) ;
42
- expect ( browserServer . wsEndpoint ( ) ) . not . toBe ( null ) ;
43
- const page = await browser . newPage ( ) ;
44
- expect ( await page . evaluate ( '11 * 11' ) ) . toBe ( 121 ) ;
45
- await page . close ( ) ;
46
- await browserServer . close ( ) ;
47
- } ) ;
48
- it ( 'should throw with remote-debugging-pipe argument and webSocket' , async ( ) => {
49
- const options = Object . assign ( { } , defaultBrowserOptions ) ;
50
- options . args = [ '--remote-debugging-pipe' ] . concat ( options . args || [ ] ) ;
51
- const error = await playwright . launchServer ( options ) . catch ( e => e ) ;
52
- expect ( error . message ) . toContain ( 'Playwright manages remote debugging connection itself' ) ;
53
- } ) ;
37
+ const headfulOptions = Object . assign ( { } , defaultBrowserOptions , {
38
+ headless : false
39
+ } ) ;
40
+ const extensionPath = path . join ( __dirname , '..' , 'assets' , 'simple-extension' ) ;
41
+ const extensionOptions = Object . assign ( { } , defaultBrowserOptions , {
42
+ headless : false ,
43
+ args : [
44
+ `--disable-extensions-except=${ extensionPath } ` ,
45
+ `--load-extension=${ extensionPath } ` ,
46
+ ] ,
47
+ } ) ;
48
+
49
+ describe ( 'launcher' , function ( ) {
50
+ it ( 'should throw with remote-debugging-pipe argument' , async ( ) => {
51
+ const options = Object . assign ( { } , defaultBrowserOptions ) ;
52
+ options . args = [ '--remote-debugging-pipe' ] . concat ( options . args || [ ] ) ;
53
+ const error = await playwright . launchServer ( options ) . catch ( e => e ) ;
54
+ expect ( error . message ) . toContain ( 'Playwright manages remote debugging connection itself' ) ;
55
+ } ) ;
56
+ it ( 'should throw with remote-debugging-port argument' , async ( ) => {
57
+ const options = Object . assign ( { } , defaultBrowserOptions ) ;
58
+ options . args = [ '--remote-debugging-port=9222' ] . concat ( options . args || [ ] ) ;
59
+ const error = await playwright . launchServer ( options ) . catch ( e => e ) ;
60
+ expect ( error . message ) . toContain ( 'Playwright manages remote debugging connection itself' ) ;
61
+ } ) ;
62
+ it ( 'should open devtools when "devtools: true" option is given' , async ( { server} ) => {
63
+ const browser = await playwright . launch ( Object . assign ( { devtools : true } , headfulOptions ) ) ;
64
+ const context = await browser . newContext ( ) ;
65
+ const browserSession = await browser . createBrowserSession ( ) ;
66
+ await browserSession . send ( 'Target.setDiscoverTargets' , { discover : true } ) ;
67
+ const devtoolsPagePromise = new Promise ( fulfill => browserSession . on ( 'Target.targetCreated' , async ( { targetInfo} ) => {
68
+ if ( targetInfo . type === 'other' && targetInfo . url . includes ( 'devtools://' ) )
69
+ fulfill ( ) ;
70
+ } ) ) ;
71
+ await Promise . all ( [
72
+ devtoolsPagePromise ,
73
+ context . newPage ( )
74
+ ] ) ;
75
+ await browser . close ( ) ;
76
+ } ) ;
77
+ } ) ;
78
+
79
+ describe ( 'extensions' , ( ) => {
80
+ it ( 'should return background pages' , async ( ) => {
81
+ const userDataDir = await makeUserDataDir ( ) ;
82
+ const context = await playwright . launchPersistent ( userDataDir , extensionOptions ) ;
83
+ const backgroundPages = await context . backgroundPages ( ) ;
84
+ let backgroundPage = backgroundPages . length
85
+ ? backgroundPages [ 0 ]
86
+ : await new Promise ( fulfill => context . once ( 'backgroundpage' , async event => fulfill ( await event . page ( ) ) ) ) ;
87
+ expect ( backgroundPage ) . toBeTruthy ( ) ;
88
+ expect ( await context . backgroundPages ( ) ) . toContain ( backgroundPage ) ;
89
+ expect ( await context . pages ( ) ) . not . toContain ( backgroundPage ) ;
90
+ await removeUserDataDir ( userDataDir ) ;
54
91
} ) ;
55
92
} ) ;
56
93
0 commit comments