You can shorten your scripts - and even get rid of a few - by formulating them in a declarative, rather than imperative , language.
For instance:
Given the cart has two products in When I empty the cart Then I should see it has nothing in it.
This can be exactly the same as the actual shopping cart as a user interface. There are no implementation details in it. You can see that some of the steps correspond to several of yours; this is good, since it preserves the complexity of the code, where it is more convenient to maintain.
If we describe your other scenario this way, we get:
Given my cart is empty Then I should not be able to empty it again.
There is no "when" because "then" is simply true for this state.
Do you really need this script? Will you be able to kill you or your company by releasing with the possibility of emptying an already empty basket? It is essentially aesthetically pleasing. It has been added to simplify the use of the user interface, and the only way to find out if the user interface can be used is to actually use it. If you ever find such scenarios, I recommend taking them out. You can always do a modular logic check, which turns a button on or off.
If you switch to this style of language, delete all scripts that test only aesthetics and usability, you will find that your function files become much smaller.
I also recommend putting the most interesting or unexpected scenarios at the top. For example, this would be a more interesting scenario (and yes, it has two “when” in it, because it describes the behavior associated with the interaction between two different users):
Given a user put a copy of "Moby Dick" in his cart When the last copy of "Moby Dick" is sold And the user comes back to look at his cart Then it should tell him, "Sorry, this item is currently out of stock."
That would be even more interesting:
Given a user put a new copy of "Moby Dick" in his cart And there are second-hand copies of "Moby Dick" available When the last new copy of "Moby Dick" is sold And the user comes back to look at his cart Then it should tell him, "Sorry, this item is currently out of stock." And it should also show the way to the second-hand copies with, "2nd hand copies are available."
This will be a differentiating scenario; what your store did differently in other stores and, therefore, was of great interest to the business.
By placing the most interesting at the top of the page, it does not matter that the function file is long. We all know how the basket for buying and selling items works, and we still don't read the scripts below at this point.
Andy Waite is right when he says there are no hard and fast rules, so play by ear; if it does not work, do something differently. Hope these tips also help.