Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:DevExpress Testcafe CommandFormatter

From Leeroopedia
Revision as of 11:12, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/DevExpress_Testcafe_CommandFormatter.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Reporting, Test Execution
Last Updated 2026-02-12 12:00 GMT

Overview

CommandFormatter transforms internal test-run command objects into a structured, reporter-friendly format, handling selector resolution, role preparation, confidential data masking, and option diffing.

Description

src/reporter/command/command-formatter.ts exports the CommandFormatter class, which takes a CommandBase and an optional result value, and produces a FormattedCommand object suitable for reporter plugin consumption.

The formatting pipeline dispatches on command type:

  • ExecuteSelectorCommand -- Joins the apiFnChain array into a single expression string and optionally includes the resolved element and timeout in a SelectorInfo structure.
  • ExecuteClientFunctionCommand -- Extracts fnCode and the first args entry into a plain object.
  • UseRoleCommand -- Extracts loginUrl, opts, and phase from the role.
  • NavigateToCommand -- Extracts the navigation URL string.
  • SetNativeDialogHandlerCommand -- Delegates to client function preparation via the command's dialogHandler property.
  • RunCustomActionCommand -- Attaches the actionResult to the formatted output.
  • All other commands -- Iterates over getReportedProperties() and assigns each property, recursively formatting nested selectors and diffing option objects against defaults.

Key features:

  • Confidential data masking -- If the command options include confidential: true, the formatter replaces TypeTextCommand.text or PressKeyCommand.keys with '********'.
  • Option diffing -- _getModifiedOptions creates a new default instance of the option class and uses diff() to include only changed properties, keeping reporter output minimal.
  • Lazy element decoding -- _ensureSelectorElements decodes the result using createReplicator with SelectorNodeTransform only when element data is actually needed.

Usage

The CommandFormatter is instantiated by the reporter infrastructure each time a test-run action completes. The reporter calls format() to obtain the FormattedCommand and passes it to reporter plugins via the action event interface.

Code Reference

Source Location

src/reporter/command/command-formatter.ts (169 lines)

Signature

export class CommandFormatter {
    private _elements: HTMLElement[];
    private readonly _command: CommandBase;
    private readonly _result: unknown;

    public constructor (command: CommandBase, result: unknown);

    public format (): FormattedCommand;

    private _maskConfidentialInfo (command: FormattedCommand): void;
    private _getElementByPropertyName (propertyName: string): HTMLElement;
    private _prepareSelector (command: ExecuteSelectorCommand, propertyName: string): SelectorInfo;
    private _prepareClientFunction (command: ExecuteClientFunctionCommand): object;
    private _prepareDialogHandler (command: SetNativeDialogHandlerCommand): object;
    private _prepareRole (command: UseRoleCommand): object;
    private _prepareUrl (command: NavigateToCommand): string;
    private _assignProperties (command: CommandBase, formattedCommand: FormattedCommand): void;
    private _ensureSelectorElements (): void;

    private static _getModifiedOptions (commandOptions: object): Dictionary<object>;
}

Supporting interfaces (from src/reporter/command/interfaces.ts):

export interface FormattedCommand {
    [key: string]: unknown;
    type: string;
}

export interface SelectorInfo {
    expression: string;
    timeout?: number;
    element?: HTMLElement;
}

Import

import { CommandFormatter } from '../../reporter/command/command-formatter';

I/O Contract

Inputs

Parameter Type Description
command CommandBase The test-run command object to be formatted. Must have at least a type and actionId property.
result unknown The optional execution result of the command, used to resolve selector elements. Can be null or undefined.

Outputs

Method Return Type Description
format() FormattedCommand A plain object with type, actionId, and command-specific properties. Selectors are represented as SelectorInfo objects. Options include only modified (non-default) values. Confidential text is masked.

The FormattedCommand object varies by command type:

  • Selector commands: { type, actionId, selector: { expression, element?, timeout? } }
  • Client function commands: { type, actionId, clientFn: { code, args } }
  • Role commands: { type, actionId, role: { loginUrl, options, phase } }
  • Navigate commands: { type, actionId, url: string }
  • Dialog handler commands: { type, actionId, dialogHandler: { code, args } }
  • Custom action commands: { type, actionId, ..., actionResult }
  • General commands: { type, actionId, [reportedProperty]: value, ... }

Usage Examples

Formatting a selector command:

import { CommandFormatter } from '../../reporter/command/command-formatter';

const formatter = new CommandFormatter(executeSelectorCommand, selectorResult);
const formatted = formatter.format();
// {
//   type: 'execute-selector',
//   actionId: 'abc123',
//   selector: { expression: "Selector('#submit-btn')", element: <HTMLElement> }
// }

Formatting a type-text command with confidential masking:

const typeCommand = new TypeTextCommand({ text: 'mySecret', options: { confidential: true } });
const formatter   = new CommandFormatter(typeCommand, null);
const formatted   = formatter.format();
// formatted.text === '********'

Formatting a command with modified options:

// Only non-default option values are included
const formatter = new CommandFormatter(clickCommand, elementResult);
const formatted = formatter.format();
// formatted.options might be { offsetX: 10 } if only offsetX differs from defaults

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment