{"id":48510,"date":"2017-06-09T14:28:35","date_gmt":"2017-06-09T08:58:35","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=48510"},"modified":"2017-06-09T14:33:39","modified_gmt":"2017-06-09T09:03:39","slug":"automation-testing-using-cucumber-tool","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/automation-testing-using-cucumber-tool\/","title":{"rendered":"Automation Testing Using Cucumber Tool"},"content":{"rendered":"<p style=\"text-align: justify\">Cucumber is an automation tool based on Behavior Driven Development (BDD) framework which is used to write tests for a web application. It allows users such as Business Analysts, Developers, Testers, etc. to automate the functionality in an easily readable and understandable format (like plain English).<\/p>\n<p style=\"text-align: justify\">Let us explore more about this automation tool.<\/p>\n<h2 style=\"text-align: justify\">Requirement of the Cucumber Test Automation Tool<\/h2>\n<p style=\"text-align: justify\">There was a need to get rid of the ambiguity and make everything connect to the entire software development lifecycle. Thus, the development process required something that expands the customer\u2019s acceptance criteria to the actual development and testing process. So the idea was to upgrade the existing TDD (Test-Driven Development) process and join the following acceptance tests, functional requirements and software documentation into one arrangement that would be reasonable to non-technical people as well as test automation tools.<\/p>\n<h2 style=\"text-align: justify\">Introduction to Cucumber<\/h2>\n<p style=\"text-align: justify\">You cannot simply download the Cucumber like other test automation tools,<span style=\"background-color: #f5f6f5\">\u00a0<\/span>and start coding and automating your test cases. There is a process needed to make full use of Cucumber which is known as Behavior-Driven Development (BDD).<\/p>\n<p style=\"text-align: justify\">In this process, there are three main people involved. One, who manages the prerequisites like a Business Analyst or a Product Owner. Second, an individual who designs executes and creates it like a developer. The third primary person is the one who is going to test and guarantee it.<\/p>\n<p style=\"text-align: justify\">These key people examine the feature which has to be implemented and discuss various use cases and how the system needs to carry on at different point of time in different situations. Further, these practices are noted down as scenarios which become the written document of how the system has to behave in various cases.<\/p>\n<h2 style=\"text-align: justify\">Language And Platform Compatibility<\/h2>\n<p style=\"text-align: justify\"><strong>Cucumber Implementation<\/strong> is available in open source languages like Python, PHP, Java, Ruby, etc.<\/p>\n<p style=\"text-align: justify\"><b>Framework Integration:<\/b> Cucumber is integrated and supported by frameworks like Waitr, Capybara, Ruby on Rails, Selenium, etc.<\/p>\n<h2 style=\"text-align: justify\">Cucumber Basics<\/h2>\n<p style=\"text-align: justify\">To understand Cucumber, we have to know each of its features and usages. These are described below.<\/p>\n<p style=\"text-align: justify\"><b>1. Feature Files:<\/b><br \/>\nThese are the\u00a0typical test case files in a BDD process and furthermore, go about as living document to the business necessity and a bridge between the requirement documentation and implementation part of it.<\/p>\n<p style=\"text-align: justify\">The syntax\/format in which these feature files are written is called Gherkin; this provides with an arrangement of guidelines which should be taken after composing your feature file. These files should have an extension \u2018.feature.\u2019<\/p>\n<p style=\"text-align: justify\"><b>Scenario:<\/b> The description following this keyword gives the expectation of this test case or scenario, as to what is being checked and in what conditions. To make a scenario more readable, Gherkin offers a few keywords which you can likewise call as clauses.<\/p>\n<p style=\"text-align: justify\"><b>Given:<\/b> Given condition speaks to the pre-conditions required for the specific situation and if your situation requires more than one pre-condition, &#8220;AND&#8221; clause can be used immediately after\u00a0the &#8216;Given&#8217; condition.<\/p>\n<p style=\"text-align: justify\"><b>When:<\/b>\u00a0Any statement that begins with &#8216;when&#8217; clause represents the steps-to-execute part of the test case document. It contains the executions steps that are specific to this scenario. In the majority of such\u00a0circumstances, this section contains more than one step and hence along with this clause we also use the AND clause as well.<\/p>\n<p style=\"text-align: justify\"><b>Then:<\/b>\u00a0Any statement that starts with this clause represents the verification steps and the expected result of the scenario. On the off chance that this part likewise contains multiple steps, then AND clause is used alongside.<\/p>\n<h2 style=\"text-align: justify\">Configure Java Environment for Cucumber Execution:<\/h2>\n<ul style=\"text-align: justify\">\n<ul>\n<li>JAVA \u2013 Install the latest (Java Development Kit) JDK on your machine.<\/li>\n<li>Eclipse \u2013<\/li>\n<\/ul>\n<\/ul>\n<p style=\"text-align: justify\">a) IDE that we will use to write our feature files and all the code behind.<br \/>\nb) When it starts up, choose a workspace.<br \/>\nc) Click on Help\u2013Install New Software, Add plug-in from http:\/\/cucumber.github.com\/cucumber-eclipse\/update-site<\/p>\n<ul style=\"text-align: justify\">\n<ul>\n<li>Download the Cucumber Jars mentioned below, from Online Maven Repository,\u00a0<a title=\"click here\" href=\"https:\/\/search.maven.org.\/#search|ga|1|cucumber-core\">click here.<\/a><\/li>\n<\/ul>\n<\/ul>\n<p style=\"text-align: justify\">a) cucumber-core<br \/>\nb) cucumber-java<br \/>\nc) cucumber-junit<br \/>\nd) cucumber-jvm-deps<br \/>\ne) cucumber-html<br \/>\nf) gherkin<br \/>\ng) junit<\/p>\n<ul style=\"text-align: justify\">\n<li>Download Selenium Standalone Server,\u00a0<a title=\"Download Selenium Standalone Server\" href=\"http:\/\/www.seleniumhq.org\/download\/\">\u00a0here.<\/a><\/li>\n<li>Create a new Java project in Eclipse, and add all downloaded External Jars to Java build path<\/li>\n<\/ul>\n<h2 style=\"text-align: justify\">Running your first Test Scenario:<\/h2>\n<p style=\"text-align: justify\">The steps below, represent one of the\u00a0scenarios that are present in your feature file called <b>Registration.feature<\/b><\/p>\n<p style=\"text-align: justify\"><b>Feature:<\/b><\/p>\n<p style=\"text-align: justify\">As a user<\/p>\n<p style=\"text-align: justify\">I want to be able to add new clients in the system<\/p>\n<p style=\"text-align: justify\">So that I can add accounting data for that client.<\/p>\n<p style=\"text-align: justify\"><b>Scenario: \u00a0<\/b><\/p>\n<p style=\"text-align: justify\">Sign up a new user<\/p>\n<p><span style=\"color: #000000\"><strong>Given<\/strong> the user is on landing page<\/span><\/p>\n<p><span style=\"color: #000000;font-size: 1rem\"><strong>When<\/strong> he chooses to new user<\/span><\/p>\n<p><span style=\"color: #000000;font-size: 1rem\"><strong>And<\/strong> he provides the first name as Tester<\/span><\/p>\n<p><span style=\"color: #000000;font-size: 1rem\"><strong>And<\/strong> he provides the last name as Jenkins<\/span><\/p>\n<p><span style=\"color: #000000;font-size: 1rem\"><strong>And<\/strong> he provides the email as testaddress@gmail.com<\/span><\/p>\n<p><span style=\"color: #000000;font-size: 1rem\"><strong>And<\/strong> he provides the password as password<\/span><\/p>\n<p><span style=\"color: #000000;font-size: 1rem\"><strong>And<\/strong> he provides the confirm password again as password<\/span><\/p>\n<p><span style=\"color: #000000;font-size: 1rem\"><strong>And<\/strong> he signs-up<\/span><\/p>\n<p><span style=\"text-align: justify;font-size: 1rem\"><strong>Then<\/strong> he should be logged in to the application<\/span><\/p>\n<p><span style=\"text-align: justify;font-size: 1rem\">The code representing the above steps in Java is called the Glue Code. A certain format of a regular expression is used to match the steps with their\u00a0respective\u00a0Glue Code.<\/span><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-48636 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled19.png\" alt=\"Untitled\" width=\"628\" height=\"104\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled19.png 628w, \/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled19-300x49.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled19-624x103.png 624w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/p>\n<p style=\"text-align: justify\">The same implies to the other statements irrespective of the clause\/keyword used. Put the above-represented code in .java file inside a class, for example, consider the file name as <b>StepsDefinitions.java.<\/b><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-48588 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled8.png\" alt=\"Untitled\" width=\"628\" height=\"307\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled8.png 628w, \/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled8-300x146.png 300w, \/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled8-624x305.png 624w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/p>\n<h2 style=\"text-align: justify\">Reports<\/h2>\n<p style=\"text-align: justify\"><b>Pretty Format (HTML Report)<\/b><br \/>\nPretty Format produces the Cucumber test report in the HTML design, i.e. an HTML record. It is the most readable report design<\/p>\n<p style=\"text-align: justify\"><b>Create a runner class file.<\/b><\/p>\n<ul style=\"text-align: justify\">\n<li>Create a runner class named cucumberTestRunner.java inside the package.<\/li>\n<li>Write the following code. Save the file.<\/li>\n<\/ul>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft wp-image-48601 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled12-e1495106099585.png\" alt=\"Untitled\" width=\"400\" height=\"119\" \/><\/p>\n<p style=\"text-align: justify\"><b>Run the test using option.<\/b><\/p>\n<ul style=\"text-align: justify\">\n<li>Select <b>cucumberTestRunner.java<\/b> file from package explorer.<\/li>\n<li>Right-click and choose the option, Run as<\/li>\n<li>Select JUnit test<\/li>\n<\/ul>\n<p style=\"text-align: justify\">After execution, under target directory, a folder named as Destination will be created.\u00a0You will be able to see the execution report named as\u00a0<b>\u201cIndex.html.\u201d\u00a0<\/b><\/p>\n<p style=\"text-align: justify\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-48605 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled13.png\" alt=\"Untitled\" width=\"329\" height=\"151\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled13.png 329w, \/blog\/wp-ttn-blog\/uploads\/2017\/05\/Untitled13-300x137.png 300w\" sizes=\"(max-width: 329px) 100vw, 329px\" \/><\/p>\n<p style=\"text-align: justify\">Successful automation does not depend on tools entirely. It is dependent on the standard testing processes, the right test team roles, duties and skills as well. Tools, processes and test teams are the three essential legs of the test automation tool.<\/p>\n<p style=\"text-align: justify\">Hope this answers your basic queries on how to use Cucumber as an automation testing tool.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cucumber is an automation tool based on Behavior Driven Development (BDD) framework which is used to write tests for a web application. It allows users such as Business Analysts, Developers, Testers, etc. to automate the functionality in an easily readable and understandable format (like plain English). Let us explore more about this automation tool. Requirement [&hellip;]<\/p>\n","protected":false},"author":1052,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"image","meta":{"iawp_total_views":21},"categories":[1818,446,1,1816],"tags":[3652,4568,1514],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/48510"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1052"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=48510"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/48510\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=48510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=48510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=48510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}