@assert-equals/dappdriver
Version:
DappDriver is an e2e testing framework designed for testing decentralized applications (dApps) using MetaMask, Rainbow or Zerion
46 lines (45 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebDriverFactory = void 0;
const selenium_webdriver_1 = require("selenium-webdriver");
const chrome_1 = require("selenium-webdriver/chrome");
const constants_1 = require("../constants");
class WebDriverFactory {
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 = new chrome_1.Options();
const args = [];
if (options.proxy) {
args.push(`--proxy-server=${constants_1.HTTPS_PROXY_HOST}`);
chromeOptions.setAcceptInsecureCerts(true);
}
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;
}
args.push(`--load-extension=${extensionPath}`);
}
args.push(`--window-size=1024,768`);
chromeOptions.addArguments(...args);
chromeOptions.enableBidi();
const driver = await new selenium_webdriver_1.Builder().forBrowser(constants_1.CHROME).setChromeOptions(chromeOptions).build();
await driver.manage().setTimeouts({ implicit: 20000 });
return driver;
}
}
exports.WebDriverFactory = WebDriverFactory;