{"id":6093,"date":"2020-10-23T19:26:06","date_gmt":"2020-10-23T13:56:06","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=6093"},"modified":"2020-11-04T19:28:29","modified_gmt":"2020-11-04T13:58:29","slug":"what-is-cucumber-hook","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/what-is-cucumber-hook\/","title":{"rendered":"What is Cucumber Hook?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>What is<\/strong> <strong>Cucumber Hook?<\/strong><\/h2>\n\n\n\n<p><strong>Cucumber hook <\/strong>is a block of code which is defined with scenario in the step definition file by using its own annotations @before and @after. Cucumber Hook allows us to handle the code work flow better and helps in reducing the redundancy. Actually the Hook is mainly used to start or close the web driver session after a specific function. Therefore is not relevant to any scenario.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>The need for a Hook<\/strong><\/h2>\n\n\n\n<p>Some times when testing, we may face some circumstances where we need to perform some pre-requisite steps before the test scenario.<\/p>\n\n\n\n<p>The pre-requisites which may be faced are:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>To start a web driver and set up database connections.<\/li><li>Setting up test data and setting up browser cookies<\/li><li>Navigating to certain page<\/li><\/ol>\n\n\n\n<p>To handle these pre-requisite steps we have to use some Cucumber Hook. In cucumber there are two types of Hooks:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>@Before ,@After<\/strong><\/h4>\n\n\n\n<p>We can use @Before hook with any function or method when we have to start a web driver.<\/p>\n\n\n\n<p>We can use @After hook with any function or method when we have to close web driver.<\/p>\n\n\n\n<p>Consider an example of a tagged Hook:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@Before&nbsp;('@RegressionTest)&nbsp;&nbsp;&nbsp;<br>@After&nbsp;('@RegressionTest)&nbsp;&nbsp;<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Cucumber Hook? Cucumber hook is a block of code which is defined with scenario in the step definition file by using its own annotations @before and @after. Cucumber Hook allows us to handle the code work flow better and helps in reducing the redundancy. Actually the Hook is mainly used to start or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6579,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-6093","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-qa-tutorials"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/6093","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=6093"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/6093\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/6579"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=6093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=6093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=6093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}