"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var w=require("@playwright/test"),h=require("node:path"),d=require("playwright");function k(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var m=k(h);const l=async t=>{await t.goto("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#initialize/welcome"),await t.locator("text=Get Started").click(),await t.waitForURL("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#initialize/select-action"),await t.locator("text=Import wallet").click(),await t.waitForURL("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#initialize/metametrics-opt-in"),await t.locator('[data-testid="page-container-footer-next"]').click(),await t.waitForURL("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#initialize/create-password/import-with-seed-phrase"),await t.locator("select").selectOption("24");const a="hockey   dilemma   magic   rigid   blade   crawl   soldier   screen   mind   siege   disorder   hint   ramp   solid   flat   caution   swamp   anger   attend   trim   tell   obscure   rice   math".split(/\s+/);for(const[i,s]of Object.entries(a)){const n=t.locator(`[data-testid="import-srp__srp-word-${i}"]`);await n.click(),await n.fill(s)}await t.locator("text=I have read and agree to the Terms of Use").click(),await t.locator("#password").click(),await t.locator("#password").fill("Over123456"),await t.locator("#confirm-password").click(),await t.locator("#confirm-password").fill("Over123456"),await t.locator('button:has-text("Import")').click(),await t.waitForURL("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#initialize/end-of-flow"),await t.locator("text=All Done").click(),await t.locator(".popover-header__title button").click()},g=w.test.extend({context:async({},t)=>{const e=m.default.join(__dirname,"./extension"),a=await d.chromium.launchPersistentContext("",{devtools:!1,headless:!1,timeout:0,args:[`--disable-extensions-except=${e}`,`--load-extension=${e}`]});await t(a),await a.close()},metaMaskPage:async({context:t,extensionId:e},a)=>{const i=`chrome-extension://${e}/popup.html`,s=t.pages(),n=s.length>0?s[0]:await t.newPage();await l(n),await n.goto(i);for(const r of t.pages())r.url().includes("home.html#initialize/welcome")&&await r.close();await a(n)},extensionId:async({context:t},e)=>{let[a]=t.backgroundPages();a||(a=await t.waitForEvent("backgroundpage"));const i=a.url().split("/")[2];await e(i)}}),o={confirmFeeEtcBtn:["button",{hasText:"Confirm"}],approveAddNetworkBtn:["button",{hasText:"Approve"}],switchNetworkBtn:["button",{hasText:"Switch network"}],rejectBtn:["button",{hasText:"Reject"}],nextBtn:["button",{hasText:"Next"}],connectBtn:["button",{hasText:"Connect"}]},c=async(t,e,a)=>{let i=!1;for(;!i;)await t.reload({waitUntil:"load"}),await t.waitForTimeout(1500),i=await t.locator(e,a).isVisible();return t.locator(e,a)};class f{constructor(e){this.metaMaskPage=e}async connect2Wallet(){await c(this.metaMaskPage,...o.nextBtn),await this.metaMaskPage.locator(...o.nextBtn).click(),await this.metaMaskPage.locator(...o.connectBtn).click()}async addAndSwitchNetwork(){await c(this.metaMaskPage,...o.approveAddNetworkBtn),await this.metaMaskPage.locator(...o.approveAddNetworkBtn).click(),await this.metaMaskPage.locator(...o.switchNetworkBtn).click()}async confirmTx(){await c(this.metaMaskPage,...o.confirmFeeEtcBtn),await this.metaMaskPage.locator(...o.confirmFeeEtcBtn).click()}}const p=t=>{console.log(`
---pages begin----`),t.pages().forEach(e=>console.log("pageurl",e.url())),t.backgroundPages().forEach(e=>console.log("background page url",e.url())),console.log(`---pages end----
`)};exports.Metamask=f;exports.SELECTORS=o;exports.printPageUrls=p;exports.signinWallet=l;exports.testWithMetaMask=g;exports.waitForMetaMask=c;
