Migration Guide
Synpress v3 to v4
Synpress v4 introduces significant improvements in functionality, performance, and API design. This guide will help you seamlessly transition your tests from v3 to v4.
This migration guide is particularly for Cypress users. If you’re using Playwright with Synpress, please refer to the Playwright-specific documentation.
Key Changes Overview
- Installation: Unchanged
- Configuration: New MetaMask-specific setup
- Support Files: More granular command imports
- TypeScript Configuration: Written in TypeScript to improve compatibility and readability
- Test Structure: Simplified with automatic page visits
- MetaMask Interactions: Renamed and enhanced commands
- Test Execution: Standardized Cypress command
- Configuration Options: Expanded for greater flexibility
Key Changes
- Installation:
The installation process remains the same in v4.
-
Configuration:
-
Update your
cypress.config.ts
:
The v4 configuration uses
configureSynpressForMetaMask
instead of the previouscypressGrepPlugin
. This new function handles MetaMask-specific setup automatically. -
-
Support Files:
-
Create or update
src/cypress/support/e2e.ts
:
In v4, you import
synpressCommandsForMetaMask
instead of the previous global import. This allows for more granular control over which commands are available in your tests. -
-
TypeScript Configuration:
-
Update your
tsconfig.json
:
The v4 TypeScript configuration is more streamlined, focusing on Cypress types and ensuring compatibility with ES modules.
-
-
Test Structure:
- v4 no longer requires explicit
cy.visit()
calls in tests orbefore()
hooks - The initial page visit is now handled by the configuration step
This change simplifies test structure and further improves performance by eliminating redundant page loads.
Example:
This approach is correct and aligns with Cypress best practices for optimizing test performance.
- v4 no longer requires explicit
-
MetaMask Interactions:
- Many MetaMask-specific commands have been renamed or modified for clarity and ease of use
- Examples of API changes:
Note: This list may not be exhaustive. It’s recommended to check the latest Synpress v4 documentation for a complete list of API changes and new commands that may have been introduced.
-
Test Execution:
- v3: Multiple commands to run tests
- v4: Simplified to use standard Cypress command:
-
Configuration:
- v4: May introduce new configuration options for Synpress and MetaMask setup
Detailed API Changes
Here’s a more detailed breakdown of the API changes between Synpress v3 and v4:
-
Connecting to dApps:
- v3:
cy.acceptMetamaskAccess()
- v4:
cy.connectToDapp()
This change simplifies the command name while maintaining its core functionality.
- v3:
-
Transaction Handling:
- v3:
cy.confirmMetamaskTransaction()
cy.rejectMetamaskTransaction()
- v4:
cy.confirmTransaction()
cy.rejectTransaction()
The new commands are more concise and remove the “Metamask” prefix for clarity.
- v3:
-
Network Management:
- v3:
cy.switchMetamaskNetwork()
cy.addMetamaskNetwork()
- v4:
cy.switchNetwork()
cy.addNetwork()
These changes streamline network-related commands by removing the “Metamask” prefix.
- v3:
-
Wallet Management:
- v3:
cy.importMetamaskAccount()
cy.createMetamaskAccount()
cy.switchMetamaskAccount()
- v4:
cy.importWallet()
- No direct equivalent for
createMetamaskAccount()
cy.switchAccount()
The v4 API simplifies wallet management commands and removes the ability to create new accounts directly.
- v3:
-
Account Information:
- v3:
cy.getMetamaskWalletAddress()
cy.getMetamaskBalance()
- v4:
cy.getAccount()
- No direct equivalent for
getMetamaskBalance()
The v4 API simplifies getting account information but removes the direct balance checking capability.
- v3:
-
New Commands in v4:
cy.emptyAnvilNode()
: Empties the Anvil nodecy.addNetwork()
: Adds a new network to MetaMaskcy.approveNewNetwork()
: Approves a new network in MetaMaskcy.approveSwitchNetwork()
: Approves switching to a different network in MetaMaskcy.rejectNewNetwork()
: Rejects a new network in MetaMaskcy.rejectSwitchNetwork()
: Rejects switching to a different network in MetaMaskcy.deployToken()
: Deploys a new token contractcy.addNewToken()
: Adds a new token to MetaMaskcy.approveTokenPermission()
: Approves token spending permission in MetaMaskcy.rejectTokenPermission()
: Rejects token spending permission in MetaMaskcy.toggleShowTestNetworks()
: Toggles the display of test networks in MetaMaskcy.toggleDismissSecretRecoveryPhraseReminder()
: Toggles the dismissal of the secret recovery phrase remindercy.providePublicEncryptionKey()
: Provides a public encryption keycy.decrypt()
: Decrypts encrypted datacy.confirmSignature()
: Confirms a signature request in MetaMaskcy.rejectSignature()
: Rejects a signature request in MetaMaskcy.confirmTransactionAndWaitForMining()
: Confirms a transaction and waits for it to be minedcy.openTransactionDetails()
: Opens transaction details in MetaMaskcy.closeTransactionDetails()
: Closes transaction details in MetaMaskcy.goBackToHomePage()
: Returns to the MetaMask home pagecy.openSettings()
: Opens MetaMask settingscy.openSidebarMenu()
: Opens a specific sidebar menu in MetaMask settings
Note: The setupMetamask()
function is not present in the provided file. Some commands like connectToDapp()
, disconnectFromDapp()
, switchNetwork()
, lock()
, unlock()
, confirmTransaction()
, and rejectTransaction()
were present in Synpress v3 and have been retained or slightly modified in v4. This list focuses on the new or significantly changed commands in v4.
- Advanced Transaction Handling in v4:
cy.confirmTransaction()
now supports advanced options:
When migrating from v3 to v4, carefully review your existing tests and update the commands according to these changes. Also, consult the latest Synpress v4 documentation for any additional new features or commands that may have been introduced.