The wallet cache feature of Synpress is its crown jewel. It allows you to define in a separate file how the wallet should be installed and set up. Based on this file, Synpress generates a browser cache that is then used as a starting point for the tests. This allows you to skip the wallet installation and setup steps, which can be quite time-consuming.Documentation Index
Fetch the complete documentation index at: https://docs.synpress.io/llms.txt
Use this file to discover all available pages before exploring further.
Writing a wallet setup file
File name
Since wallet setup files play a crucial role, they must follow a strict naming convention. The file name must follow this format:*.setup.{ts,js,mjs}.
Here are some examples of valid file names:
basic.setup.tsconnected.setup.tsoptimism.setup.tsmulti-user.setup.ts
Import
Let’s start with the import statement. You need to import thedefineWalletSetup function from @synthetixio/synpress:
Prepare seed phrase and password
Next, you need to define the seed phrase and password that will be used to import the wallet. You can define them as constants, use environment variables, or do whatever suits your needs.Define the wallet setup
Finally, you need to define the wallet setup steps. This is done by calling thedefineWalletSetup function. It takes two arguments, the password, and the setup function.
The setup function is where the magic happens. Contents of this function will be executed in the browser context, which means you can use all browser-related Playwright APIs.
Here’s how you can import a wallet with MetaMask or Phantom:
- MetaMask
- Phantom
- MetaMask
- Phantom
Building the cache
Once you’ve written your wallet setup file, you must build its cache. This is done with our CLI toolsynpress. Here’s how to do it:
- MetaMask
- Phantom
[PROJECT_ROOT]/test/wallet-setup directory. If you want to use a different one, you can pass it as an argument to the CLI:
- MetaMask
- Phantom
How it works
Basics
Understanding how the wallet cache works is crucial for writing wallet setup files. Let’s start with the basics. Here’s the wallet setup file from the previous section:- MetaMask
- Phantom
basic.setup.ts
[PROJECT_ROOT]/.cache-synpress directory.
Each cache is saved in a separate directory named after the hash of the wallet setup file.
Hash generation
The hash is generated ONLY from the contents of the function you pass to thedefineWalletSetup function. This means you can import other files, define constants, etc., without affecting the hash.
Based on the wallet setup above, only the following lines will be used to generate the hash:
- MetaMask
- Phantom
SEED_PHRASE constant and inline it like this:
- MetaMask
- Phantom
Things to keep in mind
Here are a few things that are important to keep in mind when dealing with setup files:- You can do whatever you want in the setup function as long as it’s not affecting the state of a blockchain in any way. This means you can add wallets, networks, change settings, etc., but you cannot send any transactions. However, you can still sign data with imported wallets, which is useful for connecting to dapps. With this, you can start tests with a fully configured wallet connected to a dapp.
- You don’t have to close the browser or any tabs in the setup function. Synpress will handle everything.
- You can have multiple wallet setup files. Synpress will generate a cache for each of them. However, currently, all caches are built in parallel, so if you have a ton of setup files and a slow computer, it might be impossible to build them. We’re working on a solution for this.

