From aedcb2c9be533a8385aa195e27a7a69ccb072ad8 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 16 Jan 2020 14:35:50 -0400 Subject: [PATCH] Refactor building of e2e web driver (#7841) 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. --- test/e2e/webdriver/index.js | 46 ++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/test/e2e/webdriver/index.js b/test/e2e/webdriver/index.js index df3430be362a..ae2bd8faeedb 100644 --- a/test/e2e/webdriver/index.js +++ b/test/e2e/webdriver/index.js @@ -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}`)