@assert-equals/dappdriver
Version:
DappDriver is an e2e testing framework designed for testing decentralized applications (dApps) using MetaMask, Rainbow or Zerion
82 lines (81 loc) • 2.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Connect = void 0;
const constants_1 = require("../../constants");
const metamask_1 = require("../../metamask");
const rainbow_1 = require("../../rainbow");
const dapp_driver_1 = require("../../session/dapp-driver");
const zerion_1 = require("../../zerion");
/**
*
*
* @export
* @class Connect
* @implements {IConfirmation}
*/
class Connect {
url;
title;
connect;
constructor() {
switch (dapp_driver_1.DappDriver.Instance.Wallet) {
case constants_1.METAMASK:
case constants_1.METAMASK_FLASK:
this.connect = new metamask_1.Connect();
break;
case constants_1.RAINBOW:
this.connect = new rainbow_1.Connect();
break;
case constants_1.ZERION:
this.connect = new zerion_1.Connect();
break;
}
this.url = this.connect.url;
this.title = this.connect.title;
}
async callIfMethodExists(methodName, args = []) {
return await this.connect[methodName](...args);
}
async accept(page) {
if (page) {
return await this.callIfMethodExists('accept', [page]);
}
else {
return await this.callIfMethodExists('accept');
}
}
/**
*
*
* @return {*} {Promise<any[]>}
* @memberof Connect
*/
async getAllWindowHandles() {
return await this.callIfMethodExists('getAllWindowHandles');
}
async reject(page) {
if (page) {
return await this.callIfMethodExists('reject', [page]);
}
else {
return await this.callIfMethodExists('reject');
}
}
async switchToMainWindow(page) {
if (page) {
return await this.callIfMethodExists('switchToMainWindow', [page]);
}
else {
return await this.callIfMethodExists('switchToMainWindow');
}
}
async switchToWindow(nameOrHandle, page) {
if (page) {
return await this.callIfMethodExists('switchToWindow', [nameOrHandle, page]);
}
else {
return await this.callIfMethodExists('switchToWindow', [nameOrHandle]);
}
}
}
exports.Connect = Connect;