UNPKG

@assert-equals/dappdriver

Version:

DappDriver is an e2e testing framework designed for testing decentralized applications (dApps) using MetaMask, Rainbow or Zerion

51 lines (50 loc) 2.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlaywrightFactory = void 0; const playwright_core_1 = __importDefault(require("playwright-core")); const constants_1 = require("../constants"); class PlaywrightFactory { async build(browser, options) { if (browser.toLowerCase() === constants_1.CHROME) { return await this.buildChrome(options); } throw new Error('Unsupported browser: ' + browser); } async buildChrome(options) { const chromeOptions = { headless: false, channel: 'chrome', args: [] }; if (options.proxy) { chromeOptions['ignoreHTTPSErrors'] = true; chromeOptions['proxy'] = { server: constants_1.HTTPS_PROXY_HOST }; } if (options.extension.wallet !== null && options.extension.wallet !== constants_1.HEADLESS) { let extensionPath = options.extension.path; if (options.extension.wallet === constants_1.METAMASK) { extensionPath = extensionPath || constants_1.DEFAULT_METAMASK_BINARY_PATH; } else if (options.extension.wallet === constants_1.METAMASK_FLASK) { extensionPath = extensionPath || constants_1.DEFAULT_METAMASK_FLASK_BINARY_PATH; } else if (options.extension.wallet === constants_1.ZERION) { extensionPath = extensionPath || constants_1.DEFAULT_ZERION_BINARY_PATH; } else if (options.extension.wallet === constants_1.RAINBOW) { extensionPath = extensionPath || constants_1.DEFAULT_RAINBOW_BINARY_PATH; } chromeOptions['args'].push(`--disable-extensions-except=${extensionPath}`); chromeOptions['args'].push(`--load-extension=${extensionPath}`); } chromeOptions['args'].push(`--window-size=1024,768`); const browserContext = await playwright_core_1.default.chromium.launchPersistentContext('', chromeOptions); return browserContext; } } exports.PlaywrightFactory = PlaywrightFactory;