chore: update error message when using userDataDir arg (#5814)

This commit is contained in:
E 2021-03-15 16:58:46 -07:00 committed by GitHub
parent ea32ad2b09
commit 095ad6339c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View File

@ -119,7 +119,7 @@ export class Chromium extends BrowserType {
const { args = [], proxy } = options; const { args = [], proxy } = options;
const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir')); const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir'));
if (userDataDirArg) if (userDataDirArg)
throw new Error('Pass userDataDir parameter instead of specifying --user-data-dir argument'); throw new Error('Pass userDataDir parameter to `browserType.launchPersistentContext(userDataDir, ...)` instead of specifying --user-data-dir argument');
if (args.find(arg => arg.startsWith('--remote-debugging-pipe'))) if (args.find(arg => arg.startsWith('--remote-debugging-pipe')))
throw new Error('Playwright manages remote debugging connection itself.'); throw new Error('Playwright manages remote debugging connection itself.');
if (args.find(arg => !arg.startsWith('-'))) if (args.find(arg => !arg.startsWith('-')))

View File

@ -60,7 +60,7 @@ export class Firefox extends BrowserType {
console.warn('devtools parameter is not supported as a launch argument in Firefox. You can launch the devtools window manually.'); console.warn('devtools parameter is not supported as a launch argument in Firefox. You can launch the devtools window manually.');
const userDataDirArg = args.find(arg => arg.startsWith('-profile') || arg.startsWith('--profile')); const userDataDirArg = args.find(arg => arg.startsWith('-profile') || arg.startsWith('--profile'));
if (userDataDirArg) if (userDataDirArg)
throw new Error('Pass userDataDir parameter instead of specifying -profile argument'); throw new Error('Pass userDataDir parameter to `browserType.launchPersistentContext(userDataDir, ...)` instead of specifying --profile argument');
if (args.find(arg => arg.startsWith('-juggler'))) if (args.find(arg => arg.startsWith('-juggler')))
throw new Error('Use the port parameter instead of -juggler argument'); throw new Error('Use the port parameter instead of -juggler argument');
const firefoxUserPrefs = isPersistent ? undefined : options.firefoxUserPrefs; const firefoxUserPrefs = isPersistent ? undefined : options.firefoxUserPrefs;

View File

@ -49,9 +49,9 @@ export class WebKit extends BrowserType {
const { args = [], proxy, devtools, headless } = options; const { args = [], proxy, devtools, headless } = options;
if (devtools) if (devtools)
console.warn('devtools parameter as a launch argument in WebKit is not supported. Also starting Web Inspector manually will terminate the execution in WebKit.'); console.warn('devtools parameter as a launch argument in WebKit is not supported. Also starting Web Inspector manually will terminate the execution in WebKit.');
const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir=')); const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir'));
if (userDataDirArg) if (userDataDirArg)
throw new Error('Pass userDataDir parameter instead of specifying --user-data-dir argument'); throw new Error('Pass userDataDir parameter to `browserType.launchPersistentContext(userDataDir, ...)` instead of specifying --user-data-dir argument');
if (args.find(arg => !arg.startsWith('-'))) if (args.find(arg => !arg.startsWith('-')))
throw new Error('Arguments can not specify page to be opened'); throw new Error('Arguments can not specify page to be opened');
const webkitArguments = ['--inspector-pipe']; const webkitArguments = ['--inspector-pipe'];

View File

@ -36,6 +36,13 @@ it('should throw if userDataDir option is passed', async ({browserType, browserO
expect(waitError.message).toContain('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead'); expect(waitError.message).toContain('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistentContext` instead');
}); });
it('should throw if userDataDir is passed as an argument', async ({browserType, browserOptions}) => {
let waitError = null;
const options = Object.assign({}, browserOptions, {args: ['--user-data-dir=random-path', '--profile=random-path']});
await browserType.launch(options).catch(e => waitError = e);
expect(waitError.message).toContain('Pass userDataDir parameter to `browserType.launchPersistentContext');
});
it('should throw if port option is passed', async ({browserType, browserOptions}) => { it('should throw if port option is passed', async ({browserType, browserOptions}) => {
const options = Object.assign({}, browserOptions, {port: 1234}); const options = Object.assign({}, browserOptions, {port: 1234});
const error = await browserType.launch(options).catch(e => e); const error = await browserType.launch(options).catch(e => e);