Skip to content

[Enhancement] Strongly-Typed Step Outcomes and Locators #49

Description

@rickcedwhat-ai

Problem Description

Currently, when sharing selectors/locators between adjacent steps (e.g. from .detect() to .prep()), the downstream step receives a loosely-typed lastOutcome object. Developers must manually cast the locator (e.g., lastOutcome.locator as Locator) and do not get autocomplete or type-safety on the outcome names:

.detect((page) => [
  { name: 'found', isSuccess: true, locator: page.getByRole('textbox', { name: 'Name' }) }
])
.prep('fill details', async (page, ctx, lastOutcome) => {
  if (lastOutcome?.name === 'found') { // No autocomplete or type safety
    const input = lastOutcome.locator as Locator; // Manual typecast required
    await input.fill('value');
  }
})

Proposed Solution

Refactor the generic types of the Play builder class so that the list of outcomes defined in .detect() or .attempt() maps to a strongly-typed union. Downstream steps should automatically infer:

  1. lastOutcome.name (restricted to the literal string names defined in the prior step).
  2. lastOutcome.locator (typed properly as Locator instead of any or unknown).

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedBlocked by another issueplaybook-frameworkBelongs to the future RBAC/playbook library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions