|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 | const fs = require('fs');
|
| 18 | +const os = require('os'); |
18 | 19 | const path = require('path');
|
| 20 | +const util = require('util'); |
| 21 | + |
19 | 22 | const utils = require('./utils');
|
| 23 | +const rmAsync = util.promisify(require('rimraf')); |
| 24 | +const mkdtempAsync = util.promisify(fs.mkdtemp); |
| 25 | + |
| 26 | +const TMP_FOLDER = path.join(os.tmpdir(), 'pptr_tmp_folder-'); |
20 | 27 |
|
21 |
| -module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, WEBKIT}) { |
| 28 | +module.exports.describe = function({testRunner, expect, defaultBrowserOptions, playwright, CHROMIUM, FFOX, WEBKIT}) { |
22 | 29 | const {describe, xdescribe, fdescribe} = testRunner;
|
23 | 30 | const {it, fit, xit, dit} = testRunner;
|
24 | 31 | const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;
|
@@ -181,4 +188,104 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
|
181 | 188 | await browserServer.close();
|
182 | 189 | });
|
183 | 190 | });
|
| 191 | + |
| 192 | + describe.skip(FFOX | WEBKIT)('Playwright.launch({userDataDir})', function() { |
| 193 | + it('userDataDir option', async({server}) => { |
| 194 | + const userDataDir = await mkdtempAsync(TMP_FOLDER); |
| 195 | + const options = Object.assign({userDataDir}, defaultBrowserOptions); |
| 196 | + const browser = await playwright.launch(options); |
| 197 | + // Open a page to make sure its functional. |
| 198 | + await browser.defaultContext().newPage(); |
| 199 | + expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); |
| 200 | + await browser.close(); |
| 201 | + expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); |
| 202 | + // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 |
| 203 | + await rmAsync(userDataDir).catch(e => {}); |
| 204 | + }); |
| 205 | + it('userDataDir argument', async({server}) => { |
| 206 | + const userDataDir = await mkdtempAsync(TMP_FOLDER); |
| 207 | + const options = Object.assign({}, defaultBrowserOptions); |
| 208 | + options.args = [ |
| 209 | + ...(defaultBrowserOptions.args || []), |
| 210 | + `--user-data-dir=${userDataDir}` |
| 211 | + ]; |
| 212 | + const browser = await playwright.launch(options); |
| 213 | + // Open a page to make sure its functional. |
| 214 | + await browser.defaultContext().newPage(); |
| 215 | + expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); |
| 216 | + await browser.close(); |
| 217 | + expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); |
| 218 | + // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 |
| 219 | + await rmAsync(userDataDir).catch(e => {}); |
| 220 | + }); |
| 221 | + it('should return the default arguments', async() => { |
| 222 | + if (CHROMIUM) |
| 223 | + expect(playwright.defaultArgs()).toContain('--no-first-run'); |
| 224 | + expect(playwright.defaultArgs()).toContain('--headless'); |
| 225 | + expect(playwright.defaultArgs({headless: false})).not.toContain('--headless'); |
| 226 | + expect(playwright.defaultArgs({userDataDir: 'foo'})).toContain('--user-data-dir=foo'); |
| 227 | + }); |
| 228 | + it('should filter out ignored default arguments', async() => { |
| 229 | + // Make sure we launch with `--enable-automation` by default. |
| 230 | + const defaultArgs = playwright.defaultArgs(defaultBrowserOptions); |
| 231 | + const browserServer = await playwright.launchServer(Object.assign({}, defaultBrowserOptions, { |
| 232 | + // Ignore first and third default argument. |
| 233 | + ignoreDefaultArgs: [ defaultArgs[0], defaultArgs[2] ], |
| 234 | + })); |
| 235 | + const spawnargs = browserServer.process().spawnargs; |
| 236 | + expect(spawnargs.indexOf(defaultArgs[0])).toBe(-1); |
| 237 | + expect(spawnargs.indexOf(defaultArgs[1])).not.toBe(-1); |
| 238 | + expect(spawnargs.indexOf(defaultArgs[2])).toBe(-1); |
| 239 | + await browserServer.close(); |
| 240 | + }); |
| 241 | + it('userDataDir option should restore state', async({server}) => { |
| 242 | + const userDataDir = await mkdtempAsync(TMP_FOLDER); |
| 243 | + const options = Object.assign({userDataDir}, defaultBrowserOptions); |
| 244 | + const browser = await playwright.launch(options); |
| 245 | + const page = await browser.defaultContext().newPage(); |
| 246 | + await page.goto(server.EMPTY_PAGE); |
| 247 | + await page.evaluate(() => localStorage.hey = 'hello'); |
| 248 | + await browser.close(); |
| 249 | + |
| 250 | + const browser2 = await playwright.launch(options); |
| 251 | + const page2 = await browser2.defaultContext().newPage(); |
| 252 | + await page2.goto(server.EMPTY_PAGE); |
| 253 | + expect(await page2.evaluate(() => localStorage.hey)).toBe('hello'); |
| 254 | + await browser2.close(); |
| 255 | + |
| 256 | + const browser3 = await playwright.launch(defaultBrowserOptions); |
| 257 | + const page3 = await browser3.defaultContext().newPage(); |
| 258 | + await page3.goto(server.EMPTY_PAGE); |
| 259 | + expect(await page3.evaluate(() => localStorage.hey)).not.toBe('hello'); |
| 260 | + await browser3.close(); |
| 261 | + |
| 262 | + // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 |
| 263 | + await rmAsync(userDataDir).catch(e => {}); |
| 264 | + }); |
| 265 | + // This mysteriously fails on Windows on AppVeyor. See https://github.com/GoogleChrome/puppeteer/issues/4111 |
| 266 | + it('userDataDir option should restore cookies', async({server}) => { |
| 267 | + const userDataDir = await mkdtempAsync(TMP_FOLDER); |
| 268 | + const options = Object.assign({userDataDir}, defaultBrowserOptions); |
| 269 | + const browser = await playwright.launch(options); |
| 270 | + const page = await browser.defaultContext().newPage(); |
| 271 | + await page.goto(server.EMPTY_PAGE); |
| 272 | + await page.evaluate(() => document.cookie = 'doSomethingOnlyOnce=true; expires=Fri, 31 Dec 9999 23:59:59 GMT'); |
| 273 | + await browser.close(); |
| 274 | + |
| 275 | + const browser2 = await playwright.launch(options); |
| 276 | + const page2 = await browser2.defaultContext().newPage(); |
| 277 | + await page2.goto(server.EMPTY_PAGE); |
| 278 | + expect(await page2.evaluate(() => document.cookie)).toBe('doSomethingOnlyOnce=true'); |
| 279 | + await browser2.close(); |
| 280 | + |
| 281 | + const browser3 = await playwright.launch(defaultBrowserOptions); |
| 282 | + const page3 = await browser3.defaultContext().newPage(); |
| 283 | + await page3.goto(server.EMPTY_PAGE); |
| 284 | + expect(await page3.evaluate(() => localStorage.hey)).not.toBe('doSomethingOnlyOnce=true'); |
| 285 | + await browser3.close(); |
| 286 | + |
| 287 | + // This might throw. See https://github.com/GoogleChrome/puppeteer/issues/2778 |
| 288 | + await rmAsync(userDataDir).catch(e => {}); |
| 289 | + }); |
| 290 | + }); |
184 | 291 | };
|
0 commit comments