Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
Refactor building of e2e web driver (MetaMask#7841)
Browse files Browse the repository at this point in the history
The switch case has been moved to a separate function so that the
initialization steps following the web driver instantiation could more
easily be deduplicated.
  • Loading branch information
Gudahtt authored and yqrashawn committed Jan 19, 2020
1 parent dff0f15 commit aedcb2c
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions test/e2e/webdriver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,30 @@ async function buildWebDriver ({ responsive, port } = {}) {
const browser = process.env.SELENIUM_BROWSER
const extensionPath = `dist/${browser}`

const {
driver: seleniumDriver,
extensionId,
extensionUrl,
} = await buildBrowserWebDriver(browser, { extensionPath, responsive, port })
setupFetchMocking(seleniumDriver)
await seleniumDriver.get(extensionUrl)

const driver = new Driver(seleniumDriver, browser)

return {
driver,
extensionId,
extensionUrl,
}
}

async function buildBrowserWebDriver (browser, webDriverOptions) {
switch (browser) {
case Browser.CHROME: {
const { driver, extensionId, extensionUrl } = await ChromeDriver.build({
extensionPath,
responsive,
port,
})
setupFetchMocking(driver)
await driver.get(extensionUrl)

return {
driver: new Driver(driver, browser),
extensionId,
extensionUrl,
}
return await ChromeDriver.build(webDriverOptions)
}
case Browser.FIREFOX: {
const { driver, extensionId, extensionUrl } = await FirefoxDriver.build({
extensionPath,
responsive,
port,
})
setupFetchMocking(driver)
await driver.get(extensionUrl)

return {
driver: new Driver(driver, browser),
extensionId,
extensionUrl,
}
return await FirefoxDriver.build(webDriverOptions)
}
default: {
throw new Error(`Unrecognized browser: ${browser}`)
Expand Down

0 comments on commit aedcb2c

Please sign in to comment.