Reputation: 259
We have a @BeforeStories in a common file for our JBehave / Java / Selenium automation project that does some set up steps that we need for most story files in our automation project. But, there are a few new story files in which we do not want to run everything in the @BeforeStories. Ideally, I could just remove some of these items from the @BeforeStories if they do not apply to every .story file. This actually is our end goal, but is not something we want to do at this moment as it would affect a lot of existing tests. Anyways, for the time being, if I could override the @BeforeStories for only a few story files, that would work. Then, I could take the parts of the @BeforeStories that I want to run for the new .story files and then leave out the other parts that I do not want to run for the new .story files I am creating. Skipping the @BeforeStories would also work for these new .story files as I could find other ways to handle the necessary set up steps for the new .story files ( i.e. add a "@BeforeStory" to the new .story files to handle the necessary set up steps in the new .story file for example ). Is an override or skip of the @BeforeStories possible? Thanks in advance for any advice.
Upvotes: 0
Views: 337
Reputation: 2838
Your best solution, in my opinion, and what I do with my stories, is to have a base steps class that contains @BeforeStories and has only the common steps necessary for all stories. Then I place a @BeforeStory in each steps class to address the requirements specific for that story.
As an example, in my Appium test suite, I place the code to start the Appium Server and the code to initialize my Extent Reports object in the @BeforeStories in the base class.
However, as each story has its own application, I don't establish the connection there but do it in the @BeforeStory of each steps class, along with further defining the Extent Reports object, and launching the emulator, if applicable.
I originally had those @BeforeStory steps in my base class @BeforeStories until I had multiple stories to run.
Upvotes: 3