Cypress 27 ๐ฒ Performance โ cy.press, cy.scrollTo, and render timing
Two different kinds of performance concern a Cypress suite, and they are easy to confuse. The first is the cost of the test itself โ how long cy.type(), cy.scrollTo(), and a click actually take to execute, because that cost is paid on every run and it is the difference between a suite that finishes in four minutes and one that finishes in fourteen. The second is the cost of the application โ how long the page took to paint, how long the main thread was blocked, how much layout work a scroll triggered โ and the entire point of measuring it is that the test should observe the application without being part of the number.
The commands in this chapter sit on that boundary. cy.type() fires a synthetic keydown/keypress/input/keyup sequence per character, with a default delay of 10 ms between keystrokes, so a 120-character string costs well over a second of pure test time. cy.press() dispatches a single key at the browser level through the automation protocol, which is both far cheaper and the only way to exercise shortcuts the browser itself handles. cy.scrollTo() accepts a duration that animates the scroll in steps, which exists for realism and costs the test that realism in milliseconds.
This chapter covers those three levers in order, then turns them around: the same commands that cost the test time are the ones used to produce the interactions whose render cost is being measured. The first section covers cy.press(), what “browser-level” means, and why it cannot be a rename of cy.type(). The second covers cy.scrollTo(), its duration and ensureScrollable options, the CSS scroll-behavior: smooth conflict, and the infinite-scroll pattern. The third covers render timing itself โ performance.mark/measure, the double requestAnimationFrame, the Long Animation Frame observer, and the rules for keeping Cypress’s own overhead out of the measurement.
Key point: A Cypress measurement is only as trustworthy as the boundary around it โ read every timestamp inside a single cy.window().then() callback rather than across two commands, because the command queue’s own overhead (tens of milliseconds per command in run mode) will otherwise be counted as the application’s render time, and the resulting number is a measurement of Cypress rather than of the page.
Why render timing exists
The command-queue overhead problem. Every cy. command is enqueued, and the queue advances when the previous command resolves. The gap between two commands โ the enqueue, the resolution, the assertion retry bookkeeping โ is real time in the run and it is not the application’s time. A test that records Date.now() before a click and again after a cy.get() will report the sum of the application’s work and Cypress’s plumbing, and the plumbing is frequently the larger of the two in run mode.
The synthesized-event problem. cy.type() does not press keys; it dispatches DOM events into the application frame, character by character, with a default 10 ms delay between them. That is what makes it reliable โ cy.type() never loses characters to a re-render, and the application sees a clean event sequence. It also means cy.type() cannot trigger anything the browser handles above the DOM: Escape closing a native <dialog>, Tab moving focus out of a shadow root, a keyboard shortcut registered on the browser chrome. Those need an event that originates below the application.
The actionability wait problem. Before an action Cypress checks that the element exists, is visible, is not disabled, and is not covered โ and it retries those checks until the element becomes actionable or defaultCommandTimeout (4 seconds) expires. That retry loop is correct and it is also invisible: a click that took 900 ms was a click that waited 880 ms for an overlay to finish fading. A test whose goal is to measure the app must not silently include an actionability wait in the number.
The “did it paint” problem. A DOM mutation is not a paint. Setting textContent in a click handler updates the DOM synchronously, and the browser may not composite the new pixels until the next animation frame. A timestamp taken immediately after the mutation measures the DOM update and reports it as the render cost, which understates the real number by one to two frames. The double requestAnimationFrame pattern exists solely to move the timestamp past the paint.
The long-task blind spot. Most flake-adjacent performance bugs are not slow renders; they are long tasks that block the main thread and make everything after them late. A 300 ms task that runs during a click handler does not delay the render, it delays the next interaction, the timer callbacks, and the input responsiveness. The Long Animation Frame API and the longtask observer are what surface that number, and neither is visible from a timestamp delta alone.
The trade-off. Measuring render time inside a test costs the fidelity of the measurement โ a real browser under test instrumentation is never quite the uninstrumented experience โ and the alternative is measuring nothing, which is worse. The discipline is to keep the instrumented window as narrow as possible: install the observer before the interaction, take the timestamps inside one callback, and never let the assertion machinery into the window.
a. cy.press() โ browser-level key dispatch
cy.press() fires a single key at the browser level, using the automation protocol rather than synthesized DOM events. It is supported in Chromium-based browsers, it takes one key, and it does not accept modifier combinations โ cy.press('Tab') works, cy.press('Control+A') does not, and the select-all shortcut therefore stays a cy.type() job.
// cypress/e2e/keyboard.cy.ts
it('closes a native dialog with Escape', () => {
cy.visit('/settings');
cy.get('[data-cy=delete-account]').click();
// the <dialog> handles Escape in the browser, not in application code
cy.get('dialog[open]').should('be.visible');
cy.press('Escape'); // browser-level key, Chromium only
cy.get('dialog[open]').should('not.exist');
});
The distinction matters because the two commands sit at different layers. cy.type() targets a specific element and dispatches keydown, keypress, beforeinput, input, and keyup into that element’s document. cy.press() targets the browser and dispatches the same key events at the top of the input pipeline, where the browser’s own handlers โ focus traversal, dialog dismissal, shortcuts โ see them first.
// cy.type(): one element, synthetic events, N chars ร delay
cy.get('[data-cy=search]').type('quarterly report');
// 16 characters ร 10 ms default delay = ~160 ms, plus event dispatch
// cy.press(): one key, native dispatch, no delay option
cy.press('Tab'); // focus moves to the next element
The delay option is the single largest cost knob in cy.type(), and setting it to zero is the standard optimization for a long string that the test does not need to watch being typed. It defaults to 10 ms; a 120-character address or JSON blob typed at the default costs 1.2 seconds of the run for no diagnostic value.
// the default delay dominates the cost of typing a long value
cy.get('[data-cy=notes]').type(longNote); // ~10 ms per char
cy.get('[data-cy=notes]').type(longNote, { delay: 0 }); // near-instant
cy.press() also gives a reliable way to drive a keyboard-only flow and measure it. Because each press is a single protocol round-trip with no per-character delay, twenty Tab presses cost far less than twenty cy.type('{tab}') calls, and the sequence exercises the browser’s real focus traversal instead of the application’s keydown handler.
// tabbing through a form is cheap and exercises native focus order
it('reaches the submit button by keyboard alone', () => {
cy.visit('/checkout');
cy.get('[data-cy=card]').focus();
// one native key dispatch per Tab, no per-character delay
for (let i = 0; i < 4; i++) cy.press('Tab');
cy.focused().should('have.attr', 'data-cy', 'submit');
});
b. cy.scrollTo() and scroll-driven rendering
cy.scrollTo() has three forms โ a position string ('top', 'bottom', 'center'), a coordinates object, and a child-element selector โ and three options that change what the test pays and what the application sees.
// position, coordinates, and child-element forms
cy.get('[data-cy=feed]').scrollTo('bottom'); // position
cy.get('[data-cy=canvas]').scrollTo(0, 400); // x, y
cy.get('[data-cy=list]').scrollTo('li:last'); // child
duration is the option that decides whether the scroll is instantaneous or animated, and it is the one that most often surprises a team optimising a suite. The default is 0, which sets scrollTop directly and takes one frame. Passing a duration makes Cypress interpolate the position across many frames, which is realistic and costs the test exactly that duration.
// default: one assignment, one frame, free
cy.get('[data-cy=feed]').scrollTo('bottom');
// animated: realistic, but the test now waits `duration` ms
cy.get('[data-cy=feed]').scrollTo('bottom', { duration: 1000, easing: 'linear' });
ensureScrollable defaults to true, and it is the option that produces the most confusing error message in the command. If the element has no overflow it cannot be scrolled, and Cypress fails with “cy.scrollTo() failed because this element is not scrollable” โ which is usually a CSS bug worth knowing about, and occasionally an element that is genuinely scrollable but only after its content has loaded.
// fail fast when the container has no overflow (the default)
cy.get('[data-cy=feed]').scrollTo('bottom');
// skip the check for a container that becomes scrollable after loading
cy.get('[data-cy=log]').scrollTo('bottom', { ensureScrollable: false });
The CSS interaction is the part that costs debugging time. scroll-behavior: smooth on the container (or on html) makes every programmatic scroll animated by the browser itself, and it composes badly with Cypress: the assertion after cy.scrollTo() can fire while the smooth scroll is still in motion, and the element under test is halfway up the viewport. Cypress warns about this combination, and the fix is to disable smooth scrolling in the test’s stylesheet rather than to add a wait.
// the app's stylesheet, or a test-only override
// html { scroll-behavior: smooth; } โ conflicts with cy.scrollTo
// in a test, override it before navigating
cy.on('window:before:load', (win) => {
const style = win.document.createElement('style');
style.textContent = 'html, body { scroll-behavior: auto !important; }';
win.document.head.appendChild(style); // restore instant scrolling
});
The pattern that matters most for render timing is incremental scrolling. An infinite feed renders a page of items per scroll event, so the interesting number is not “how long did the scroll take” but “how long did the frame after each scroll take”. Scrolling to the bottom in one call skips that entirely.
// scroll one viewport at a time and measure each frame
it('renders incrementally while scrolling', () => {
cy.visit('/feed');
cy.get('[data-cy=feed]').then(($feed) => {
const step = $feed[0].clientHeight;
for (let offset = 0; offset < step * 5; offset += step) {
cy.get('[data-cy=feed]').scrollTo(0, offset); // one viewport
cy.get('[data-cy=feed]').find('[data-cy=item]').should('have.length.greaterThan', 0);
}
});
});
Lazy-loaded images are the same problem in a different shape. A <img loading="lazy"> inside a scrolled container does not request its source until the intersection observer fires, so a test that scrolls past it and asserts on .should('be.visible') measures visibility of a box whose pixels have not arrived. Asserting on the natural width is what waits for the decode.
// the box is visible before the image has loaded; assert on the pixels
cy.get('[data-cy=feed]').scrollTo('bottom');
cy.get('[data-cy=thumb]')
.first()
.should(($img) => {
expect(($img[0] as HTMLImageElement).naturalWidth).to.be.greaterThan(0);
});
c. Render timing โ marks, frames, and long tasks
The measurement primitives all live in the application’s frame, and cy.window() is the way to reach them. The AUT runs in an iframe, so cy.window() yields the application’s window โ its performance object holds entries for the application’s work, not for the Cypress runner’s.
The first rule is that a timing window must not span two commands. Every command boundary is a scheduling gap, and across a dozen commands the gap is larger than the thing being measured.
// WRONG: the window spans a command boundary
cy.window().then((win) => { win.__t0 = win.performance.now(); });
cy.get('[data-cy=refresh]').click(); // gap included
cy.window().then((win) => { win.__t1 = win.performance.now(); });
// RIGHT: one callback, one command boundary, no queue overhead inside
cy.window().then((win) => {
const t0 = win.performance.now();
win.document.querySelector('[data-cy=refresh]')!.click();
const t1 = win.performance.now();
cy.wrap(t1 - t0).should('be.lessThan', 100); // ms
});
The second rule is that the paint happens after the mutation, so a timestamp taken straight after a DOM change stops short. Two nested requestAnimationFrame callbacks land after the frame has been painted, and that pairing is the standard way to timestamp a render.
// resolve after the browser has painted the change
cy.window().then((win) => {
return new Cypress.Promise<number>((resolve) => {
const t0 = win.performance.now();
win.requestAnimationFrame(() => {
win.requestAnimationFrame(() => {
resolve(win.performance.now() - t0); // after the second paint
});
});
});
});
performance.mark() and performance.measure() are the durable record. A mark is a named timestamp in the frame’s timeline; a measure is a named delta between two marks, and it survives into the trace and the DevTools Performance panel where it appears on the timeline next to the layout and paint events it is measuring.
// named marks survive into the DevTools performance timeline
cy.window().then((win) => {
win.performance.mark('list:start');
win.document.querySelector('[data-cy=refresh]')!.click();
win.performance.mark('list:end');
win.performance.measure('list:render', 'list:start', 'list:end');
const [m] = win.performance.getEntriesByName('list:render');
cy.wrap(m.duration).should('be.lessThan', 100); // milliseconds
});
Long tasks are the measurement that a timestamp delta cannot produce, because a long task delays work that has not started yet rather than the work in flight. The longtask observer reports every task over 50 ms, and the long-animation-frame observer (Chromium 123+) reports frames over 50 ms with attribution โ which script, which function, how much time.
// install the observer before the interaction that might block
cy.window().then((win) => {
win.__long = [];
new win.PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
win.__long.push({ start: entry.startTime, dur: entry.duration });
}
}).observe({ type: 'longtask', buffered: true }); // > 50 ms tasks
});
// after the interaction, assert none of the tasks were long
cy.get('[data-cy=filter]').click();
cy.window().then((win) => {
const worst = Math.max(0, ...win.__long.map((t: { dur: number }) => t.dur));
cy.wrap(worst).should('be.lessThan', 50); // the threshold
});
elementtiming is the attribute that makes a specific element’s paint time observable. Adding elementtiming="hero" to the element and observing the element entry type reports when that element’s pixels were rendered, which is the closest the browser gets to a per-component paint number.
// <img src="hero.jpg" elementtiming="hero">
cy.window().then((win) => {
new win.PerformanceObserver((list) => {
for (const e of list.getEntries()) win.__hero = e.startTime;
}).observe({ type: 'element', buffered: true });
});
One compatibility rule governs all of this: cy.clock() replaces Date, setTimeout, and setInterval, and a render timing test that fakes the clock also freezes the animation-frame scheduling it depends on. cy.clock() with no arguments stubs the timers; passing the array form limits it to what is named. A render test should use neither, or should limit the fake to Date alone.
// fakes only Date; timers and rAF stay real, so timing still works
cy.clock(Date.UTC(2025, 0, 1), ['Date']);
Complete Example Session
// ============================================
// PART 1: THE CHEAP KEYBOARD FLOW
// ============================================
// cypress/e2e/perf.cy.ts
describe('render performance', () => {
it('reaches submit with native tab presses', () => {
cy.visit('/checkout');
cy.get('[data-cy=card]').focus();
// one protocol dispatch per key; no per-character delay
for (let i = 0; i < 3; i++) cy.press('Tab');
cy.focused().should('have.attr', 'data-cy', 'submit');
});
// ============================================
// PART 2: THE TYPING COST
// ============================================
it('fills a long note quickly', () => {
const note = 'a'.repeat(200);
// 200 chars ร 10 ms default = 2 s with the default delay
cy.get('[data-cy=note]').type(note, { delay: 0 }); // near-instant
cy.get('[data-cy=note]').should('have.value', note);
});
// ============================================
// PART 3: THE SCROLL, INSTANT
// ============================================
it('scrolls the feed to the bottom', () => {
cy.visit('/feed');
cy.get('[data-cy=feed]').scrollTo('bottom'); // duration 0
cy.get('[data-cy=item]').should('have.length.greaterThan', 20);
});
// ============================================
// PART 4: THE SCROLL, LAZY IMAGES
// ============================================
it('decodes thumbnails after scrolling', () => {
cy.visit('/feed');
cy.get('[data-cy=feed]').scrollTo('bottom', { ensureScrollable: false });
cy.get('[data-cy=thumb]').first().should(($img) => {
// naturalWidth is 0 until the image data has decoded
expect(($img[0] as HTMLImageElement).naturalWidth).to.be.greaterThan(0);
});
});
// ============================================
// PART 5: THE SMOOTH-SCROLL OVERRIDE
// ============================================
beforeEach(() => {
cy.on('window:before:load', (win) => {
const s = win.document.createElement('style');
s.textContent = 'html, body { scroll-behavior: auto !important; }';
win.document.head.appendChild(s); // undo smooth
});
});
// ============================================
// PART 6: THE MEASUREMENT WINDOW
// ============================================
it('renders the refreshed list within 100 ms', () => {
cy.visit('/orders');
cy.window().then((win) => {
win.performance.mark('list:start');
win.document.querySelector<HTMLElement>('[data-cy=refresh]')!.click();
win.performance.mark('list:end');
win.performance.measure('list:render', 'list:start', 'list:end');
const [m] = win.performance.getEntriesByName('list:render');
cy.wrap(m.duration).should('be.lessThan', 100); // milliseconds
});
});
// ============================================
// PART 7: THE PAINT-AWARE TIMESTAMP
// ============================================
it('paints the badge after the click', () => {
cy.visit('/cart');
cy.window().then((win) =>
new Cypress.Promise<number>((resolve) => {
const t0 = win.performance.now();
win.document.querySelector<HTMLElement>('[data-cy=apply]')!.click();
win.requestAnimationFrame(() =>
win.requestAnimationFrame(() => resolve(win.performance.now() - t0))
);
})
).then((elapsed) => {
expect(elapsed).to.be.lessThan(150); // two frames
});
});
// ============================================
// PART 8: THE LONG-TASK OBSERVER
// ============================================
it('applies a filter without a long task', () => {
cy.visit('/orders');
cy.window().then((win) => {
win.__long = [];
new win.PerformanceObserver((list) => {
for (const e of list.getEntries()) win.__long.push(e.duration);
}).observe({ type: 'longtask', buffered: true }); // > 50 ms
});
cy.get('[data-cy=filter]').click();
cy.window().then((win) => {
const worst = Math.max(0, ...win.__long);
cy.wrap(worst).should('be.lessThan', 50); // none over 50
});
});
// ============================================
// PART 9: THE CLOCK CAVEAT
// ============================================
it('does not fake timers in a timing test', () => {
// fake Date only; rAF and timers stay real
cy.clock(Date.UTC(2025, 0, 1), ['Date']);
cy.visit('/dashboard');
cy.window().then((win) => {
cy.wrap(typeof win.requestAnimationFrame).should('eq', 'function');
});
});
// ============================================
// PART 10: THE MEASURE LOG
// ============================================
afterEach(function () {
cy.window().then((win) => {
win.performance.getEntriesByType('measure').forEach((m) => {
cy.task('log', `MEASURE ${m.name} ${m.duration.toFixed(1)}ms`);
});
});
});
});
The ten parts covered the native-keyboard flow, the delay: 0 typing optimization, an instant scroll, lazy-image decoding, the smooth-scroll override, a performance.measure window, a paint-aware double-rAF timestamp, the longtask observer, the cy.clock caveat, and a cy.task measure log.
Quick Reference
Command defaults
| Command | Option | Default |
|---|---|---|
cy.type() | delay | 10 ms per char |
cy.press() | keys | One key, Chromium only |
cy.scrollTo() | duration | 0 (instant) |
cy.scrollTo() | easing | 'swing' |
cy.scrollTo() | ensureScrollable | true |
Render timing APIs
| API | Reports |
|---|---|
performance.mark() | Named timestamp |
performance.measure() | Named delta between marks |
requestAnimationFrame ร2 | After-paint timestamp |
longtask observer | Tasks > 50 ms |
long-animation-frame | Frames > 50 ms, with attribution |
element + elementtiming | Per-element paint time |
paint observer | first-paint, first-contentful-paint |
Thresholds worth asserting
| Number | Meaning |
|---|---|
| 16 ms | One frame at 60 Hz |
| 50 ms | Long task / long animation frame boundary |
| 100 ms | Interaction still feels instantaneous |
| 200 ms | Upper bound for a “responsive” interaction |
Where the overhead hides
| Source | Cost |
|---|---|
| Command boundary | Tens of ms per command in run mode |
cy.type() default delay | 10 ms per character |
cy.scrollTo({ duration }) | The duration itself |
| Actionability retry | Up to defaultCommandTimeout |
cy.clock() timer fakes | Freezes rAF-dependent timing |
Best Practices
โ Do This:
// Use browser-level keys for browser-level shortcuts
cy.press('Escape'); // โ
// Drop the typing delay when the keystrokes are not the subject
cy.get('[data-cy=note]').type(text, { delay: 0 }); // โ
// Keep scrolls instant unless the animation is under test
cy.get('[data-cy=feed]').scrollTo('bottom'); // โ
// Measure inside one callback, never across commands
cy.window().then((win) => { mark(); click(); mark(); measure(); }); // โ
// Timestamp after the paint with two rAFs
win.requestAnimationFrame(() => win.requestAnimationFrame(resolve)); // โ
// Assert on long tasks, not just on elapsed time
.observe({ type: 'longtask', buffered: true }); // โ
// Fake only `Date` in a timing test
cy.clock(Date.UTC(2025, 0, 1), ['Date']); // โ
โ Don’t Do This:
// Time across a command boundary
cy.window().then((w) => (w.__t0 = performance.now()));
cy.get('[data-cy=x]').click(); // โ gap
cy.window().then((w) => (w.__t1 = performance.now())); // โ
// Animate the scroll to make the test "realistic"
cy.get('[data-cy=feed]').scrollTo('bottom', { duration: 2000 }); // โ
// Type a 200-char blob at the default delay
cy.get('[data-cy=note]').type('a'.repeat(200)); // โ ~2 s
// Try a modifier combo with cy.press
cy.press('Control+A'); // โ
// Leave `scroll-behavior: smooth` in place
// html { scroll-behavior: smooth; } // โ
// Fake every timer and then measure rAF
cy.clock(); // โ
// Assert on a timestamp taken right after the mutation
el.textContent = 'x'; const t = performance.now(); // โ
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Measurement includes Cypress | Window spans commands | One cy.window().then() |
| Scroll assertion races | scroll-behavior: smooth | Override to auto |
| Suite is slow | cy.type default delay | { delay: 0 } |
cy.press errors | Modifier combination | Use cy.type for combos |
cy.press unsupported | Non-Chromium browser | Gate on Cypress.browser |
| Scroll fails | ensureScrollable on empty box | { ensureScrollable: false } |
| Render looks instant | Timestamp before paint | Double rAF |
| Jank invisible | Only elapsed time measured | Add longtask observer |
| Timing breaks under clock | cy.clock() faked timers | ['Date'] only |
| Image assertion passes early | Box visible, pixels not | naturalWidth > 0 |
Real-World Examples
1. Native Escape
cy.press('Escape'); // closes a <dialog>
2. Gate on the browser
if (Cypress.browser.family === 'chromium') cy.press('Tab');
3. No typing delay
cy.get('[data-cy=note]').type(note, { delay: 0 });
4. Instant scroll
cy.get('[data-cy=feed]').scrollTo('bottom');
5. Animated scroll, deliberate
cy.get('[data-cy=feed]').scrollTo('bottom', { duration: 300 });
6. Lazy image decoded
expect(($img[0] as HTMLImageElement).naturalWidth).to.be.greaterThan(0);
7. Measure
win.performance.measure('render', 'start', 'end');
8. After paint
win.requestAnimationFrame(() => win.requestAnimationFrame(done));
9. Long task
.observe({ type: 'longtask', buffered: true });
10. Log the measure
cy.task('log', `${m.name} ${m.duration.toFixed(1)}ms`);
Visual
The layer each command fires at
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ WHERE EACH COMMAND FIRES โ
โ โ
โ browser process โ
โ โโ cy.press('Tab') native key, protocol dispatch โ
โ โ
โ application frame โ
โ โโ cy.type() keydown/keypress/input/keyup โ
โ per character, 10 ms apart โ
โ โโ cy.get().click() query, actionability, dispatch โ
โ โโ cy.scrollTo() scrollTop assignment or frames โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Typing cost vs press cost
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TYPING COST VS PRESS COST โ
โ โ
โ cy.type('hello') โ
โ h โ e โ l โ l โ o 5 ร (delay 10 ms + 4 events) โ
โ total โ 50 ms+ of test time โ
โ โ
โ cy.press('Tab') โ
โ one key โโบ one dispatch โโบ keydown/keypress/keyup โ
โ total โ 1 ms of test time โ
โ โ
โ cy.type('...', { delay: 0 }) โ
โ events only, no wait between them โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The two kinds of timing window
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TIMING WINDOWS โ
โ โ
โ WRONG โ spans command boundaries โ
โ t0 โโ[queue gap]โโ click โโ[queue gap]โโ t1 โ
โ measures Cypress + app โ
โ โ
โ RIGHT โ one callback โ
โ t0 โโ click โโ t1 (inside cy.window().then) โ
โ measures app only โ
โ โ
โ PAINT-AWARE โ
โ t0 โโ click โโ DOM โโ rAF โโ paint โโ rAF โโ t1 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Scroll-driven rendering
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SCROLL-DRIVEN RENDERING โ
โ โ
โ scrollTo('bottom') one jump โ
โ โโ one frame, one render โ
โ โ
โ scrollTo ร 5 viewports incremental โ
โ โโ frame 1 โโบ items 1..10 โ
โ โโ frame 2 โโบ items 11..20 โ
โ โโ frame 3 โโบ items 21..30 โ
โ โโ each frame measurable separately โ
โ โ
โ lazily loaded thumbnails โ
โ box visible โ pixels decoded โ
โ assert naturalWidth > 0 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
cy.press() | One native key, Chromium-based browsers |
cy.press() scope | Browser level, no modifier combos |
cy.type() default delay | 10 ms per character |
cy.type() fast form | { delay: 0 } |
cy.scrollTo() default duration | 0 (instant) |
cy.scrollTo() scrollability check | ensureScrollable: true |
| Smooth-scroll conflict | scroll-behavior: smooth on html/body |
| Timing boundary | One cy.window().then() callback |
| After-paint timestamp | Two nested rAF calls |
| Long task threshold | 50 ms |
cy.clock() in timing tests | Fake Date only |
Key takeaways:
cy.press()andcy.type()are not the same command at different speeds.cy.type()dispatches synthetic DOM events into the application frame, character by character, with a 10 ms default delay.cy.press()dispatches a single key at the browser level through the automation protocol, which is both far cheaper and the only way to exercise shortcuts the browser itself handles. The line between them is the line between “the app handles this key” and “the browser handles this key”.- The
delayoption is the largest cost knob incy.type(). At the default, a 200-character value costs two seconds of run time for no diagnostic return.{ delay: 0 }keeps the event sequence and drops the wait, and it is safe whenever the test is not asserting on keystroke timing. cy.scrollTo({ duration })spends the test’s time to buy realism. The default of0assignsscrollTopand renders one frame. A duration animates the scroll across many frames, which is genuinely more realistic and costs the test exactly the duration. Use it when the animation is under test, not otherwise.scroll-behavior: smoothis a race, not a bug. Browser-driven smooth scrolling means the assertion aftercy.scrollTo()can fire mid-scroll. Override the property toautoinwindow:before:loadrather than adding a wait, because the wait fixes one instance and the override fixes all of them.- A timing window must live inside one callback. The command queue’s own overhead โ tens of milliseconds per command in run mode โ is counted as the application’s time whenever a measurement spans two commands.
cy.window().then()with the click, the marks, and the assertion inside it is the only shape that measures the page. - A DOM mutation is not a paint. Two nested
requestAnimationFramecallbacks resolve after the frame has been composited. A timestamp taken straight aftertextContent = 'x'measures the DOM write and reports it as the render cost, which understates it by one to two frames. - Elapsed time never shows jank; long tasks do. A 300 ms task blocks everything scheduled after it, and none of that appears in a
t1 - t0delta. Thelongtaskorlong-animation-frameobserver is what turns “the click was fast” into “the main thread was blocked for a third of a second during the click”.
Remember: The performance work in Cypress splits cleanly into making the test cheap and measuring the application honestly, and the same three commands serve both halves. cy.press(), cy.type({ delay: 0 }), and an instant cy.scrollTo() keep the suite fast rather than slow, because the interaction cost the test pays is not the interaction cost the user pays. performance.mark/measure, the double rAF, and the longtask observer produce the number that is worth asserting on, and they produce it only when the window is narrow โ one callback, timestamps after the paint, timers left real. Get the boundary right and the number means something; get it wrong and the suite is measuring itself.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!