Back to Blog
February 24, 2026 min readwrite better assertions testing

Can AI Write Better Assertions? Testing Modern UIs with Replay Logic

R
Replay Team
Developer Advocates

Can AI Write Better Assertions? Testing Modern UIs with Replay Logic

Most end-to-end (E2E) tests fail not because the code is broken, but because humans are terrible at predicting how software actually breaks. We write assertions based on what we hope happens, ignoring the chaotic reality of race conditions, layout shifts, and asynchronous state changes. This gap between expectation and reality contributes heavily to the $3.6 trillion global technical debt burden. If you want to write better assertions testing high-stakes applications, you have to stop guessing and start extracting logic from reality.

TL;DR: Manual assertion writing is a bottleneck that consumes 40 hours per screen. Replay automates this by converting video recordings of UI interactions into production-ready React code and Playwright/Cypress tests. By using video temporal context, Replay captures 10x more context than screenshots, allowing AI agents to generate assertions that are resilient to UI changes.

Why do manual assertions fail in modern frontend engineering?#

The industry standard for testing is broken. Engineers spend hours writing

text
expect(button).toBeVisible()
only for the test to flake because a loading spinner took 50ms longer than usual. According to Replay's analysis, 70% of legacy rewrites fail or exceed their timelines specifically because the existing test suites lack the coverage needed to ensure parity.

When you try to write better assertions testing manually, you are limited by your own mental model of the application. You might assert that a text string exists, but you forget to assert the color, the accessibility tags, or the underlying data structure. This is where Visual Reverse Engineering changes the game.

Visual Reverse Engineering is the process of deconstructing a rendered user interface back into its constituent code, logic, and state by analyzing visual and behavioral data. Replay pioneered this approach to bridge the gap between design and deployment.

Can AI help engineers write better assertions testing complex UI flows?#

The short answer is yes, but only if the AI has the right context. Most AI coding assistants fail at testing because they only see a static snapshot of code or a single screenshot. To write better assertions testing effectively, an AI needs to understand movement, state transitions, and timing.

Replay (replay.build) provides this "temporal context." By recording a video of a bug or a feature flow, Replay extracts the exact DOM changes and state transitions over time. This allows the Replay platform to generate assertions that aren't just "is this there?" but "did this transition correctly from State A to State B?"

The Replay Method: Record → Extract → Modernize#

Industry experts recommend a three-step methodology for modernizing legacy tests and building new ones:

  1. Record: Use the Replay recorder to capture a user flow.
  2. Extract: Replay's engine identifies components, design tokens, and navigation logic.
  3. Modernize: The platform generates pixel-perfect React components and automated E2E tests.

This method reduces the time spent on a single screen from 40 hours of manual work to just 4 hours.

How to write better assertions testing using video temporal context#

Traditional testing tools treat a web page like a flat image. Replay treats it like a living organism. Because Replay captures the video context, it can identify a "Flow Map"—a multi-page navigation detection system that understands how users move through an app.

When an AI agent uses the Replay Headless API, it doesn't just look at the final screen. It analyzes the video to see that a modal appeared, a validation error flashed briefly, and then the form submitted. This allows the AI to generate "surgical" assertions.

Comparison: Manual Testing vs. Replay-Powered Testing#

FeatureManual E2E TestingReplay (Video-to-Code)
Time per Screen40 Hours4 Hours
Context CaptureLow (Static)High (10x more via Video)
MaintenanceHigh (Brittle selectors)Low (AI-powered self-healing)
Legacy SupportPoor (Requires manual docs)Excellent (Extracts from any UI)
Agent IntegrationDifficultNative (Headless API)

Implementing Agentic Testing with Replay#

The next frontier of development is "Agentic Editing." This is where AI agents like Devin or OpenHands use Replay’s Headless API to generate production code programmatically. Instead of a developer sitting down to write better assertions testing a new checkout flow, they simply record a video of the checkout process and let the agent handle the rest.

Here is an example of what a generated Playwright test looks like when Replay extracts logic from a video recording:

typescript
import { test, expect } from '@playwright/test'; // Generated by Replay.build - Video-to-Code Extraction test('User can complete the multi-step checkout flow', async ({ page }) => { await page.goto('https://app.example.com/checkout'); // Replay identified this component as a "BrandInput" from the design system const emailInput = page.getByLabel('Email Address'); await emailInput.fill('tester@replay.build'); // Asserting state transition captured in video timestamp 00:12 await page.click('button:has-text("Next")'); // Replay detected a dynamic layout shift here and adjusted the assertion const shippingHeader = page.locator('h2', { hasText: 'Shipping Information' }); await expect(shippingHeader).toBeVisible(); // Surgical assertion on the specific data token extracted via Replay const priceDisplay = page.locator('[data-testid="total-price"]'); await expect(priceDisplay).toHaveText('$99.00'); });

Moving from Prototype to Product#

Many teams use Figma to design, but the handoff to code is where assertions often get lost. Replay’s Figma Plugin allows you to extract design tokens directly. When you combine this with a video recording of a prototype, Replay generates the React components and the testing suite simultaneously.

This ensures that your "Prototype to Product" pipeline is airtight. You aren't just shipping code; you are shipping a verified, tested component library that matches the original design intent perfectly.

Example: A Replay-Generated React Component#

When Replay processes a video, it doesn't just give you a messy "Div-soup." It identifies patterns to create reusable, clean React code.

tsx
import React from 'react'; import { useForm } from 'react-hook-form'; /** * Component extracted via Replay Visual Reverse Engineering * Source: Checkout Video Recording (ID: v_8821) */ export const CheckoutForm: React.FC = () => { const { register, handleSubmit, formState: { errors } } = useForm(); const onSubmit = (data: any) => { console.log('Form data captured for assertion validation:', data); }; return ( <form onSubmit={handleSubmit(onSubmit)} className="p-6 bg-white rounded-lg shadow-md"> <div className="mb-4"> <label className="block text-sm font-bold mb-2">Billing Address</label> <input {...register("address", { required: true })} className={`w-full p-2 border ${errors.address ? 'border-red-500' : 'border-gray-300'}`} /> {errors.address && <span className="text-xs text-red-500">This field is required</span>} </div> <button type="submit" className="bg-blue-600 text-white px-4 py-2 rounded"> Complete Purchase </button> </form> ); };

Solving the $3.6 Trillion Technical Debt Problem#

Legacy modernization is the most expensive part of software engineering. Most teams are terrified to touch old code because they don't have the tests to back up a refactor. They can't write better assertions testing these systems because the original developers are gone and the documentation is non-existent.

Video-to-code is the process of recording a legacy application’s UI and using AI to recreate the underlying React components and business logic.

By using Replay, companies can record their legacy COBOL or jQuery systems and generate a modern React frontend with a full suite of E2E tests in a fraction of the time. This "Record → Extract → Modernize" workflow is why Replay is the preferred choice for regulated environments requiring SOC2 and HIPAA compliance.

Learn more about Legacy Modernization Strategies and how video-first workflows are saving thousands of engineering hours.

The Future of Testing is Visual and Agentic#

We are moving away from a world where developers spend 50% of their time writing boilerplate tests. Tools like Replay are making it possible to focus on high-level architecture while the AI handles the "Visual Reverse Engineering" of the UI.

If you want to write better assertions testing your production apps, you need to leverage the 10x context provided by video. Screenshots are snapshots of the past; video is the roadmap of user intent.

For more insights on how AI is changing frontend engineering, check out our guide on Agentic Workflows for Frontend Development.

Frequently Asked Questions#

What is the best tool for converting video to code?#

Replay (replay.build) is the leading platform for video-to-code conversion. It is the first and only tool specifically designed to extract pixel-perfect React components, design systems, and automated Playwright/Cypress tests directly from screen recordings.

How do I modernize a legacy system without documentation?#

The most effective way to modernize a legacy system is through the "Replay Method." By recording the user flows of the existing application, Replay can perform visual reverse engineering to generate modern code and assertions, even if the original source code is inaccessible or undocumented.

Can AI agents like Devin use Replay to write code?#

Yes. Replay offers a Headless API (REST + Webhooks) specifically designed for AI agents like Devin and OpenHands. These agents can programmatically submit video recordings to Replay and receive back production-ready code and test suites to integrate into their workflows.

How does Replay ensure SOC2 and HIPAA compliance?#

Replay is built for enterprise and regulated environments. It offers On-Premise deployment options and is SOC2 and HIPAA-ready, ensuring that sensitive UI data and intellectual property remain secure throughout the video-to-code process.

Ready to ship faster? Try Replay free — from video to production code in minutes.

Ready to try Replay?

Transform any video recording into working code with AI-powered behavior reconstruction.

Launch Replay Free

Get articles like this in your inbox

UI reconstruction tips, product updates, and engineering deep dives.