Skip to main content
Version: 1.x

Class: AgenticHandler

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

pramanAI.agentic

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

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>>

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>>

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

Beta

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.

Remarks

Beta — checkpoint serialization format may change in minor releases.

Returns the in-memory checkpoint. For cross-process resume, first load from disk and call saveCheckpoint before calling this method.

Example

const checkpoint = handler.resumeFromCheckpoint('sess-001');
if (checkpoint) {
// Resume execution from where it left off
const remaining = checkpoint.remainingSteps;
for (const step of remaining) {
await handler.interpretStep(step, page);
}
}

saveCheckpoint()

saveCheckpoint(checkpoint): void

Beta

Save an execution checkpoint for later resumability.

Parameters

checkpoint

AgenticCheckpoint

Checkpoint state to save (see AgenticCheckpoint for JSON schema).

Returns

void

Remarks

Beta — checkpoint serialization format may change in minor releases.

Stores the checkpoint in an in-memory Map keyed by checkpoint.sessionId. Retrieve via resumeFromCheckpoint.

For cross-process persistence, serialize with JSON.stringify(checkpoint) before saving to disk, then restore with handler.saveCheckpoint(JSON.parse(stored) as AgenticCheckpoint).

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[]>>

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);
}