Custom Step and Stepdef Parser Built-ins¶
When writing custom Stepdefs with Step Details, the parseStepParameters()
Built-ins are used to retrieve and evaluate the values of these parameters.
Syntax
1 2 | parseSteps(<step String>) parseStepParameters(<step String>, <stepdef String>) |
Parameters
-
step - The step to be parsed
-
stepdef - The stepdef to be parsed
Note:
parseStepParameters
returns null
if the stepdef
does not match the step.
Example
1 2 | parseSteps(menuOptions) parseStepParameters(mySteps, "with menu item {} at index {}") |
If a custom Stepdef contains Custom Steps such as the following:
1 2 3 | stepdef "create sub menu:" / menuOptions / ... end |
Example 1 The step can be called in a Feature File such as the one below:
1 2 3 4 | And create sub menu: * with menu item "File" at index 1 * with menu item "Edit" at index 2 * with menu color "Green" |
In this case, the parameter menuOptions
will contain the following string as value:
1 | " * with menu item "File" at index 1\n * with menu item "Edit" at index 2" |
This Built-in function can then be used to parse the Custom Steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | stepdef "create sub menu:" / menuOptions / mySteps := parseSteps(menuOptions) for step in mySteps stepParameters := parseStepParameters(step, "with menu item {} at index {}") if stepParameters != null then println("Menu Name: " + stepParameters[0]) println("Menu Index: " + stepParameters[1]) end stepParameters := parseStepParameters(mySteps, "with menu color {}") if stepParameters != null then println("Menu Color: " + stepParameters[0]) end end end |
Example 2
1 2 3 | And prepare an Xccp search operation as Search * where CIN is SearchCin * where CSN is 1 |
In the example above, SearchCin
is a Context Object that evaluates to "123456789"
. The parseStepParameters
Built-in is then used to parse the Custom Steps:
1 | p := parseStepParameters(detail, "where {ident} is {}") |
This returns the following results:
1 2 | p[0] = "CIN" p[1] = "123456789" |