Best Practices: Duplicate test steps
# i-need-help
f
What’s the best way to handle tests that have duplicate steps?
p
I am keen to know this especially when we use cucumber like cypress-cucumber-preprocess plug-in
a
I currently have the same concern. I use cucumber and I have several features that have the same steps. What I have currently done is group them into classes of steps, for example: I create a class called CheckoutStep and there I put all the steps that are common to the features. So each step feature that is repeated in each feature goes to the same place.
c
Use Background from BDD
f
Should one leverage custom commands? Sometimes the duplication is unavoidable πŸ˜…
e
For duplicate test steps I always throw them in the commands file.
l
I loosely follow this convention: - Need to re-use steps in a single spec file? Use a regular function at the bottom of the
describe
scope. (Regular functions get "hoisted", meaning they can be declared after places they are used, thus they reduce clutter at the top of the
describe
and
it
blocks.) - Need to re-use steps among several spec files? Create a common file that you can import into the specs. - Have a sequence of steps that you plan to use a lot throughout many of your tests? Create a Cypress custom command.
f
Perfect, thank you πŸ™πŸ»
2 Views