1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

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.
This commit is contained in:
Mark Stacey 2020-01-16 14:35:50 -04:00 committed by GitHub
parent 70e083820b
commit 08dcd87d58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,28 +8,26 @@ 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}`)