場合によっては、動的に値を定義し (datetime now、ランダムな文字列、ランダムな整数、ファイルの内容など)、値を明示的またはハードコーディングすることなく、さまざまなステップでそれらを使用する必要があります。
したがって、私の質問は、次のステップでこれらの変数を使用するために、ステップ内で変数を定義する方法 (正しい方法) です。
いくつかの例
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}}"
これは、ステップで変数を定義し、コンテキストに保存して次のステップで使用する理由を説明しようとする基本的な例です。
私の考えは、 before_step および after_step メソッドを変更することでした... コンテキストに変数を設定して、次のようなカスタム変数を保存します。
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):
# Here use a regex to check each cell and look for `"{{<identifier>}}"` and if match, replace the cell value by context.vars[identifier] so the step "the posts table shows these posts will never know what is `{{my_text}}` it will be abstract seeing the random string.
シナリオの概要、次のような変数を定義するものを使用して"<some_identifier>"
から、各例でステップの値を置き換えます。
基本的には動作を再現することですが、単純またはテーブルを使用するあらゆる種類のステップに対してです。
このようなことをするのは正しい方法ですか?