skip to content

In Cucumber, what does a conjunction step like "Given I sign in and open the catalogue" cost you?

level: juniorimportance: should knowfreq 63%

answer

  1. The keyword is stripped before matching
  2. One line, one definition, one result
  3. The half you wanted elsewhere is trapped
  4. Which half failed? The report cannot say
  5. Given states a fact, not a procedure

basics

~20 s

Cucumber strips the keyword and matches the whole remaining sentence, so a conjunction step becomes one definition nothing else can reuse, and a failure cannot say which half broke. Split it into two steps with two definitions.

solid answer

~50 s

Nothing in Cucumber objects to the word *and* inside a step: the keyword is removed before matching and the rest of the line is matched as one expression, so `Given I sign in and open the catalogue` binds to a single definition. Cucumber will even generate the stub for it, which makes the compound step the path of least resistance. The cost is threefold. **Reuse**: no other scenario wants exactly that pair, so the definition is written once and used once. **Diagnosis**: the run reports one result for two actions, so a failure in the second half is attributed to a step whose text also claims the first. **Drift**: each new pairing adds another sentence-long definition. The fix is to split the line into two steps - usually a `Given` that states a state and a second step for the real action.

code

gherkin · 6 lines
gherkin
# conjunction step: one definition, used once, one red result for two actions
Given I sign in as "rosa" and open the seed catalogue

# split: two definitions, both reusable, failures land on the right line
Given "rosa" is signed in
And the seed catalogue is open

go deeper

for a junior

Recognise a step that does two things and be able to rewrite it as two lines. Know that the And keyword starting a line is good style, while and buried inside the step text is the smell.

for a middle

Explain why the tool never complains: the keyword is stripped and the whole sentence is matched as one expression, so a compound simply becomes one narrow definition. Then name the reuse and diagnosis costs concretely.

for a senior

Show what compounds cost in triage on a real suite - a failure attributed to the wrong half, or a definition count growing one per sentence - and describe how you get a team to split by intent rather than into interface steps.

for a principal

Frame it as a standard worth setting: what the house rule is for step granularity, how it is reviewed, and when you accept a compound because splitting it would expose machinery the specification should not mention.

A **conjunction step** is a single Gherkin line that performs two things joined by *and*, *then*, *with* or a comma - `Given I sign in and open the catalogue`. It is the most common Gherkin smell precisely because Cucumber does nothing to discourage it. ## Why Cucumber never objects Cucumber strips the step keyword before matching. `Given`, `When`, `Then`, `And`, `But` and `*` are all removed, and in Cucumber-JVM the `@Given`, `@When` and `@Then` annotations are interchangeable when a step is matched - the keyword is there for the reader. What is matched is the whole remaining sentence, and a sentence containing *and* is just a longer sentence. So: - the compound line matches one definition, not two; - when it is undefined, Cucumber prints one snippet for the whole sentence, so accepting the generated stub cements the compound; - the run reports one step with one result and one duration. That is the trap: the tool makes the wrong shape marginally cheaper to create than the right one. ## What the conjunction costs | Cost | What you actually see | |---|---| | Reuse | The definition matches exactly one sentence; the half you wanted elsewhere has to be written again | | Diagnosis | One red step for two actions - the failure text names sign-in even when the catalogue failed | | Timing | One duration covers both actions, so you cannot see which half is slow | | Growth | Each new pairing ("sign in and open the order history") is another sentence-long definition | | Readability | The scenario stops being a sequence of facts and becomes a paragraph | On a seed-catalogue ordering service the effect compounded with a merge queue that serialises everything: 31 scenarios each opened with a sign-in-and-navigate compound, and when the catalogue page began failing intermittently the report blamed a step whose text started with "I sign in", so three engineers looked at authentication first. The compound cost more in triage than it ever saved in typing. ## Splitting it 1. **Separate the actions onto their own lines.** `Given "rosa" is signed in` then `And the seed catalogue is open`. Two lines, two definitions, both reusable. 2. **Phrase the Given as a state, not an action.** A `Given` describes the world before the behaviour under test; `"rosa" is signed in` is a fact, `I sign in` is a procedure. Stating it as a fact frees the definition to reach that state the cheapest way it can - often a seeded session rather than a real sign-in. 3. **Keep only the real action in `When`.** If the scenario is about ordering, sign-in and navigation are both context; the single `When` is the order. 4. **Let repeated context move up.** When every scenario in the file needs the same two Givens, that is a question about `Background` or a tagged hook, not a reason to weld the pair back into one line. ## Where the halves should go Splitting is not the same as shredding. The over-correction is to break a compound into control-level micro-steps - open the menu, click the account item, type the password - which trades one unreusable step for six coupled ones and buries the rule. The target is two or three lines that a domain reader would recognise as facts. A useful check: read the split lines aloud without the keywords. If they sound like statements about the system, the split landed; if they sound like instructions to a person driving a machine, you split in the wrong direction. ## When *and* is fine The word itself is not banned. `Given the catalogue lists "Cherokee Trail of Tears" and "Painted Mountain"` is one fact about one thing, not two actions - the conjunction joins two values inside a single state, which a data table or an `Examples` column can also express. The test is not the presence of *and*, it is whether the line does two things that could independently fail. If either half can fail on its own and you would want to know which, it is two steps. ## The `And` keyword is not the problem either `And` as a *keyword* at the start of a line is good Gherkin - it keeps a run of Givens readable instead of repeating `Given` four times. The smell is *and* buried inside the step text, where Cucumber cannot see it and the report cannot separate it. Junior candidates often conflate the two and claim `And` lines should be avoided; that answer inverts the guidance.

  • When is the word and inside a Cucumber step text genuinely acceptable?
    When it joins two values inside one fact rather than two actions - `Given the catalogue lists 'Painted Mountain' and 'Glass Gem'` is a single state that either holds or does not. The test is independent failure: if the halves could fail separately and you would want to know which, it is two steps.
  • You split the compound and now every scenario in the file repeats both halves. What is the next move?
    Repetition across scenarios is a placement question, not a reason to recombine. Context every scenario in the file genuinely needs can sit above them as shared context; machinery most of them do not need belongs in a hook keyed on a tag. Recombining into one line only hides the repetition and loses the reuse again.
  • A team fixes conjunction steps by breaking each one into six control-level steps. What went wrong?
    They split in the wrong direction. Two reusable statements became six steps welded to the interface, so the scenario now documents navigation and every one of those steps breaks on a redesign. Split by intent into two or three domain facts, not by mechanism into individual interactions.

saying these in an interview costs you the question

  • Thinks the And keyword itself is the anti-pattern
  • Says Cucumber will reject a step containing the word and
  • Expects Cucumber to report a compound step as ambiguous
  • Splits a compound into click-level micro-steps
  • Writes Given as a procedure rather than a state