Get memory consumption of web app with Cypress

Recently when checking performance of the web app I’ve worked on, I needed to get the memory consumption of web app after certain behavior actions.

To do it with Cypress, first we need to capture the app performance using the below command in the Cypress test block:

cy.window().then((window) => {
firstTask = window.performance.memory.usedJSHeapSize
})

By default, Chrome does not capture real time memory consumption of current browser session. Instead it checks for every 20 seconds. To get the real time memory consumption, we need to pass the following argument when initiate the Chrome browser session by updating the cypress.config.ts

export default defineConfig({
chromeWebSecurity: false,
waitForAnimations: true,
defaultCommandTimeout: 10000,
requestTimeout: 10000,
responseTimeout: 10000,
projectId: '4oe38f',
video: true,
experimentalStudio: true,
e2e: {
setupNodeEvents(on, config) {

on('before:browser:launch', (browser = {
name: "",
family: "chromium",
channel: "",
displayName: "",
version: "",
majorVersion: "",
path: "",
isHeaded: false,
isHeadless: false
}, launchOptions) => {
if (browser.family === 'chromium' && browser.name !== 'electron') {
// auto open devtools
launchOptions.args.push('--enable-precise-memory-info')
}

return launchOptions

})

},
baseUrl: '${baseUrl}',
specPattern: 'cypress/**/*.{js,jsx,ts,tsx}',
},
});

Notice the line of code:

launchOptions.args.push('--enable-precise-memory-info')

Hope it helps~~

~~PEACE~~

--

--

For those who are interested in automating the stuffs, CI/CD pipeline, automation test..

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Donald Le

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.