Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable usage of variables in feature steps #1132

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gyoganathan
Copy link

We have a use case, where we would like to enable passing variables in the step name which will get replaced to the actual values from the variable's map we have in the before_step implementation.

Eg:

When I send an email to "foo@bar.com" with subject "Hello" and body "Try out this website at http://google.com"
        And I click the link in the email I received at "foo@bar.com"

We want to have the ability to generate this email address dynamically for every run and use that email throughout the other steps. So we would like to do something like:

# The below step will create a random email address and store it in a context.random map as context.random["foo"] = generate_new_random_email()
Given a random email address named "foo" 
When I send an email to "{foo}" with subject "Hello" and body "Try out this website at http://google.com"
        And I click the link in the email I received at "{foo}"
def before_step(context, step):
    if 'random' in context:
        new_name = step.name.format(**context.random)
        step.name = new_name

This doesn't execute the step after replacement, because the match object is being built before the before_step hook is called. Moving that code before we create the match object makes it work perfectly.

@jenisys
Copy link
Member

jenisys commented Sep 1, 2023

  • Placeholder translation can be easily done by using type-converters in your steps (and you can do that yourself and not need an before_step() preparation because your step implementation should do the work

OTHERWISE:

  • we do not two things at the same time: Changing Gherkin translation and adding something new
  • Gherkin keyword translations are provided in the cucumber repo. behave only pulls the latest changes and generates the source code here.

SEE ALSO:

@jenisys jenisys force-pushed the main branch 2 times, most recently from 0a4d73b to 2c11d2e Compare May 14, 2024 22:39
@jenisys jenisys force-pushed the main branch 2 times, most recently from 3e51dda to c6ab01c Compare May 26, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants