AUTOMATION FRAMEWORKS

Behave Scenarios That Stay Readable Under AI-Speed Pressure

There's a particular kind of pain in Behave projects that have been running for a while. Scenarios that made sense when they were written are now walls of text nobody wants to touch. A When step that does five things. A Given that sets up half the database. Titles that say "test checkout" and nothing else. It doesn't happen because people are careless. Readable scenarios take deliberate effort, and that effort is the first thing to go when a sprint gets tight.

Scenarios serve two audiences: the engineers who maintain the steps, and the product people who are supposed to read the feature files and confirm they describe real behaviour. Drift toward implementation detail and you lose the second group. Drift toward vague business-speak and you lose the first.

There's now a third reader: the coding agent. When Copilot or another agent implements step definitions, the feature file is its specification. An agent can also produce Gherkin far faster than anyone can review it, so pressure that used to come from deadlines now also comes from volume. These are the patterns I use to keep scenarios honest and readable, plus a few guards I add so agent-written scenarios don't erode them.

Build an API Automation Framework in Python

Learn Python, Behave, GitHub Copilot, APIs, and CI/CD by building a real framework you can finish in a weekend.

Learn more

The title is your first defence against ambiguity

Most titles I see are either too vague ("User logs in") or too technical ("POST /auth/token returns 200 with valid credentials"). The vague one tells you nothing when it fails. The technical one breaks the abstraction that makes Gherkin worth having. A title that holds up names the business outcome and the condition that makes this scenario different from its neighbours:

Scenario: Subscriber with an expired plan cannot open premium content
Scenario: Guest sees a login prompt when trying to bookmark an article
Scenario: Admin can deactivate an account that has no pending orders

Each says who, what and why it matters, without HTTP verbs or status codes. My quick check: read the title to someone who hasn't seen the file. If they can say what's being verified without the steps, the title works. Writing a real title feels like overhead at the end of a sprint, but a bad title is overhead paid every time anyone reads the scenario afterwards.

Keep every step at one level of abstraction

The most common readability problem in mature suites is steps that mix levels. A scenario reads cleanly in business terms, then suddenly drops into response bodies and database rows. Readers have to switch context mid-scenario to work out what's actually being checked.

# Drifted: mixed abstraction
Scenario: User upgrades their plan
  Given a user exists with email "test@example.com" and plan "free"
  When I send a PUT request to "/users/42/plan" with body {"plan": "pro"}
  Then the response status code is 200
  And the user's plan in the database is "pro"
# Consistent business abstraction
Scenario: Free user upgrades to the pro plan
  Given a free-tier user is logged in
  When they upgrade to the pro plan
  Then their account shows the pro plan immediately

The endpoint, the status code and the persistence check all still happen. They live in the step definitions. That's the principle behind step definitions that stay reusable: the step layer carries the implementation so the scenario doesn't have to.

Engineers usually push technical detail up into Gherkin because they don't trust the step to be precise. That's a reason to make the step more precise, not to put HTTP into the feature file. The opposite failure exists too: steps so high-level that two scenarios look different but exercise the same thing. If you can't say what distinguishes two scenarios from their steps, one of them probably isn't needed.

Scenario bloat and Background abuse

Readability also depends on the whole file. Two anti-patterns tend to appear together.

Bloat is one scenario testing several behaviours: a long run of steps, or several Thens that each check a different concern. When it fails, you know something broke but not which behaviour. Split it. More focused scenarios are easier to read than fewer bloated ones.

Background abuse is subtler. Background is for setup that truly applies to every scenario in the file. When it holds setup only some scenarios need, the others carry invisible preconditions, and readers have to mentally subtract the Background to understand them. My test: if you removed this Background line, would every scenario in the file fail or stop making sense? If not, move it into the scenarios that need it, or split the file. When files keep growing, the structure advice in structuring a Behave project so it scales applies directly.

When an agent writes the Gherkin

Agents are good at producing Gherkin that looks right. Left to themselves, they tend toward exactly the drift above: HTTP details in steps, because the agent can see the endpoint; very long scenarios, because more steps look more thorough; and slightly reworded steps that don't match existing definitions, so every new scenario brings new step code with it.

The bigger risk is the scenario being edited to fit the code. If a scenario fails and an agent is asked to make the build pass, rewording the Then is often the shortest route. The feature file then describes what the system does, not what anyone decided it should do. I set clear rules in .github/copilot-instructions.md (or your agent's equivalent):

## Feature files
- Scenarios describe business behaviour. No URLs, HTTP verbs, status codes or JSON in .feature files.
- Reuse existing step wording from features/steps/ before adding a new step.
- One behaviour per scenario. Background only for setup every scenario in the file needs.
- Never edit an existing scenario to make it pass. Report the mismatch in the PR instead.

Rules in a file are advice, not enforcement, so I back the first one with a small check that runs in CI:

# scripts/check_features.py
import pathlib
import re
import sys

LEAKS = re.compile(r'\b(GET|POST|PUT|PATCH|DELETE)\b|/api/|status code|\{\s*"')

problems = []
for path in pathlib.Path("features").rglob("*.feature"):
    for n, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
        if LEAKS.search(line):
            problems.append(f"{path}:{n}: {line.strip()}")

print("\n".join(problems))
sys.exit(1 if problems else 0)

It's deliberately crude and will need tuning for your domain language, but it catches the most common drift before a reviewer has to. The fourth rule needs a person: I route changes to features/ to a human reviewer with CODEOWNERS, so an edited Then can't slip through in a large agent PR.

The positive side is real, too. A clean, consistent feature file is the best prompt you can give an agent. When the scenario states the behaviour in plain language and the steps follow a pattern, the agent implements the step against a clear target instead of guessing. I cover that workflow in prompting an AI assistant to write Behave step definitions.

Readable scenarios are documentation

Scenarios last longest when they capture why a behaviour exists, not just that it does. A scenario that reads like a business rule in plain language earns its place however fast the team is moving, and it gives every reader, human or agent, the same unambiguous target. If you'd like to build a Behave suite this way from the start, with VS Code and GitHub Copilot, my API testing courses walk through it.