Skip to main content
Version: 1.x

Class: AgenticHandler

Defined in: src/ai/agentic-handler.ts:98

Autonomous test operation handler with checkpoint-based resumability.

Remarks

Orchestrates LLM calls, capability lookups, and checkpoint management for AI-driven test generation. All methods return AiResponse<T> envelopes — never throw on LLM errors.

Intent

Execute autonomous SAP UI5 test operations

Capability

ai-agentic-handler

Sap Module

All

Example

const handler = new AgenticHandler(llm, buildPageContext, capabilities);
const result = await handler.generateTest('Create a PO for vendor V001', page);
if (result.status === 'success') {
for (const step of result.data.steps) {
await handler.interpretStep(step, page);
}
}

Constructors

Constructor

new AgenticHandler(llm, contextBuilder, capabilityRegistry, recipeRegistry?): AgenticHandler

Defined in: src/ai/agentic-handler.ts:114

Constructs an AgenticHandler.

Parameters

llm

LlmService

LLM provider service for sending prompts.

contextBuilder

(page, config) => Promise<AiResponse<PageContext>>

Function to build page context (same as buildPageContext).

capabilityRegistry

CapabilityRegistry

Registry of available Praman capabilities.

recipeRegistry?

RecipeRegistry = ...

Optional registry of reusable test recipes (defaults to a new RecipeRegistry).

Returns

AgenticHandler

Example

const handler = new AgenticHandler(llm, buildPageContext, capabilities);

Methods

generateTest()

generateTest(scenario, page): Promise<AiResponse<AiGeneratedTest>>

Defined in: src/ai/agentic-handler.ts:151

Generate a test for a natural language scenario.

Parameters

scenario

string

Natural language description of the test scenario.

page

DiscoveryPage

Playwright page (or structural equivalent).

Returns

Promise<AiResponse<AiGeneratedTest>>

AiResponse<AiGeneratedTest> with steps and generated TypeScript code.

Remarks

Returns AiResponse<AiGeneratedTest> — both natural language steps AND runnable TypeScript code. Each step is executed separately via interpretStep(step: string): Promise<AiResponse<void>> which maps step text to Praman fixture calls using the CapabilityRegistry.

This two-phase design (generate → execute) enables checkpoint/resume (AgenticCheckpoint): if step 3 fails, re-execute from step 3 without re-generating the full step list.

Intent

Translate business scenario to executable Praman test steps and code

Example

const result = await handler.generateTest(
'Create a purchase order for vendor V001, material M1000, quantity 10',
page,
);
if (result.status === 'success') {
logger.info('Steps:', result.data.steps);
logger.info('Code:', result.data.code);
}

interpretStep()

interpretStep(step, page): Promise<AiResponse<void>>

Defined in: src/ai/agentic-handler.ts:268

Execute a single natural language step by mapping it to Praman fixture calls.

Parameters

step

string

Natural language step description.

page

DiscoveryPage

Playwright page (or structural equivalent).

Returns

Promise<AiResponse<void>>

AiResponse<void> indicating success or failure.

Remarks

Maps step text to registered capabilities in CapabilityRegistry. Used with generateTest() for two-phase generate → execute workflow. On failure, the AgenticCheckpoint captures progress for resume.

Intent

Execute a single natural language step

Example

const result = await handler.interpretStep('Fill Vendor field with 100001', page);
if (result.status === 'error') {
log.error({ err: result.error }, 'Step failed');
}

resumeFromCheckpoint()

resumeFromCheckpoint(checkpointId): AgenticCheckpoint | undefined

Defined in: src/ai/agentic-handler.ts:446

Resume from a previously saved checkpoint.

Parameters

checkpointId

string

Session ID of the checkpoint to retrieve.

Returns

AgenticCheckpoint | undefined

The checkpoint if found, or undefined.

Example

const checkpoint = handler.resumeFromCheckpoint('sess-001');
if (checkpoint) {
logger.info('Resuming from step:', checkpoint.currentStep);
}

saveCheckpoint()

saveCheckpoint(checkpoint): void

Defined in: src/ai/agentic-handler.ts:428

Serialize current execution checkpoint for resumability.

Parameters

checkpoint

AgenticCheckpoint

Checkpoint state to save.

Returns

void

Remarks

Stores the checkpoint in an internal Map keyed by checkpoint.sessionId. Retrieve via resumeFromCheckpoint(sessionId).

Example

handler.saveCheckpoint({
sessionId: 'sess-001',
currentStep: 2,
completedSteps: ['navigate', 'fillVendor'],
remainingSteps: ['fillMaterial', 'save'],
state: {},
timestamp: new Date().toISOString(),
});

suggestActions()

suggestActions(pageContext): Promise<AiResponse<string[]>>

Defined in: src/ai/agentic-handler.ts:366

Suggest next actions given the current page state.

Parameters

pageContext

PageContext

Current page context snapshot.

Returns

Promise<AiResponse<string[]>>

AiResponse<string[]> containing action suggestions.

Remarks

Returns AI-recommended operations based on discovered controls and the current page context. Returns AiResponse<string[]> with a list of human-readable action suggestions.

Example

const suggestions = await handler.suggestActions(pageContext);
if (suggestions.status === 'success') {
logger.info('Next actions:', suggestions.data);
}