Skip to content

metamask.setup() ​

Initializes the MetaMask browser extension for testing by creating a new wallet or importing an existing wallet, and optionally configuring an RPC network.

This command is provided by the built-in metamask plugin and automates the entire MetaMask onboarding flow (terms of service, password creation, seed phrase confirmation, and introductory modal dismissals).

Paid Add-On: MetaMask Test Runner

This command requires running tests on the MetaMask browser runner, which is available as a paid add-on for your UI-licious workspace. Businesses can contact our team at [email protected] or visit uilicious.com/contact-sales to request a trial.

Load the Plugin

The metamask plugin must be loaded in your test script before calling metamask.setup():

js
let metamask = TEST.loadPlugin("metamask")

Usage ​

js
// Load the plugin
let metamask = TEST.loadPlugin("metamask")

// 1. Create a fresh wallet on Ethereum Mainnet
metamask.setup()

// 2. Import an existing wallet
metamask.setup({
    wallet: {
        passphrase: "<12 or 24-word seed phrase>"
    }
})

// 3. Import wallet and configure custom RPC network
metamask.setup({
    wallet: {
        passphrase: "<12 or 24-word seed phrase>"
    },
    network: {
        name: "Sepolia Testnet",
        rpcURL: "https://rpc.sepolia.org",
        chainID: 11155111,
        currencySymbol: "SEP"
    }
})

Parameters ​

ParameterTypeDescription
configobjectOptional configuration object specifying wallet and network settings (see below).

Configuration Object ​

PropertyTypeDescription
walletobjectOptional wallet configuration. If omitted, a brand new wallet is created.
wallet.passphrasestringThe 12- or 24-word secret recovery seed phrase.
networkobject | stringOptional network configuration. Can be a predefined network name (e.g. "Aurora Mainnet") or a custom RPC object (see below).
network.namestringRequired. Name of the network.
network.rpcURLstringJSON-RPC endpoint URL for custom networks.
network.chainIDnumber | stringBlockchain network Chain ID.
network.currencySymbolstringTicker symbol for the native gas token (e.g. "ETH", "SEP").
network.explorerURLstringOptional block explorer URL (e.g. "https://sepolia.etherscan.io").

Associated Helper Methods ​

When the metamask plugin is loaded, the following helper methods are also available:

MethodReturn TypeDescription
metamask.getPassphrase()stringReturns the recovery seed phrase generated or imported for the active wallet.
metamask.getDevicePassword()stringReturns the session device password generated by the plugin to unlock MetaMask.

Examples ​

Create a Fresh Wallet ​

js
let metamask = TEST.loadPlugin("metamask")

// Create a new wallet
metamask.setup()

// Print the generated seed phrase to the test report
TEST.log.info("Passphrase: ", metamask.getPassphrase())

Import an Existing Testnet Wallet ​

js
let metamask = TEST.loadPlugin("metamask")

metamask.setup({
    wallet: {
        passphrase: DATA.testnet_passphrase
    }
})

Setup with Custom RPC Testnet ​

js
let metamask = TEST.loadPlugin("metamask")

metamask.setup({
    wallet: {
        passphrase: DATA.testnet_passphrase
    },
    network: {
        name: "Localhost 8545",
        rpcURL: "http://127.0.0.1:8545",
        chainID: 31337,
        currencySymbol: "ETH"
    }
})

See Also ​