0
votes

My test suite currently has its features run in parallel, and the scenarios in each of these features run one after the other, without having to reset webdriver in between scenarios. This all works fine but I am struggling to find a good way to do a teardown after the whole feature is finished, I cannot use AfterFeature as it requires my webdriver to be static and that will prevent parallel exeuction from working, and if I do the teardown in afterScenario then I would need to restart my webdriver for every scenario, which will unnecessarily take up much more time. Is there any way to use featurecontext or something to determine if the current scenario is the last one in the feature? or something else that does something similar? I basically need a way to determine if the current scenario is the end of the feature without using Before/AfterFeature

1
I don't have experience in parallel execution, but you maybe want to hard code name of your scenario (w_last, w_finish...abuse it, I did it a couple of times when needed) and make sure that expected scenario is executing last among set of scenarios in one feature (with nUnit scenarios are executed in alphabetical order) . And then using FeatureContext.Current.FeatureInfo.Title to query if it contains hard coded substring. Check link: ontestautomation.com/running-your-tests-in-a-specific-orderStefan Zivkovic
I have thought about doing this and it's probably what I'll need to do if there is absolutely no other way, but ideally I'd want this to work no matter how many scenarios I'm running in the feature, It should work if I choose to run anywhere from 1-10 of the scenarios in any combination. So I am looking for a way to somehow get the number of tests/scenarios that are running for this feature in this run, or somehow finding out when the feature is about to be over before it actually endsmeshier

1 Answers

0
votes

By default Specflow sort scenarios alphabetically but you can work around it by naming scenarios with numbers in the start, like 01 - Login, 02 - Logout.
And then use the approach suggested in comments.
On AfterScenario hook:

  1. get all scenarios names and sort them
  2. get the last scenario name
  3. if it is equal to the current scenario - reset web driver instance.

Nothing will be hardcoded and will work for all your suites. But you should maintain the naming approach with index in the start.