I have been using SpecFlow for a while, without making use of the "but" logic.
Considering the following scenario:
Scenario: Kiran logs into the system but doesn't click remember me
Given I have a username of 'Kiran'
And a password of 'password'
When I chose login
But I don't chose remember me
Then I should be logged in
And Taken to the home screen
But My username should not be remembered
Couldn't the "but" steps just be interchanged with "and"?
Is there any advantage to using "but"?
Am I right in thinking that this is purely for readability purposes?
I look forward to hearing your thoughts on this.
Many thanks, Kiran
Yes you are right, "and" and "but" are inter-changeable in the gherkin syntax.
However in my experience "and" is used when you are indicating that a user should carry out an action, whereas "but" is best suited to when you want to highlight that a user should not perform an action; this is because "but" in the English language is generally used in a negative context.
Hence in your example:
But I don't chose remember me
Is a good use of "but" as they are not performing an action. Additionally using "but" makes the intent of the test explicit and removes any possible ambiguities.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With