question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecate `And` and `But` functions for step definitions

See original GitHub issue

Current behavior

Step definitions can be defined with Given, When, Then, And and But - see https://github.com/badeball/cypress-cucumber-preprocessor/blob/b6295672f0433f454b14c2ea3f7f859a97f0ac44/lib/index.ts#L65-L71

Desired behavior

Step definitions can be defined with Given, When and Then. This is what Cucumber.js does: https://github.com/cucumber/cucumber-js/blob/01368ca6e3c9b097a7a88bb72de5beeddb4a0326/src/index.ts#L45-L51

Here is an example illustrating why:

Feature: banking
  Scenario: Overdraft
    Given I have an overdraft limit of 50
    And I have a balance of 300
    When I withdraw 330
    Then my balance should be -30

With the currentl API, people might implement step definitions this way:

Given('I have an overdraft limit of {int}')
And('I have a balance of {int}')

But what if I add a new scenario:

  Scenario: No overdraft
    Given I have a balance of 300
    When I withdraw 330
    Then my balance should be 300
    And I should be told my overdraft limit is 0

It no longer makes sense that the step defnition is defined with And.

The And and But keywords only belong in Gherkin. Step definitions are reusable in any order, and should therefore not use And and But.

Checklist

  • I’ve read the FAQ.
  • I’ve read Instructions for logging issues.
  • I’m not using cypress-cucumber-preprocessor@4.3.1 (package name has changed and it is no longer the most recent version, see #689).

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
aslakhellesoycommented, Oct 4, 2022

Ah, now I understand. But in German this does not work. The sentence structure after Dann (German for Then) is different than after Und (German for And).

@iomedico-beyer can you give me a concrete example of a sentence/step that would be different with Dann and Und? I’m one of the maintainers of Cucumber and understanding this would be helpful.

0reactions
badeballcommented, Nov 4, 2022

I want to highlight the following comment from Mar 16, 2021: https://github.com/cucumber/cucumber-js/issues/1615#issuecomment-800401681

We’re never going to add And and But as step definition methods.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to document cucumber js step definitions with JsDoc
Deprecating step definitions ​​ This approach allows you to have a step definition that is being used by a scenario feature, but you...
Read more >
Calling Steps from Step Definitions - SpecFlow's documentation
It is possible to call steps from within Step Definitions: [Binding] public class CallingStepsFromStepDefinitionSteps : Steps { [Given(@"the user (.
Read more >
Reuse Cucumber steps - Stack Overflow
UPDATE: The method described below has been deprecated. ... Calling steps from step definitions is a bad practice and has some disadvantages ...
Read more >
State - Cucumber Documentation
Within your scenarios, you might want to share state between steps. It's possible to store object state in variables inside your step definitions....
Read more >
Step Definition - Cucumber - Tools QA
What is Step Definition in Cucumber, How to create Step Definition file in ... it executes the piece of code written inside the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found