{"id":6091,"date":"2020-10-23T19:24:45","date_gmt":"2020-10-23T13:54:45","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=6091"},"modified":"2020-11-04T19:26:59","modified_gmt":"2020-11-04T13:56:59","slug":"cucumber","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/cucumber\/","title":{"rendered":"Cucumber"},"content":{"rendered":"\n<p>Cucumber is an open source tool that supports Behaviour Driven development. It explains the given application into simple like English language called Gherkin.<\/p>\n\n\n\n<p>The Gherkin includes components like :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Feature<\/li><li>Scenario<\/li><li>Background<\/li><li>Given<\/li><li>When<\/li><li>Then<\/li><li>And &amp; But<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to use these Gherkin components in cucumber testing?<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>First, identify the scenario which you want to automate.<\/li><li>Add a feature file for the scenario<\/li><li>Create a test Runner class that will execute feature file<\/li><li>Create a step definition which has to be linked to the java code.<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to create a feature file in Cucumber?<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>Setup a cucumber eclipse plug in.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/AaKKO_56JIKrtGL5l7jvZTgZpbVOXw5HQ3h_hwRDj2dh2aApZ297t58y0XL-uecleA8hOTdaairoTonChvn3nzb0K1N3HEgpv1kg3n7Fe22os43LtUMHv4RpJ9BLZ7D4PD1I0lqm2AQbdBJN3A\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li>Create a new Maven project in Java EE in new project.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/CAeR8lj_yg4_rXSZnc1T0PM82xasrVn-6RAFAd-hOA__JukVXdbxv3vGV8H-PvKNJM0uh4LduxZCf-rqn0RY_OGSAODTG13JH3Zgx0cgPrIkHYLgYCfjAY14bEWfJx2AC2XxWV8EZoaFEJKP-g\" alt=\"Add new source folder in Cucumber project\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li>Enter the details of the maven project like Group id etc.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/ccKscFzx57plvT1x29JJ0yItIQatJOuN4X_R3mJKYtuiXQ2kloDqA6uWw1M5JmfYBotdA9ir4XYhT-lejZi3t9SXwY26gx4ClNAPQ1iDbYdlcMJNdieYRY53RxLekL0O381I0_kYFSdz5RMjUw\" alt=\"New Package in resources folder\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\"><li>Type the scenario for home page. This is an example to verify the website called orange HRM home page by launching the chrome browser. This is a feature file, very simple and easy to write. Any body can write this feature file as it is easily understandable by others.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/9GP-9tCF7V41mKTcWHAznxPocDmhELLjgOzxg0tGexfDe1Zy3eNcfPOj_tiJ0xfq9UcmYXuomLZJcf2sUgcDTz12Vs_p87UQ-YNZ2pvPMPRVcu6ALhbJOBIPiRrvpzKeG7-Y9qVFESXaDuiUGw\" alt=\"Cucumber feature file in eclipse project\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\"><li>Next create step definitions under this. Create a java class by clicking on the folder called step definition.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/EWYcZ4pDkGwm5iOY83Z177tKyqe9GcnSiw23XPrNezG3t6UwawJpL7j_z_3G78YHI6DXKPyx2f7EyKFL3MDy-jhtUgvDylGgqnkW5fcqLOuGuMaBha63LzZU6pKD1NuXPLgl7jourLb5SLk-Sw\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"6\"><li>Create all the methods for the step definition. To do that, go to feature file Right click -&gt; select run feature file. When the feature file gets executed it fails and provides a suggestions of missing methods in the form of snippets.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/NsOtH6b973g0kQYjnj7pxFW-wES7Zyp8hclyPZpTeeKdHw9rTAJVJOJKdPF145UboWmbqkjr322aRhjTkH6QpFO4aMSjrwGiiTNFGa6LEE7qFgYvswxOcRFr9Al7HihboTL0apSdWIKB9Bbekg\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>According to the output created by the feature file while running all the scenario<\/p>\n\n\n\n<p>steps get failed and missing methods are provided for the implementation.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/dKlDEEGdSw-ueNkcaauLfoYdpSKvrITK2JROfIBG6BOVvAzL9Cr1wdmYl1_xxP7-IMAuVL6id6WL-9knU1uLu66JVzUednWaqrSGjPn3Z--xhMnZpoZ8gUsvsHzjXPBWRAzpE20Iczh3vuQN2Q\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"7\"><li>Copy the snippets and paste in the step definition screen under the java class.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/hrJSoE1Elrg8E_bTrMJpKG6LdfJ12wYWodVzQaqWHA5Cy_EOt9PoBTjby1h1VXPL1jPHKVUFirZ7vqWagDiB5z912KmPAEQvnLxRgGVgi_t2iOBsefBSQTwSMsvVcrS6spJFOPwyQS1yyXgEjg\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"8\"><li>Whatever we have copied is just a outer structure. We have to type it, in order to eliminate errors for each step definition method which is created by executing the feature file. Once we start typing on the component a list of package is provided.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/O6WJe-HRhogmJILYYiZ2EZ4pyPtEDiqhmBh6krShbDvb9s0jq5_jtoV1lhJ-g8mapitp2JynWjcroaBnFNTMFXXGdfX7A6-P5c-li6fXQPvUhrPHkvrGDaMwVdpikFxJSkKzSdr5ajfusGF7sA\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"9\"><li>Import the package of cucumber and all the errors of the methods will be eliminated.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/H2A5tscj2EZ1tmUYs4pv1WSTnEJl0onxCK3c5MVLT__7GCT6KewYKieNlkLQsCXCrltk5xBtA6gPpY6X0jnRcgI5YZSKsJ18uiNmp2TVC5o-vPMcAh1vP9pVavWL3wb5iMTYUnmsPzkTFRNi4Q\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"10\"><li>&nbsp;Write the codes properly for all the methods in the application, in order to implement the scenario. At the end of the file, then it is automatically created and it can also be changed to And.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/spliHMvvZ2a0YDPMRpDs3UWWM8s9JFgxaePIUYDlosz4kH7l_eq6ZG6iiodtbVUL-1znEKaYgukq1Vi6rEdMX2AaA3EqvweMFyOFcV0Wf-qmoiKpquRDlHm2N7wzBZHiXSj1tlCq4r5q5rPbGQ\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<ol class=\"wp-block-list\" start=\"11\"><li>Lastly run the feature file as usual mentioned in the above screenshot. We can see, in the below mentioned, that there is one scenario and four steps which is passed.<\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/BHqjqAGcX4mkoLx0Pay0boNv-6ZqVt9zh1yeqhHREgw3LscE-Ygew3T05_HRVxgyLpSWAdi0e5TWYRjeb0Y9vCtbdcGflZe6LmIP49D5zvkXa27XZFjzDXdmXKE-fraCTss4nJT4QjH3vXalkw\" alt=\"\" title=\"\"><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Cucumber is an open source tool that supports Behaviour Driven development. It explains the given application into simple like English language called Gherkin. The Gherkin includes components like : Feature Scenario Background Given When Then And &amp; But How to use these Gherkin components in cucumber testing? First, identify the scenario which you want to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6578,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-6091","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\/6091","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=6091"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/6091\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/6578"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=6091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=6091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=6091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}