Agent-Based Mobile UI Recreation and Acceptance Testing

    A practical workflow for recreating mobile interfaces and verifying their visual and behavioral fidelity. This article defines six fidelity levels, explains device-based capture and structured comparison, and outlines same-device acceptance testing, common pitfalls, and compliance requirements.

    1. Why UI Recreation Is Difficult

    UI recreation means reproducing a page’s appearance, layout, and interactions in another implementation using an established reference. Common scenarios include turning designs into working screens, migrating an existing interface to a new technology stack, and maintaining a consistent experience across platforms.

    The main challenge is usually not drawing the interface but aligning it with the reference. A design mockup is static, while a running interface has state, asynchronous loading, and variations in font rendering. Several kinds of discrepancies are easy to introduce:

    • Element positions and spacing may drift by a few pixels. Individual differences can be hard to notice, but their cumulative effect changes the overall appearance.
    • Colors, corner radii, and font sizes may be estimated visually rather than based on measured values.
    • Navigation, dialogs, loading states, empty states, and other interaction details are often overlooked.
    • Relationships between text and application states may go undocumented, making it difficult to determine the correct behavior during regression testing.

    The key is to turn “Does it look right?” into data that can be checked item by item. The following workflow is built around that principle.

    2. Define the Target Fidelity Level

    Before collecting data, the team needs to decide how closely the implementation must match its reference. Without a defined target, acceptance testing can become a subjective debate.

    The following six-level model progresses from L0 to L5:

    Level Name Acceptance criteria
    L0 Static screenshot comparison Compare only the overall visual impression of a single screenshot.
    L1 Layout consistency Element positions, dimensions, and hierarchy match the reference.
    L2 Visual style consistency Colors, corner radii, font sizes, spacing, and other style properties match within defined tolerances.
    L3 Interaction and state consistency Navigation paths, dialogs, loading states, empty states, and form validation behave consistently.
    L4 Approximate data logic parity Given the same inputs, business data structures and calculation results are approximately equivalent.
    L5 Full functional parity All functionality and edge-case behavior match, including performance metrics.

    For most business applications, L3 is a reasonable default. It ensures that screens look and behave consistently while keeping the workload manageable. Raise the target to L4 or L5 only when data and business-logic alignment are explicit requirements.

    Once selected, the fidelity level should guide every subsequent stage.

    3. A Five-Step Workflow

    The process consists of five steps: define the fidelity level, connect to the device, capture structure and visuals, create structured comparison records, and rebuild and validate on the same device. Each step produces artifacts that can be retained and reviewed.

    Step 1: Define Fidelity and Scope

    Select the target level using the model above, then list the screens included in the project. Record each screen’s entry path so that deeply nested screens are not missed.

    Step 2: Establish a Direct Device Connection

    Enable a debugging connection on a physical device or emulator so that a computer-side program can read the interface and send input.

    This captures data from the actual runtime environment, with the fonts, resolution, and system theme used in that environment. Wrap device access in a common interface so that application code depends on the abstraction rather than a specific tool.

    1. class DeviceSession:
    2. def capture_tree(self) -> list:
    3. """Read the current screen's UI tree and return its elements."""
    4. ...
    5. def capture_screenshot(self) -> bytes:
    6. """Capture the current screen and return image bytes."""
    7. ...
    8. def tap(self, x: int, y: int) -> None:
    9. """Tap at the specified coordinates."""
    10. ...

    This abstraction makes it easier to replace the underlying implementation or substitute a mock object during testing.

    Step 3: Capture Structure and Visual Properties

    Capture proceeds along two tracks.

    Structural capture reads the UI tree and records each element’s stable identifier, type, bounds, and text. Prefer resource names assigned during development as stable identifiers. If those are unavailable, use the element’s path in the tree, keeping in mind that the path can change when the screen structure changes.

    Visual capture extracts style properties from screenshots. An element’s dominant color can be sampled from its region, corner radius can be estimated through edge detection, and font size can be inferred from element height and the number of text lines. These estimates are imperfect, so later comparisons should use tolerances rather than require exact equality.

    Capture timing also matters. Screenshots taken before an animation finishes may show shifted coordinates, while screenshots taken during loading may contain placeholders. Capture only after the interface has stabilized, and document the stability condition—for example, a pixel difference below a specified threshold between two consecutive screenshots.

    Step 4: Create Structured Comparison Records

    Organize the captured results into two tables.

    A per-screen UI difference table compares properties for each element on each screen. Its fields should include the screen name, element identifier, property name, reference value, actual value, and a description of the difference.

    A behavior audit table records actions and state transitions. Its fields should include the step number, triggering action, precondition state, resulting state, navigation destination, and any exception notes. This table supports replay: anyone following its steps should obtain the same results.

    The following illustrative code compares reference and implemented screens and returns difference rows:

    1. from dataclasses import dataclass, field
    2. @dataclass
    3. class Element:
    4. key: str # Stable element identifier
    5. role: str # Element type, such as button, text, or input
    6. box: tuple # Top-left and bottom-right coordinates (x1, y1, x2, y2)
    7. text: str = ""
    8. style: dict = field(default_factory=dict) # Color, corner radius, font size, etc.
    9. def diff_screens(spec: list, actual: list, tol: int = 4) -> list:
    10. spec_map = {e.key: e for e in spec}
    11. actual_map = {e.key: e for e in actual}
    12. rows = []
    13. for key in spec_map.keys() | actual_map.keys():
    14. s = spec_map.get(key)
    15. a = actual_map.get(key)
    16. if s is None:
    17. rows.append((key, "Extra element", "-", "Present"))
    18. elif a is None:
    19. rows.append((key, "Missing element", "Present", "-"))
    20. else:
    21. if any(abs(p - q) > tol for p, q in zip(s.box, a.box)):
    22. rows.append((key, "Bounds mismatch", s.box, a.box))
    23. if s.text != a.text:
    24. rows.append((key, "Text mismatch", s.text, a.text))
    25. if s.style != a.style:
    26. rows.append((key, "Style mismatch", s.style, a.style))
    27. return sorted(rows, key=lambda r: r[0])

    Set tol according to the device’s pixel density. On a high-density screen, a difference of several physical pixels may amount to only half a logical pixel. An overly strict tolerance can generate many insignificant differences.

    Step 5: Rebuild and Validate on the Same Device

    During implementation, resolve the differences one by one. Address structure first, styling second, and interactions last, because structural issues can affect both styling and behavior.

    Acceptance testing must use the same device. Compare the reference and recreated interfaces at the same resolution, with the same font settings and system theme, to eliminate environmental variables.

    Acceptance requires both of the following:

    • The difference table contains no unresolved items that exceed the defined tolerances.
    • Every step in the behavior audit table can be reproduced.

    4. Common Problems and How to Handle Them

    Dynamic content breaks comparisons. List data, timestamps, and advertising placements may change between captures. Mask these regions before comparison, or compare their structure without comparing their content.

    Font rendering differs. The same nominal font size can produce different rendered heights on different devices. Record the font name and size in the reference, and use the same font file during acceptance testing.

    Asynchronous loading produces intermediate states. A screen may display a skeleton while network requests are pending. Capture scripts should wait for loading to complete, while also recording the skeleton as a separate state that must be recreated.

    Permission dialogs interrupt the workflow. System dialogs are not part of the application interface, but they can obscure it. Pre-grant permissions in the test environment or include dialog handling as a fixed step in the behavior audit table.

    Inferred style properties are inaccurate. Corner radii and font sizes estimated from screenshots can have substantial errors. Use values from the design files as the authoritative reference. Screenshot-based estimates should help identify anomalies, not establish final specifications.

    5. Compliance Boundaries

    This workflow is intended for design implementation, migration, and regression acceptance testing of products you own. Its use should respect several boundaries.

    First, reference materials should come from your own design files, public design guidelines, or materials you are authorized to use. Do not directly copy another product’s interface assets, brand identifiers, proprietary text, or functional implementation.

    Second, obtain explicit authorization before capturing or reverse-engineering another party’s software interface. Without authorization, limit references to public interaction guidelines and design your own implementation.

    Third, document the source of every reference screen. If a dispute arises, these records provide important evidence of the team’s compliance.

    Fourth, the resulting product should have its own visual language and brand identity. Similar interface structures are common design conventions, but directly copying visual elements can create intellectual property risks.

    6. Implementation Checklist

    • Define the target fidelity level and list all screens and entry paths.
    • Wrap device access in a common interface that can be replaced with mocks in tests.
    • Define the interface stability condition before capture.
    • Generate and retain both the per-screen UI difference table and the behavior audit table.
    • Set comparison tolerances according to device pixel density.
    • Apply masks or exclusion rules to dynamic regions.
    • Complete acceptance testing on the same device, with no unresolved differences exceeding tolerance.
    • Record the design source for every reference screen.