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

Check for nightly channel to handle devtools #5528

Merged
merged 8 commits into from
Jun 25, 2020
24 changes: 24 additions & 0 deletions packages/devtools/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const FIREFOX_NAMES = ['firefox', 'ff', 'mozilla', 'mozillafirefox', 'hea
export const EDGE_NAMES = ['edge', 'msedge', 'microsoft-edge', 'microsoftedge']
export const SUPPORTED_BROWSER = [...CHROME_NAMES, ...FIREFOX_NAMES, ...EDGE_NAMES]

export const BROWSER_TYPE = {
chrome: 'chrome',
firefox: 'firefox',
edge: 'edge'
}

export const DEFAULTS = {
capabilities: {
type: 'object',
Expand Down Expand Up @@ -93,8 +99,26 @@ export const ERROR_MESSAGES = {
}
}

export const BROWSER_ERROR_MESSAGES = {
firefoxNightly: `Only Nightly release channel is supported in Devtools/Puppeteer for Firefox. Refer to the following issue:
https://bugzilla.mozilla.org/show_bug.cgi?id=1606604

You can use the following link to download Firefox Nightly edition:
https://www.mozilla.org/en-US/firefox/channel/desktop/

Adding the following binary capability in Firefox Options is mandatory to run with Nightly edition:

'moz:firefoxOptions': {
binary: '/path/to/firefox'
}

Note: "Nightly" as a term should be present in the "Firefox Application Name" across all OS's in binary path mentioned above for this to work.`
}

export const VENDOR_PREFIX = {
chrome: 'goog:chromeOptions',
firefox: 'moz:firefoxOptions',
edge: 'ms:edgeOptions'
}

export const CHANNEL_FIREFOX_NIGHTLY = 'nightly'
20 changes: 16 additions & 4 deletions packages/devtools/src/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ import logger from '@wdio/logger'
import browserFinder from './finder'
import { getPages } from './utils'
import {
CHROME_NAMES, FIREFOX_NAMES, EDGE_NAMES, DEFAULT_FLAGS, DEFAULT_WIDTH,
DEFAULT_HEIGHT, DEFAULT_X_POSITION, DEFAULT_Y_POSITION, VENDOR_PREFIX
CHROME_NAMES,
FIREFOX_NAMES,
EDGE_NAMES,
BROWSER_TYPE,
DEFAULT_FLAGS,
DEFAULT_WIDTH,
DEFAULT_HEIGHT,
DEFAULT_X_POSITION,
DEFAULT_Y_POSITION,
VENDOR_PREFIX,
CHANNEL_FIREFOX_NIGHTLY,
BROWSER_ERROR_MESSAGES
} from './constants'

const log = logger('devtools')
Expand Down Expand Up @@ -120,6 +130,8 @@ function launchBrowser (capabilities, product) {

if (!executablePath) {
throw new Error('Couldn\'t find executable for browser')
} else if (product === BROWSER_TYPE.firefox && !executablePath.toLowerCase().includes(CHANNEL_FIREFOX_NIGHTLY)) {
throw new Error(BROWSER_ERROR_MESSAGES.firefoxNightly)
}

log.info(`Launch ${executablePath} with config: ${JSON.stringify(puppeteerOptions)}`)
Expand All @@ -134,12 +146,12 @@ export default function launch (capabilities) {
}

if (FIREFOX_NAMES.includes(browserName)) {
return launchBrowser(capabilities, 'firefox')
return launchBrowser(capabilities, BROWSER_TYPE.firefox)
}

/* istanbul ignore next */
if (EDGE_NAMES.includes(browserName)) {
return launchBrowser(capabilities, 'edge')
return launchBrowser(capabilities, BROWSER_TYPE.edge)
}

throw new Error(`Couldn't identify browserName ${browserName}`)
Expand Down
63 changes: 24 additions & 39 deletions packages/devtools/tests/__snapshots__/launcher.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,35 @@ Array [
]
`;

exports[`launch Firefox with custom arguments 1`] = `
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",
},
],
]
`;

exports[`launch Firefox Nightly with custom arguments 1`] = `
Array [
Array [
Object {
"args": Array [
"foobar",
],
"binary": "/foo/bar",
"binary": "/foo/firefox-nightly",
"defaultViewport": Object {
"height": 456,
"width": 123,
},
"executablePath": "/foo/bar",
"executablePath": "/foo/firefox-nightly",
"headless": true,
"ignoreDefaultArgs": undefined,
"product": "firefox",
Expand All @@ -57,16 +73,18 @@ Array [
]
`;

exports[`launch Firefox with default values 1`] = `
exports[`launch Firefox Nightly without Puppeteer default args 1`] = `
Array [
Array [
Object {
"binary": "/foo/firefox-nightly",
"defaultViewport": Object {
"height": 900,
"width": 1200,
},
"executablePath": "/path/to/firefox",
"ignoreDefaultArgs": undefined,
"executablePath": "/foo/firefox-nightly",
"headless": true,
"ignoreDefaultArgs": true,
"product": "firefox",
},
],
Expand Down Expand Up @@ -224,36 +242,3 @@ Array [
],
]
`;

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",
},
],
]
`;
57 changes: 51 additions & 6 deletions packages/devtools/tests/launcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,42 @@ test('throws an error if an unknown deviceName is picked', async () => {
})

test('launch Firefox with default values', async () => {
await launch({
browserName: 'firefox'
})
expect(puppeteer.launch.mock.calls).toMatchSnapshot()
expect.assertions(1)

try {
await launch({ browserName: 'firefox' })
} catch (err) {
expect(err.message).toContain('Only Nightly release channel is supported')
}
})

test('launch Firefox with custom arguments', async () => {
expect.assertions(1)

try {
await launch({
browserName: 'firefox',
'moz:firefoxOptions': {
args: ['foobar'],
binary: '/foo/bar',
headless: true,
defaultViewport: {
width: 123,
height: 456
}
}
})
} catch (err) {
expect(err.message).toContain('Only Nightly release channel is supported')
}
})

test('launch Firefox Nightly with custom arguments', async () => {
await launch({
browserName: 'firefox',
'moz:firefoxOptions': {
args: ['foobar'],
binary: '/foo/bar',
binary: '/foo/firefox-nightly',
headless: true,
defaultViewport: {
width: 123,
Expand Down Expand Up @@ -151,14 +175,35 @@ test('throws if browser is unknown', async () => {
}
})

test('launch Firefox without Puppeteer default args', async () => {
test('launch Firefox Nightly without Puppeteer default args', async () => {
await launch({
browserName: 'firefox',
'moz:firefoxOptions': {
binary: '/foo/firefox-nightly',
headless: true
},
ignoreDefaultArgs: true
})
expect(puppeteer.launch.mock.calls).toMatchSnapshot()
})

test('launch Firefox without Puppeteer default args', async () => {
expect.assertions(1)

try {
await launch({
browserName: 'firefox',
'moz:firefoxOptions': {
binary: '/foo/firefox',
headless: true
},
ignoreDefaultArgs: true
})
} catch (err) {
expect(err.message).toContain('Only Nightly release channel is supported')
}
mathew-jithin marked this conversation as resolved.
Show resolved Hide resolved
})

test('launch Edge without Puppeteer default args', async () => {
await launch({
browserName: 'edge',
Expand Down