{"id":115201,"date":"2018-03-12T06:35:04","date_gmt":"2018-03-12T06:35:04","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=115201"},"modified":"2021-07-16T12:13:25","modified_gmt":"2021-07-16T12:13:25","slug":"parametrization-in-cucumber","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/","title":{"rendered":"Parametrization in Cucumber"},"content":{"rendered":"\n<p>In our previous <a href=\"https:\/\/webkul.com\/blog\/how-to-implement-cucumber-with-selenium\/\">blog<\/a> on Cucumber Introduction, we understood the basic concept of Cucumber and behavior driven testing(BDD); In this blog we will have a glance at parametrization concept in cucumber.<br>The basic requirement of automated testing is to use same test again and again but with different set of data. Although, cucumber is a BDD framework but it supports the concept of <b>Data Driven Testing<\/b><\/p>\n\n\n\n<p>Cucumber supports Data Driven Testing using <b>Scenario Outline<\/b> and <b>Examples<\/b> keywords. Creating a feature file with Scenario Outline and Example keywords will help to reduce the code and testing multiple scenarios with different values.<\/p>\n\n\n\n<div class=\"wk-index-wrap\"><h3 class=\"index-title\">Scenario Outline<\/h3><\/div>\n\n\n\n<p>This keyword lets you run the same scenario for two or more different input data. It basically replaces value assigned in the variable from the input values mentioned in the <b>Examples<\/b> input data set. Each row in the input data set acts as a scenario.<\/p>\n\n\n\n<p>For better understanding, we can consider an example of login page, where for every different Login credentials, a scenario has to be defined, and each step will be repeated for every input data.<\/p>\n\n\n\n<p>For such cases, the scenarios will look something like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:plain\">Scenario:\n\nGiven user navigates to Login page\n\nWhen I enter correct username and password\n\nThen login should be successful\n\nScenario:\n\nGiven user navigates to Login page\n\nWhen I enter correct UName and Password\n\nThen login should be successful\n\nScenario:\n\nGiven user navigates to Login page\n\nWhen I enter correct LoginID and PSWD\n\nThen login should be successful<\/pre>\n\n\n\n<p>As we can see in the above mentioned scenarios the input parameters is changing for every scenario. That\u2019s where the importance of scenario outline comes into picture.<br>By using Scenario Outline we can specify one test scenario and at the bottom of it we can provide a number of inputs. The scenario will get executed as many number of times as the number of inputs provided.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Examples<\/h3>\n\n\n\n<p><em>All scenario outlines are followed by Examples part that contains the set of data that has to be passed during the execution of tests.<\/em><\/p>\n\n\n\n<p>Scenario Outline and Examples keyword together will form a set of test cases something like this.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:plain\">Scenario Outline: Test user Login with different credentials\n\tGiven Open Firefox and navigate to Login page\n\tWhen valid \"&lt;username&gt;\" and \"&lt;password&gt;\" is entered\n\tThen User should be logged in successfully\n\nExamples:\n    | username   | password |\n    | rahul@gmail.com | Test@123 |\n    | xyz@gmail.com| Testtest |<\/pre>\n\n\n\n<p>After creating feature file, create a Test Runner class and a steps to run class for further execution.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:java\">package Login_cucumber;\nimport org.junit.runner.RunWith;\nimport cucumber.api.CucumberOptions;\nimport cucumber.api.junit.Cucumber;\n\n@RunWith(Cucumber.class)\n@CucumberOptions(features = {\"Cases\"},glue={\"StepsToTest\"})\npublic class TestRunner {\n}<\/pre>\n\n\n\n<p>After running the class,create a class for steps to run the actual test in which the execution flow of the test will be mentioned.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:java\">public class LoginSteps {\n    \n    WebDriver driver;    \n \n    @Given(\"^Open Firefox and navigate to Login page$\")\n    public void given_Open_Firefox_and_navigate_to_Login_page() throws Throwable\n    {\n       driver = new FirefoxDriver();\n       driver.get(\"http:\/\/LoginPage.com\");\n       driver.manage().window().maximize();\")\n    }\n      \n    @When(\"^valid \\\"(.*)\\\" and \\\"(.*)\\ is entered$\")\n    public void when_valid_username_and_password_is_entered(String username,String password) throws Throwable\n    {\n        driver.findElement(By.xpath(\".\/\/*[@id='login']\")).sendKeys(username);\n        driver.findElement(By.xpath(\".\/\/*[@id='password']\")).sendKeys(password);\n    }\n      \n    @Then(\"^user should logged in successfully$\") throws Throwable\n    public void then_user_should_logged_in_successfully()\n    {\n    driver.findElement(By.xpath(\".\/\/*[@id='submit']\")).click();\n    System.out.println(\"User Logged in successfully\");\n    }\n}<\/pre>\n\n\n\n<p>On running this class,the login credentials i.e username and password will get filled from feature file with new values each time till the Examples has values; in current example, test will run for two times as it has two test data.<br>Instead of hard coding the test data, variables are defined in the Examples section and used in Scenario Outline section.<\/p>\n\n\n\n<p>This was the concept of parametrization in cucumber.<\/p>\n\n\n\n<p>Please share your valuable feedback in the comment section below. Keep Testing!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our previous blog on Cucumber Introduction, we understood the basic concept of Cucumber and behavior driven testing(BDD); In this blog we will have a glance at parametrization concept in cucumber.The basic requirement of automated testing is to use same test again and again but with different set of data. Although, cucumber is a BDD <a href=\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":180,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3137,4932],"tags":[6283,6281,6282],"class_list":["post-115201","post","type-post","status-publish","format-standard","hentry","category-testing","category-web-testing","tag-cucumber","tag-how-to-pass-values-in-cucumber","tag-parametrization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Parametrization in Cucumber | How to parametrize values in cucumber | Parametrization<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Parametrization in Cucumber | How to parametrize values in cucumber | Parametrization\" \/>\n<meta property=\"og:description\" content=\"In our previous blog on Cucumber Introduction, we understood the basic concept of Cucumber and behavior driven testing(BDD); In this blog we will have a glance at parametrization concept in cucumber.The basic requirement of automated testing is to use same test again and again but with different set of data. Although, cucumber is a BDD [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-12T06:35:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-16T12:13:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Rahul Upadhyay\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rahul Upadhyay\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/\"},\"author\":{\"name\":\"Rahul Upadhyay\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/4e1d2bf0d14e7c6e80a97902e9982e3e\"},\"headline\":\"Parametrization in Cucumber\",\"datePublished\":\"2018-03-12T06:35:04+00:00\",\"dateModified\":\"2021-07-16T12:13:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/\"},\"wordCount\":428,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"cucumber\",\"How to pass values in cucumber\",\"parametrization\"],\"articleSection\":[\"Testing\",\"Web testing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/\",\"url\":\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/\",\"name\":\"Parametrization in Cucumber | How to parametrize values in cucumber | Parametrization\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2018-03-12T06:35:04+00:00\",\"dateModified\":\"2021-07-16T12:13:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Parametrization in Cucumber\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/4e1d2bf0d14e7c6e80a97902e9982e3e\",\"name\":\"Rahul Upadhyay\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ec3e4b9e8fc4bf599e04086b0c15093211ef33767ae4c07a6c63169735efbd1e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ec3e4b9e8fc4bf599e04086b0c15093211ef33767ae4c07a6c63169735efbd1e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Rahul Upadhyay\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/rahulkumar-upadhyay671\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Parametrization in Cucumber | How to parametrize values in cucumber | Parametrization","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/","og_locale":"en_US","og_type":"article","og_title":"Parametrization in Cucumber | How to parametrize values in cucumber | Parametrization","og_description":"In our previous blog on Cucumber Introduction, we understood the basic concept of Cucumber and behavior driven testing(BDD); In this blog we will have a glance at parametrization concept in cucumber.The basic requirement of automated testing is to use same test again and again but with different set of data. Although, cucumber is a BDD [...]","og_url":"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2018-03-12T06:35:04+00:00","article_modified_time":"2021-07-16T12:13:25+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Rahul Upadhyay","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Rahul Upadhyay","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/"},"author":{"name":"Rahul Upadhyay","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/4e1d2bf0d14e7c6e80a97902e9982e3e"},"headline":"Parametrization in Cucumber","datePublished":"2018-03-12T06:35:04+00:00","dateModified":"2021-07-16T12:13:25+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/"},"wordCount":428,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["cucumber","How to pass values in cucumber","parametrization"],"articleSection":["Testing","Web testing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/","url":"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/","name":"Parametrization in Cucumber | How to parametrize values in cucumber | Parametrization","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2018-03-12T06:35:04+00:00","dateModified":"2021-07-16T12:13:25+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/parametrization-in-cucumber\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Parametrization in Cucumber"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/4e1d2bf0d14e7c6e80a97902e9982e3e","name":"Rahul Upadhyay","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ec3e4b9e8fc4bf599e04086b0c15093211ef33767ae4c07a6c63169735efbd1e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ec3e4b9e8fc4bf599e04086b0c15093211ef33767ae4c07a6c63169735efbd1e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Rahul Upadhyay"},"url":"https:\/\/webkul.com\/blog\/author\/rahulkumar-upadhyay671\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/115201","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/180"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=115201"}],"version-history":[{"count":28,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/115201\/revisions"}],"predecessor-version":[{"id":296528,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/115201\/revisions\/296528"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=115201"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=115201"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=115201"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}