{"id":9953,"date":"2023-04-02T11:42:21","date_gmt":"2023-04-02T11:42:21","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=9953"},"modified":"2023-04-02T11:42:21","modified_gmt":"2023-04-02T11:42:21","slug":"ordering-of-our-specflow-hooks","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/ordering-of-our-specflow-hooks\/","title":{"rendered":"Ordering of our SpecFlow hooks"},"content":{"rendered":"<p>In my post <a href=\"https:\/\/putridparrot.com\/blog\/running-code-when-a-feature-or-scenario-starts-in-specflow\/\" rel=\"noopener\" target=\"_blank\">Running code when a feature or scenario starts in SpecFlow<\/a> I showed we can use hooks to run before the feature and scenario. However, what if we have, for example, a lot of separate scenario hooks but the order that they run in matters. Maybe we need to have the logging of the scenario title and this should run first.<\/p>\n<p>The <em>BeforeScenario<\/em> has a property <em>Order<\/em> which we can assign a number like this<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n&#x5B;BeforeScenario(Order = 1)]\r\npublic static void BeforeScenario(ScenarioContext scenarioContext)\r\n{\r\n  Debug.WriteLine($&quot;Scenario starting: {scenarioContext.ScenarioInfo.Title}&quot;);\r\n}\r\n<\/pre>\n<p>This will run before other scenarios, including those with no <em>Order<\/em> property. <\/p>\n<p>Beware, if you set the [AfterScenario(Order = 1)] it would also be run first. Which you might not want in a logging situation, then (the only solutions I&#8217;ve found thuis far is) you&#8217;ll have to actually have an Order property in all <em>AfterScenario<\/em> attributes, i.e. explicitly state the order or all such hooks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my post Running code when a feature or scenario starts in SpecFlow I showed we can use hooks to run before the feature and scenario. However, what if we have, for example, a lot of separate scenario hooks but the order that they run in matters. Maybe we need to have the logging of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[33],"tags":[],"class_list":["post-9953","post","type-post","status-publish","format-standard","hentry","category-specflow"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9953","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=9953"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9953\/revisions"}],"predecessor-version":[{"id":9955,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9953\/revisions\/9955"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=9953"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=9953"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=9953"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}