ASTA Docs
User Docs
Advanced Topics
Language Reference

ASTA Programming Languages Documentation

Rules Language

The Rules language is designed for defining rules that consist of multiple scenarios, each with a single Gherkin rule expression. Rules follow a structure with given contexts, actions, assertions, and optional final assignments.

Rule Structure

Rules consist of a rule identifier and a title, followed by one or more scenarios.

Production RuleDescriptionSource
RuleDefines a rule with scenariosRule = "Rule" ruleId? ":" title Scenario+
ruleIdAn optional rule identifierruleId = name | numericLiteral
nameAn identifier name for the rulename = identifierName
titleA title for the ruletitle = letter ~"\n" (alnum | "_" | "-" | " " | "\t")*

Scenarios

Scenarios describe the conditions, actions, and assertions for a rule.

Production RuleDescriptionSource
ScenarioDefines a scenario with a rule expressionScenario = "Scenario" ruleId? ":" title RuleExp
RuleExpThe main expression for a scenarioRuleExp = "Given" Context "When" Actions "Then" Assertions ("Finally" Assignments)?

Context, Actions, Assertions, Assignments Clauses

These sections define the components of a scenario, detailing the initial context, actions performed, expected outcomes, and final assignments.

Production RuleDescriptionSource
ContextInitial conditions or setup for the scenario. Used to check application and page state.Context = BooleanList | wildcard
ActionsChecks what kind action that just occurred, and what it was performed on.Actions = NonemptyConjunctionList<ActionContext> | wildcard
ActionContextDefines an action contextActionContext = "action" "is" Action
AssertionsExpected outcomes of the actions. Scenarios will pass or fail if this passes or fails.Assertions = BooleanList
AssignmentsOptional. Updates run and application state. Only runs if assertions pass.Assignments = NonemptyListOf<Assignment, "And">
AssignmentSets a state variable to a valueAssignment = "set" memberExp "to" (class | ValueExp)

Actions

Defines specific user actions such as input, mouse actions, visits, and browser actions.

Production RuleDescriptionSource
ActionDefines an actionAction = InputAction | MouseAction | VisitAction | BrowserAction
InputActionDefines an input actionInputAction = ("set" | "drag" | "fill") Component ("to" | "with") ValueExp
MouseActionDefines a mouse actionMouseAction = ("click" | "dblclick" | "hover" | "rightclick") Component
VisitActionDefines a visit actionVisitAction = "visit" ("page" | stringLiteral)
BrowserActionDefines a browser actionBrowserAction = "browser" ("back" | "forward" | "refresh")

Flows Language

The Flows language is designed for defining flows consisting of a series of steps in a breadcrumb notation. Flows include steps like actions, flow calls, command calls, assignments, assertions, and control statements like while and if.

Flow Structure

A flow is defined with a title, optional parameters, and a series of steps.

Production RuleDescriptionSource
FlowDefines a flow with parameters and stepsFlow = title #"(" Params ")" ":" Steps
ParamsA comma-separated list of parametersParams = ListOf<FormalParameter, ",">
FormalParameterA parameter in the flowFormalParameter = identifier

Steps

Steps describe the sequence of actions and other statements in a flow.

Production RuleDescriptionSource
StepsA list of steps separated by >, comments, or whitespaceSteps = nonemptyListOf<Step, stepDelimiter>
StepA single step in a FlowStep = Action | flowCall | commandCall | AssignmentStatement | AssertionStatement | WhileStatement | IfStatement

Actions

Defines specific user actions within a flow.

| Production Rule | Description | Source | | ------------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------- | ------------ | | Action | Defines an action | Action = InputAction \| MouseAction \| VisitAction \| BrowserAction | SmartAction | | InputAction | Fills an <input>, <form>, <select> or any other element that can hold a value. | InputAction = ("set" \| "drag" \| "fill") Component ("to" \| "with") ValueExp | | MouseAction | Perform an action with the mouse (e.g. click, hover) | MouseAction = ("click" \| "dblclick" \| "hover" \| "rightclick") Component | | VisitAction | Defines a visit action | VisitAction = "visit" ("page" \| stringLiteral) | | BrowserAction | Defines a browser action | BrowserAction = "browser" ("back" \| "forward" \| "refresh") | | SmartAction | Defines a smart action using selectors | SmartAction = Selector |

Flow and Command Calls

Flow calls and command calls within a flow.

Production RuleDescriptionSource
flowCallA call to another flowflowCall = "$flow" "." flowIdentifier "(" applySyntactic<Args> ")"
commandCallA call to a built-in commandcommandCall = "$cmd" "." qualifiedIdentifier "(" applySyntactic<Args> ")"

Built-in Commands

The following built-in commands are available for use in flows:

CommandDescriptionParametersReturnsExample
gen_auth_codeGenerate a Two-Factor authenticator code from an authenticator keyauthKey: string - The auth key to generate an auth code fromstring - The generated auth code$cmd.gen_auth_code("JBSWY3DPEHPK3PXP")
get_auth_keyGet a Two-Factor Authentication key from the pageNonestring - The extracted 2FA key$cmd.get_auth_key()
get_temp_codeGet a temporary authenticator code from the pageNonestring - The extracted temporary code$cmd.get_temp_code()
waitPause the action for a desired amount of timems: number - Duration to wait in millisecondsNone$cmd.wait(1000)
extract_textExtract text from a page elementselector: string - The selector to extract text from
regex: string - The regex to use to extract text
string - The extracted text$cmd.extract_text("input[name='email']", "(.+@.+)")
generate_dataUse AI to generate data for form elements on the current pageuseInvalidData?: boolean - Whether to generate invalid data (optional)object - The generated data as key-value pairs$cmd.generate_data() or $cmd.generate_data(true)

Assignments

Declare or re-assign variables.

Production RuleDescriptionSource
AssignmentStatementAssigns a value to a variable. This both reassigns existing variables and declares new ones.AssignmentStatement = memberExp "=" (ValueExp | Component)

Assertions

Assert that some condition is true, terminating the flow with a failure if it is not.

Production RuleDescriptionSource
AssertionStatementAsserts a conditionAssertionStatement = "assert" BooleanList

Control Flow

Control the flow of execution with while and if statements.

Production RuleDescriptionSource
WhileStatementExecutes steps while a condition is trueWhileStatement = "while" BooleanList "do" Steps "end"
IfStatementExecutes steps based on a conditionIfStatement = "if" BooleanList "then" Steps ("else" Steps)? "end"

Selectors

Selectors are used to identify and locate UI components within a page. They can be hierarchical or primary, using various forms such as classes, model items, locators, semantic selectors, and substring selectors.

Production RuleDescriptionSource
SelectorA UI component selectorSelector = HierarchicalSelector | PrimarySelector
HierarchicalSelectorSelector composed of a primary selector and a sub-selectorHierarchicalSelector = PrimarySelector "/" Selector
PrimarySelectorBasic selector including class, model item, locator, semantic, substring, or parenthesis selectorPrimarySelector = class | modelItem | Locator | semSel | SubstringSelector | ParenSelector
classSelector for a component classclass = "~" qualifiedIdentifier
modelItemSelector for a model itemmodelItem = "@" qualifiedIdentifier
LocatorSelector for an element using Playwright syntaxLocator = "(" Attributes ")"
semSelSemantic selector using a tilde and string literalsemSel = "~" stringLiteral
SubstringSelectorSubstring selector using a string literal without tildeSubstringSelector = stringLiteral ~(space* "+")
ParenSelectorSelector wrapped in parenthesesParenSelector = "~"? "(" (Selector | StringExp) ")"
AttributesList of attribute-value pairs for locatorsAttributes = NonemptyListOf<AttrValue, ",">
AttrValueAn attribute-value pair in a locatorAttrValue = (attr | stringLiteral) "=" ValueExp
attrAn attribute name in a locatorattr = qualifiedIdentifier
ComponentUI components identified by a selector or special nameComponent = ComponentInner
ComponentPropComponent property identified by a property nameComponentProp = property
propertyA property name for a componentproperty = identifier
PageSpecial page identifiers, "current" or "prior"Page = ("current" | "prior")? "page"