Sometimes you need to dynamically determine values ββ(for example, date-time, random strings, random integers, file contents, etc.) and use them at different stages without explicit or hard coding of the value.
So my question is how can I define the variables inside the steps (the right way to do this) in order to use these variables in the next steps.
Example
Given A random string of length "100" as "my_text" And I log in to my platform And I ask to add the following post: | title | description | | Some example of title | {{my_text}} | When I submit the post form Then The posts table shows these posts: | title | description | | Some example of title | {{my_text}} | And I delete any post containing in the description "{{my_text}}"
This is a basic example that tries to explain why I would like to define variables in steps and store them in context, so I can use it in the next steps.
My idea was to modify the before_step and after_step ... methods to set the variable in context to store my custom variables as follows:
def before_step(context): if not hasattr(context, 'vars'): context.vars = {} if hasattr(context, table) and context.table: parse_table(context) def parse_table(context):
Outline scripts, use something like these defining variables, such as "<some_identifier>" , and then for each example, replace the value in step.
This is mainly for reproducing behavior, but for any step, simple or using tables.
Is this right to do?
source share