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 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:
- get all scenarios names and sort them
- get the last scenario name
- 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.
FeatureContext.Current.FeatureInfo.Title
to query if it contains hard coded substring. Check link: ontestautomation.com/running-your-tests-in-a-specific-order – Stefan Zivkovic