MetaMask class for interacting with the MetaMask extension in Playwright tests.

This class provides methods to perform various operations on the MetaMask extension, such as importing wallets, switching networks, confirming transactions, and more.

Extends

  • MetaMaskAbstract

Constructors

new MetaMask()

new MetaMask(
   context, 
   page, 
   password, 
   extensionId?): MetaMask

Creates an instance of MetaMask.

Parameters

ParameterTypeDescription
contextBrowserContextThe Playwright BrowserContext in which the MetaMask extension is running.
pagePageThe Playwright Page object representing the MetaMask extension’s main page.
passwordstringThe password for the MetaMask wallet.
extensionId?stringThe ID of the MetaMask extension. Optional if no interaction with dapps is required.

Returns

MetaMask

Overrides

MetaMaskAbstract.constructor

Properties

PropertyModifierTypeDescriptionOverrides
contextreadonlyBrowserContext--
crashPagereadonlyCrashPageThis property can be used to access selectors for the crash page.-
extensionId?readonlystring-MetaMaskAbstract.extensionId
homePagereadonlyHomePageThis property can be used to access selectors for the home page.-
lockPagereadonlyLockPageThis property can be used to access selectors for the lock page.-
notificationPagereadonlyNotificationPageThis property can be used to access selectors for the notification page.-
onboardingPagereadonlyOnboardingPageThis property can be used to access selectors for the onboarding page.-
pagereadonlyPage--
passwordreadonlystring-MetaMaskAbstract.password
settingsPagereadonlySettingsPageThis property can be used to access selectors for the settings page.-

Methods

addNetwork()

addNetwork(network): Promise<void>

Adds a new network to MetaMask.

Parameters

ParameterTypeDescription
networkobjectThe network configuration to add.
network.blockExplorerUrl?string-
network.chainIdnumber-
network.namestring-
network.rpcUrlstring-
network.symbolstring-

Returns

Promise<void>

Overrides

MetaMaskAbstract.addNetwork


addNewAccount()

addNewAccount(accountName): Promise<void>

Adds a new account with the given name.

Parameters

ParameterTypeDescription
accountNamestringThe name for the new account.

Returns

Promise<void>

Overrides

MetaMaskAbstract.addNewAccount


addNewToken()

addNewToken(): Promise<void>

Adds a new token.

Returns

Promise<void>

Overrides

MetaMaskAbstract.addNewToken

Throws

If extensionId is not set.


approveNewNetwork()

approveNewNetwork(): Promise<void>

Approves adding a new network.

Returns

Promise<void>

Overrides

MetaMaskAbstract.approveNewNetwork

Throws

If extensionId is not set.


approveSwitchNetwork()

approveSwitchNetwork(): Promise<void>

Approves switching to a new network.

Returns

Promise<void>

Overrides

MetaMaskAbstract.approveSwitchNetwork

Throws

If extensionId is not set.


approveTokenPermission()

approveTokenPermission(options?): Promise<void>

Approves a token permission request.

Parameters

ParameterTypeDescription
options?objectOptional settings for the approval.
options.gasSetting?| "low" | "market" | "aggressive" | "site" | { "gasLimit": number; "maxBaseFee": number; "priorityFee": number; }-
options.spendLimit?number | "max"-

Returns

Promise<void>

Overrides

MetaMaskAbstract.approveTokenPermission

Throws

If extensionId is not set.


closeTransactionDetails()

closeTransactionDetails(): Promise<void>

Closes the transaction details view.

Returns

Promise<void>

Overrides

MetaMaskAbstract.closeTransactionDetails


confirmSignature()

confirmSignature(): Promise<void>

Confirms a signature request.

Returns

Promise<void>

Overrides

MetaMaskAbstract.confirmSignature

Throws

If extensionId is not set.


confirmSignatureWithRisk()

confirmSignatureWithRisk(): Promise<void>

Confirms a signature request with risk.

Returns

Promise<void>

Overrides

MetaMaskAbstract.confirmSignatureWithRisk

Throws

If extensionId is not set.


confirmTransaction()

confirmTransaction(options?): Promise<void>

Confirms a transaction.

Parameters

ParameterTypeDescription
options?objectOptional gas settings for the transaction.
options.gasSetting?| "low" | "market" | "aggressive" | "site" | { "gasLimit": number; "maxBaseFee": number; "priorityFee": number; }-

Returns

Promise<void>

Overrides

MetaMaskAbstract.confirmTransaction

Throws

If extensionId is not set.


confirmTransactionAndWaitForMining()

confirmTransactionAndWaitForMining(options?): Promise<void>

Confirms a transaction and waits for it to be mined.

Parameters

ParameterTypeDescription
options?objectOptional gas settings for the transaction.
options.gasSetting?| "low" | "market" | "aggressive" | "site" | { "gasLimit": number; "maxBaseFee": number; "priorityFee": number; }-

Returns

Promise<void>

Overrides

MetaMaskAbstract.confirmTransactionAndWaitForMining

Throws

If extensionId is not set.


connectToDapp()

connectToDapp(accounts?): Promise<void>

Connects MetaMask to a dapp.

Parameters

ParameterTypeDescription
accounts?string[]Optional array of account addresses to connect.

Returns

Promise<void>

Overrides

MetaMaskAbstract.connectToDapp

Throws

If extensionId is not set.


decrypt()

decrypt(): Promise<void>

Decrypts a message.

Returns

Promise<void>

Overrides

MetaMaskAbstract.decrypt

Throws

If extensionId is not set.


disableEthSign()

disableEthSign(): Promise<void>

Disables eth_sign.

Returns

Promise<void>

Overrides

MetaMaskAbstract.disableEthSign


getAccountAddress()

getAccountAddress(): Promise<string>

Gets the address of the currently selected account.

Returns

Promise<string>

The account address.

Overrides

MetaMaskAbstract.getAccountAddress


goBackToHomePage()

goBackToHomePage(): Promise<void>

Navigates back to the home page.

Returns

Promise<void>

Overrides

MetaMaskAbstract.goBackToHomePage


importWallet()

importWallet(seedPhrase): Promise<void>

Imports a wallet using the given seed phrase.

Parameters

ParameterTypeDescription
seedPhrasestringThe seed phrase to import.

Returns

Promise<void>

Overrides

MetaMaskAbstract.importWallet


importWalletFromPrivateKey()

importWalletFromPrivateKey(privateKey): Promise<void>

Imports a wallet using the given private key.

Parameters

ParameterTypeDescription
privateKeystringThe private key to import.

Returns

Promise<void>

Overrides

MetaMaskAbstract.importWalletFromPrivateKey


lock()

lock(): Promise<void>

Locks the MetaMask wallet.

Returns

Promise<void>

Overrides

MetaMaskAbstract.lock


openSettings()

openSettings(): Promise<void>

Opens the settings page.

Returns

Promise<void>

Overrides

MetaMaskAbstract.openSettings


openSidebarMenu()

openSidebarMenu(menu): Promise<void>

Opens a specific sidebar menu in the settings.

Parameters

ParameterTypeDescription
menuSettingsSidebarMenusThe menu to open.

Returns

Promise<void>

Overrides

MetaMaskAbstract.openSidebarMenu


openTransactionDetails()

openTransactionDetails(txIndex): Promise<void>

Opens the details of a specific transaction.

Parameters

ParameterTypeDescription
txIndexnumberThe index of the transaction to open.

Returns

Promise<void>

Overrides

MetaMaskAbstract.openTransactionDetails


providePublicEncryptionKey()

providePublicEncryptionKey(): Promise<void>

Provides a public encryption key.

Returns

Promise<void>

Overrides

MetaMaskAbstract.providePublicEncryptionKey

Throws

If extensionId is not set.


rejectNewNetwork()

rejectNewNetwork(): Promise<void>

Rejects adding a new network.

Returns

Promise<void>

Overrides

MetaMaskAbstract.rejectNewNetwork

Throws

If extensionId is not set.


rejectSignature()

rejectSignature(): Promise<void>

Rejects a signature request.

Returns

Promise<void>

Overrides

MetaMaskAbstract.rejectSignature

Throws

If extensionId is not set.


rejectSwitchNetwork()

rejectSwitchNetwork(): Promise<void>

Rejects switching to a new network.

Returns

Promise<void>

Overrides

MetaMaskAbstract.rejectSwitchNetwork

Throws

If extensionId is not set.


rejectTokenPermission()

rejectTokenPermission(): Promise<void>

Rejects a token permission request.

Returns

Promise<void>

Overrides

MetaMaskAbstract.rejectTokenPermission

Throws

If extensionId is not set.


rejectTransaction()

rejectTransaction(): Promise<void>

Rejects a transaction.

Returns

Promise<void>

Overrides

MetaMaskAbstract.rejectTransaction

Throws

If extensionId is not set.


renameAccount()

renameAccount(currentAccountName, newAccountName): Promise<void>

Renames the currently selected account.

Parameters

ParameterTypeDescription
currentAccountNamestringThe current account name.
newAccountNamestringThe new name for the account.

Returns

Promise<void>


resetAccount()

resetAccount(): Promise<void>

Resets the account.

Returns

Promise<void>

Overrides

MetaMaskAbstract.resetAccount


switchAccount()

switchAccount(accountName): Promise<void>

Switches to the account with the given name.

Parameters

ParameterTypeDescription
accountNamestringThe name of the account to switch to.

Returns

Promise<void>

Overrides

MetaMaskAbstract.switchAccount


switchNetwork()

switchNetwork(networkName, isTestnet?): Promise<void>

Switches to the specified network.

Parameters

ParameterTypeDescription
networkNamestringThe name of the network to switch to.
isTestnet?booleanWhether the network is a testnet. Default is false.

Returns

Promise<void>

Overrides

MetaMaskAbstract.switchNetwork


toggleDismissSecretRecoveryPhraseReminder()

toggleDismissSecretRecoveryPhraseReminder(): Promise<void>

Toggles the dismissal of the secret recovery phrase reminder.

Returns

Promise<void>

Overrides

MetaMaskAbstract.toggleDismissSecretRecoveryPhraseReminder


toggleShowTestNetworks()

toggleShowTestNetworks(): Promise<void>

Toggles the display of test networks.

Returns

Promise<void>

Overrides

MetaMaskAbstract.toggleShowTestNetworks


unlock()

unlock(): Promise<void>

Unlocks the MetaMask wallet.

Returns

Promise<void>

Overrides

MetaMaskAbstract.unlock


unsafe_enableEthSign()

unsafe_enableEthSign(): Promise<void>

Enables eth_sign (unsafe).

Returns

Promise<void>

Overrides

MetaMaskAbstract.unsafe_enableEthSign