Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore defaultChromeFlags / PptrDefaultArgs tags #5344

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/ConfigurationFile.md
Expand Up @@ -100,6 +100,11 @@ exports.config = {
// (see https://developers.google.com/web/updates/2017/04/headless-chrome)
// args: ['--headless', '--disable-gpu'],
}
// To run Chrome without 'WebdriverIO/DevTools' default flags:
// disableDefaultChromeFlags: true,
//
// To use 'WebdriverIO/DevTools' Puppeteer without its default arguments:
// ignorePuppeteerDefaultArgs: true,
}, {
// maxInstances can get overwritten per capability. So if you have an in house Selenium
// grid with only 5 firefox instance available you can make sure that not more than
Expand Down
15 changes: 11 additions & 4 deletions packages/devtools/src/launcher.js
Expand Up @@ -22,6 +22,8 @@ const DEVICE_NAMES = Object.values(DEVICES).map((device) => device.name)
async function launchChrome (capabilities) {
const chromeOptions = capabilities[VENDOR_PREFIX.chrome] || {}
const mobileEmulation = chromeOptions.mobileEmulation || {}
const disableDefaultChromeFlags = capabilities.disableDefaultChromeFlags || false
const ignorePuppeteerDefaultArgs = capabilities.ignorePuppeteerDefaultArgs || false

if (typeof mobileEmulation.deviceName === 'string') {
const deviceProperties = Object.values(DEVICES).find(device => device.name === mobileEmulation.deviceName)
Expand All @@ -39,7 +41,7 @@ async function launchChrome (capabilities) {

const deviceMetrics = mobileEmulation.deviceMetrics || {}
const chromeFlags = [
...DEFAULT_FLAGS,
...(disableDefaultChromeFlags ? [] : DEFAULT_FLAGS),
...[
`--window-position=${DEFAULT_X_POSITION},${DEFAULT_Y_POSITION}`,
`--window-size=${DEFAULT_WIDTH},${DEFAULT_HEIGHT}`
Expand All @@ -60,10 +62,13 @@ async function launchChrome (capabilities) {
}

log.info(`Launch Google Chrome with flags: ${chromeFlags.join(' ')}`)
const chrome = await launchChromeBrowser({

const chrome = await launchChromeBrowser( Object.assign({
chromePath: chromeOptions.binary,
chromeFlags
})
},
ignorePuppeteerDefaultArgs ? { ignoreDefaultArgs: true } : {}
))

log.info(`Connect Puppeteer with browser on port ${chrome.port}`)
const browser = await puppeteer.connect({
Expand Down Expand Up @@ -92,6 +97,7 @@ async function launchChrome (capabilities) {

function launchBrowser (capabilities, product) {
const vendorCapKey = VENDOR_PREFIX[product]
const ignoreDefaultArgs = capabilities.ignorePuppeteerDefaultArgs || false

if (!capabilities[vendorCapKey]) {
capabilities[vendorCapKey] = {}
Expand All @@ -109,7 +115,8 @@ function launchBrowser (capabilities, product) {
width: DEFAULT_WIDTH,
height: DEFAULT_HEIGHT
}
}, capabilities[vendorCapKey] || {})
}, capabilities[vendorCapKey],
ignoreDefaultArgs ? { ignoreDefaultArgs: true } : {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above:

    const puppeteerOptions = Object.assign({
        product,
        executablePath,
        defaultViewport: {
            width: DEFAULT_WIDTH,
            height: DEFAULT_HEIGHT
        },
		ignoreDefaultArgs: Boolean(ignoreDefaultArgs)
    }, capabilities[vendorCapKey] || {})

Copy link
Contributor Author

@anemer anemer May 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move ignoreDefaultArgs into goog:chromeOptions as it i a custom capability?

It's true my first need was for Chrome. But:

  • As I can see in devtools/launcher.js devtools can also be used for other browsers than Chrome. Maybe not yet at the same level as with Chrome, but it's possible.

  • And it seems Puppeteer accepts this ignoreDefaultArgs parameter in its experimental support of Firefox (see experimental/puppeteer-firefox/Launcher.js).

so why limit this parameter only for Chrome?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above:

    const puppeteerOptions = Object.assign({
        product,
        executablePath,
        defaultViewport: {
            width: DEFAULT_WIDTH,
            height: DEFAULT_HEIGHT
        },
		ignoreDefaultArgs: Boolean(ignoreDefaultArgs)
    }, capabilities[vendorCapKey] || {})

line 124 is actually wrong. It should be like line 75:

    ignoreDefaultArgs ? { ignoreDefaultArgs: ignoreDefaultArgs } : {}

as ignoreDefaultArgs is either a boolean or a array of string (as in Puppeteer)


if (!executablePath) {
throw new Error('Couldn\'t find executable for browser')
Expand Down
100 changes: 100 additions & 0 deletions packages/devtools/tests/__snapshots__/launcher.test.js.snap
Expand Up @@ -154,3 +154,103 @@ Array [
],
]
`;

exports[`launch chrome without default flags 1`] = `
Array [
Array [
Object {
"chromeFlags": Array [
"--window-position=0,0",
"--window-size=1200,900",
],
"chromePath": undefined,
},
],
]
`;

exports[`launch chrome without default flags 2`] = `
Array [
Array [
Object {
"browserURL": "http://localhost:1234",
"defaultViewport": null,
},
],
]
`;

exports[`launch chrome without default flags and without puppeteer default args 1`] = `
Array [
Array [
Object {
"chromeFlags": Array [
"--window-position=0,0",
"--window-size=1200,900",
],
"chromePath": undefined,
"ignoreDefaultArgs": true,
},
],
]
`;

exports[`launch chrome without default flags and without puppeteer default args 2`] = `
Array [
Array [
Object {
"browserURL": "http://localhost:1234",
"defaultViewport": null,
},
],
]
`;

exports[`overriding chrome default flags 1`] = `
Array [
Array [
Object {
"chromeFlags": Array [
"--window-position=0,0",
"--window-size=1200,900",
"--no-first-run",
"--enable-features=NetworkService",
],
"chromePath": undefined,
},
],
]
`;

exports[`launch Firefox without Puppeteer default args 1`] = `
Array [
Array [
Object {
"defaultViewport": Object {
"height": 900,
"width": 1200,
},
"executablePath": "/path/to/firefox",
"ignoreDefaultArgs": true,
"product": "firefox",
},
],
]
`;


exports[`launch Edge without Puppeteer default args 1`] = `
Array [
Array [
Object {
"defaultViewport": Object {
"height": 900,
"width": 1200,
},
"executablePath": "/path/to/edge",
"ignoreDefaultArgs": true,
"product": "edge",
},
],
]
`;
59 changes: 59 additions & 0 deletions packages/devtools/tests/launcher.test.js
Expand Up @@ -56,6 +56,49 @@ test('launch chrome with chrome arguments', async () => {
})
})

test('launch chrome without default flags', async () => {
const browser = await launch({
browserName: 'chrome',
disableDefaultChromeFlags: true
})
expect(launchChromeBrowser.mock.calls).toMatchSnapshot()
expect(puppeteer.connect.mock.calls).toMatchSnapshot()

const pages = await browser.pages()
expect(pages[0].close).toBeCalled()
expect(pages[1].close).toBeCalledTimes(0)
})

test('launch chrome without default flags and without puppeteer default args', async () => {
const browser = await launch({
browserName: 'chrome',
disableDefaultChromeFlags: true,
ignorePuppeteerDefaultArgs: true
})
expect(launchChromeBrowser.mock.calls).toMatchSnapshot()
expect(puppeteer.connect.mock.calls).toMatchSnapshot()

const pages = await browser.pages()
expect(pages[0].close).toBeCalled()
expect(pages[1].close).toBeCalledTimes(0)
})

test('overriding chrome default flags', async () => {
const browser = await launch({
browserName: 'chrome',
disableDefaultChromeFlags: true,
'goog:chromeOptions': {
args: [
'--no-first-run', '--enable-features=NetworkService']
}
})
expect(launchChromeBrowser.mock.calls).toMatchSnapshot()

const pages = await browser.pages()
expect(pages[0].close).toBeCalled()
expect(pages[1].close).toBeCalledTimes(0)
})

test('throws an error if an unknown deviceName is picked', async () => {
const err = await launch({
browserName: 'chrome',
Expand Down Expand Up @@ -122,3 +165,19 @@ test('throws if browser is unknown', async () => {
expect(e.message).toContain('Couldn\'t identify browserName')
}
})

test('launch Firefox without Puppeteer default args', async () => {
await launch({
browserName: 'firefox',
ignorePuppeteerDefaultArgs: true
})
expect(puppeteer.launch.mock.calls).toMatchSnapshot()
})

test('launch Edge without Puppeteer default args', async () => {
await launch({
browserName: 'edge',
ignorePuppeteerDefaultArgs: true
})
expect(puppeteer.launch.mock.calls).toMatchSnapshot()
})