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

[Gherkin language feature support] Gherkin can support StepMacros syntax? #2154

Closed
shihai1991 opened this issue Aug 30, 2023 · 5 comments
Closed

Comments

@shihai1991
Copy link

shihai1991 commented Aug 30, 2023

🤔 What's the problem you're trying to solve?

I have many colleagues to develop step functions. After some times, we have many similar steps or groups of step.
IMH, Using MacroSteps can help us manage the common steps.

✨ What's your proposed solution?

Some BDD framework support StepMacros.

In Chorus BDD, the example looks like:

#file: login.stepmacro
Step-Macro: I log in as user <user> with password <password>
    Given I click the login button
    And the login dialog is shown
    When I type <user> into the field username
    And I type <password> into the field password
    And I click the OK button
     
#file: login.feature
Feature: Log In 

    Scenario: I can log in using the login form
        Given I log in as user Nick with password myPassword
        Then I am logged in as the user Nick
    
#file: accountSummary.feature
Feature: Account Summary
 
    Scenario: Account summary link is shown when logged in
        Given I log in as user Nick with password myPassword
        Then the account summary link is visible on homepage

In Behave, it looks like:

@when(u'I do the same thing as before with the {color:w} button')
def step_impl(context, color):
    context.execute_steps(u'''
        When I press the big {color} button
         And I duck
    '''.format(color=color))

The issue discuss in pytest-bdd.

⛏ Have you considered any alternatives or workarounds?

📚 Any additional context?


This text was originally generated from a template, then edited by hand. You can modify the template here.

@luke-hill
Copy link
Contributor

This looks similar to steps in steps in ruby, which is something we're advising heavily against.

Ideally if you have lots of common steps, you should use that languages abstraction techniques. So in ruby this would be a module or a class, and similar in Java.

Then you would call the methods in the steps. so something like.

Given('I log in as user {word} with password {word}') do |user, password|
  # method here to login, using a class or module
end

@ehuelsmann
Copy link
Contributor

This Stack Overflow thread: https://stackoverflow.com/a/23092261

Refers to this discussion: https://groups.google.com/g/cukes/c/DzE_kGZx94I/m/5rf__N31qvAJ

which can be summarized as "Gherkin is a collaboration tool, not a programming language". What makes your request different?

@shihai1991
Copy link
Author

Ideally if you have lots of common steps, you should use that languages abstraction techniques. So in ruby this would be a module or a class, and similar in Java.

Thanks for your suggestion. You are right. Using some computer languages' techniques can resolve this problem too. But I would prefer to use StepMacros to combine those steps. Some of my reasons:

  1. We have kinds of teams. Some developers use Java, others use Golang or C/C++. In order to make sure all of our teammates to understand the test scenario efficiently, we must discuss the scenario details in Gherkin language level. Involving kinds of computer languages' techniques will destroy the effectiveness;
  2. Our test scenario is Cloud Computing. There are many Resource concepts. We will get a very long feature file If we describe all details in one feature. For example:
# create VPC1
# Of Course, we can combine the multi step description in one step
# something like: When create a VPC with the the Availability region with the Availiability zone with ipv4...
# But the test scenario should be flexible and combinable. But the combined step lost the flexibility.
When build a VPC_Request_Body
And choose the Availability region in VPC_Request_Body
And choose the Availiability zone in VPC_Request_Body
And set the ipv4 in VPC_Request_Body
And set the subnet in VPC_Request_Body
And create an VPC with VPC_Request_Body
Then VPC created successful
# create VPC2
# the creation operation will be repeated in here, but the property ov VPC2 will be different
# create ECS1 in VPC1
# create ECS2 in VPC2
# test the connectivity between ECS1 and ECS2

@shihai1991
Copy link
Author

shihai1991 commented Sep 1, 2023

Refers to this discussion: https://groups.google.com/g/cukes/c/DzE_kGZx94I/m/5rf__N31qvAJ
which can be summarized as "Gherkin is a collaboration tool, not a programming language". What makes your request different?

Oh, thanks for your information. Looks like my request is not different with the discussion.

Some points from cucumber-waves-goodbye-to-givenscenario

Difficult to understand isolated scenarios

I think we can't consider this problem If the IDE support to find and link the related scenario.
The IDE is much better now than 10 years ago.

Creating setups which pretend to be scenarios

If the user need use this feature. IMHO, the key word GivenScenario could be updated to CombinedGivenCombinedWhen and so on.

Noise in the output

We don't focus on the output until we meet the failed testcase.

@luke-hill
Copy link
Contributor

I'm going to close this. We've briefly spoken about it in the committers meeting and async, and given this is something we are strongly advising against - all languages have their own paradigms. We advise using those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants