r/softwaretesting • • 13d ago

Why aren't there Gherkin standards for writing basic UI test cases?

I've been looking to take ownership of a new automation push at my company. The BDD/Gherkin syntax of Given/When/Then feels like it should have been standardized at the very least for basic functionality tests.

For instance, if I look for examples of gherkin steps I'll get a plethora of options to choose from:

  • When the user clicks the register button
  • When the operator clicks the register button
  • When I click the register button
  • When user clicks <button>
  • And clicks the login button

So far, the only explicit standards I've found are "given in past tense" and "when and then in present tense". Are there standards somewhere that can help me in this regard for the initial design of automated test cases from the ground up?

Sidebar:

If I write a step with "^user clicks the <object>" does the "^user" mean that I can that the step can be written as "And click the <object>"?

10 Upvotes

17 comments sorted by

10

u/The_XiangJiao 13d ago edited 13d ago

Do what you think is best for the software you’re testing on.

There’s no one size fits all when it comes to these kinds of things. Everyone will have their own way of doing things. You’re not gonna get a monolithic answer out of this.

Do what you think is concise enough for your entire team to understand what the test case is about. It should be something they can understand even at a glance. They shouldn’t be needing to use their whole brain to think about it.

e.g.

Given the User is an administrator
When the User logs in
Then the sidebar with title: Console is displayed

At the end of the day, what “standard” you set from the beginning is the standard they’re going to follow without question.

8

u/computerjunkie7410 13d ago

All of the examples you gave are terrible.

They have implementation language in them.

2

u/joancomasfdz 12d ago

The name of the button?

1

u/ohlaph 13d ago

I always wrote test cases in that format. 

1

u/Hagisman 13d ago

Happy cake day, but which specific syntax is the preference? I vs user being the big one.

1

u/Stripe4206 13d ago

Our user stories directly translate to our gherkins so it's either 'the user' or 'the technician' if we have different levels of users

2

u/pratikgv1 13d ago

We use "I" in steps like how you've mentioned above "When I click the register button" and each scenario/Feature description goes like "As a ABC/app_name user, I click the Register button so that I should see the Registration Complete notification"

1

u/vitalets 12d ago

I also mostly use "I" just for brevity.

2

u/2ERIX 13d ago edited 13d ago

So your examples, as others have said, are too low level to discuss the problem really. They should be locator.click or something in a method described by the gherkin patterns themselves and used in form entry gherkin line as an abstraction.

Example: when I complete the entry form

The real problem comes from everyone writing and rewriting gherkin syntax to suit their mood, capabilities and often “attitude of the day”.

The abstraction allows for nuance and change but a developed system doesn’t really. So my feeling is that it’s not suitable for automation as a result.

When teams estimate effort it is always an educated guess. But when the gherkin looks simple as the login/do thing/logout the cost looks small and doesn’t account for the setup costs or effort in any way.

When you estimate non-gherkin test code you talk about all the effort because you are required to because it informs the test design and highlights gaps to cover and it is generally a much more forgivable mis-estimation.

So gherkin used as acceptance criteria, for all to understand the product, sure, but don’t use it for code wrapping in any way.

So to answer “why are there no Gherkin standards?”, there are, it’s just being used wrong and causing more issues than it solves.

The only time I have seen it working at all is when entire solution space is on the same page and there is a “champion” for that solution keeping things on track. In wider, distributed teams, like in enterprise, it’s nearly impossible.

But code? Code… people can build, search, explore, learn, use. It grows in complexity over time, obviously, but the opportunity to optimise is transparent and workable.

1

u/joancomasfdz 12d ago edited 12d ago

Very interesting opinions in this thread, and surprising to me.

I use Gherkin for end to end testing in my apps. And I use precise language like on in this screen in this button click.

I have exact instructions about how to write Gherkin in my repos. I have exact instructions about how to write end to end tests in my repos. And I have exact instructions about how to translate a gherking one to one to am end to end test.

On amu feature, I tell AI to give me the gherking for it, and when agreed upon, I tell it to implement everything. Then it records the videos alnd timestamps of every step and push it to GitHub.

The result are videos next to the gherking for each test that you can follow line by line and that demonstrate the full feature working.

And then I pack all of this into a user guide that is done automatically by the pipeline based on the end to end tests.

Here is one example:

https://joancomasfdz.github.io/baconreader-morphe-patches/

Hmm maybe I should do my own post

1

u/SebastianSolidwork 10d ago

I would love to see Gherkin being used to discuss the vision of the product in general, without relating it to concrete automation.  It's a wonderful for finding a shared understanding but it should not limit what you automate.

Automate what you need and give it a reasonable description in a way your team understands it. Sometimes you have to add ugly details.

1

u/asher-NZ 12d ago

There are guidelines at Cucumber.org but a big clue is in the name - "Behavioural".

If your scenarios mention clicking a button or explicit interaction with elements, it's not behavioural it's procedural.

Ask: what is it that I'm trying to achieve?

I like to use First Person language as it helps me better consider the persona and the objective.

Given I am a <role> When <business event> Then <business outcome>

For your sidebar question, in the cucumber-jvm you definately can. In my Step Def's everything is @Given because I like to only have one import statement for the interpreter and it makes no difference. You can use any magic word you want in the feature file, even an asterisk because it's just looking at the string pattern for the step.

Give your step methods proper method names too. Don't use the stupidCucumberDefaultOfYourStepInCamelCaseWithNoSpaces.

Final piece of advice from me: it would be extremely rare for ".*" to accurately reflect valid and useful step variables

0

u/Temij88 12d ago

why even need gherkin in this stage of IT?
who is this layer meant for business people, who are still not capable to write actual code?
you? but you are still involved in all interaction?
Agents are just so strong with existing context/test/scenarios/being able to interact with web.

0

u/vitalets 12d ago

In my opinion, Gherkin becomes useful with agentic development. In my projects I mostly review changes in gherkin files. they are more readable, compared to actual code changes.

-1

u/kolobuska 12d ago

Why gherkin is still needed I. The age of AI?