PageSourceSearch

https://docs-production-katalon.netlify.app/assets/js/a896fede.2e0b4dba.js

js docs-production-katalon.netlify.app collected 2026-10-03 10:40:26 UTC 25,752 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkKatalon_Docs=self.webpackChunkKatalon_Docs||[]).push([[2619],{28453:(e,n,t)=>{t.d(n,{R:()=>r,x:()=>o});var s=t(96540);const i={},a=s.createContext(i);function r(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),s.createElement(a.Provider,{value:n},e.children)}},39214:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>l,contentTitle:()=>o,default:()=>h,frontMatter:()=>r,metadata:()=>s,toc:()=>c});const s=JSON.parse('{"id":"bdd-testing/work-with-bdd-feature-files-in-katalon-studio","title":"Work with BDD feature files in Katalon Studio","description":"Learn how to work with BDD feature files in Katalon Studio.","source":"@site/docs/katalon-studio/bdd-testing/work-with-bdd-feature-files-in-katalon-studio.md","sourceDirName":"bdd-testing","slug":"/bdd-testing/work-with-bdd-feature-files-in-katalon-studio","permalink":"/katalon-studio/bdd-testing/work-with-bdd-feature-files-in-katalon-studio","draft":false,"unlisted":false,"tags":[],"version":"current","lastUpdatedAt":1783306975000,"frontMatter":{"title":"Work with BDD feature files in Katalon Studio"},"sidebar":"katalon-studio","previous":{"title":"Create BDD test cases in Katalon Studio","permalink":"/katalon-studio/bdd-testing/create-bdd-test-cases-in-katalon-studio"},"next":{"title":"Rerun failed scenarios","permalink":"/katalon-studio/bdd-testing/rerun-failed-scenarios"}}');var i=t(74848),a=t(28453);const r={title:"Work with BDD feature files in Katalon Studio"},o=void 0,l={},c=[{value:"Add feature files",id:"add-feature-files",level:2},{value:"Maintain feature files",id:"maintain-feature-files",level:2},{value:"Define steps",id:"define-steps",level:2},{value:"Step definitions",id:"step-definitions",level:3},{value:"How to define steps",id:"how-to-define-steps",level:4},{value:"Set the default package for step definitions",id:"set-the-default-package-for-step-definitions",level:3},{value:"Best Practices for Handling Glue",id:"best-practices-for-handling-glue",level:3},{value:"Run feature files",id:"run-feature-files",level:2},{value:"Set up Cucumber hooks",id:"set-up-cucumber-hooks",level:2},{value:"Create Cucumber feature files",id:"create-cucumber-feature-files",level:3},{value:"Add Cucumber hooks",id:"add-cucumber-hooks",level:3}];function d(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",h4:"h4",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,a.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(n.p,{children:["Learn how to work with BDD feature files in ",(0,i.jsx)(n.strong,{children:"Katalon Studio"}),"."]}),"\n",(0,i.jsx)(n.h2,{id:"add-feature-files",children:"Add feature files"}),"\n",(0,i.jsxs)(n.p,{children:["This section shows you how to add feature files in ",(0,i.jsx)(n.strong,{children:"Katalon Studio"}),". Steps in the scenario will then be defined by step definitions."]}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["In ",(0,i.jsx)(n.strong,{children:"Katalon Studio"}),", open a Katalon project. Then, navigate to ",(0,i.jsx)(n.strong,{children:"Test Explorer > Include > features"}),". Right-click on the features folder and choose ",(0,i.jsx)(n.strong,{children:"New Feature File"}),"."]}),"\n"]}),"\n",(0,i.jsx)("img",{alt:"create new feature file",src:"/96273b70-22b2-11ed-9930-0242fe3e4a3f/ks-840-create-new-feature-file.png",width:"500px"}),"\n",(0,i.jsxs)(n.ol,{start:"2",children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:"The New Feature File"})," dialog appears. Give your feature file a name. You may also choose to ",(0,i.jsx)(n.strong,{children:"Generate sample Feature template"}),". This option ensures that the created feature file matches with BDD convention."]}),"\n"]}),"\n",(0,i.jsx)("img",{alt:"new feature file",src:"/96223260-22b2-11ed-9930-0242fe3e4a3f/ks-840-new-feature-file.png",width:"300px"}),"\n",(0,i.jsx)(n.p,{children:"A new feature file is created."}),"\n",(0,i.jsx)("img",{alt:"new feature file",src:"/961f7340-22b2-11ed-9930-0242fe3e4a3f/ks-840-new-feature-file-sample.png",width:"500px"}),"\n",(0,i.jsxs)(n.ol,{start:"3",children:["\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Add your scenarios to the feature file following the sample format:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"Feature"}),": List of scenarios."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"Scenario"}),": Business rule through list of steps with arguments."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"Scenario Outline"}),": Used where test data is replaced with multiple sets of data for each run of a test script."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"Given"}),": Precondition step."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"When"}),": Key actions."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"The
1n"}),": Observe outcomes or validation."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"And"}),", But: Enumerate more ",(0,i.jsx)(n.strong,{children:"Given, When, Then"})," steps."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"Background"}),": List of steps run before each of the scenarios."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"Examples"}),": Container for data set."]}),"\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.code,{children:"Tags/ Labels"}),": To group relevant scenarios. Using tags is a good way to organize features and scenarios. A feature or scenario may have multiple tags."]}),"\n"]}),"\n"]}),"\n"]}),"\n",(0,i.jsxs)(n.p,{children:["For example, to test the Login feature of the ",(0,i.jsx)(n.strong,{children:"Katalon Demo Cura System"})," (",(0,i.jsx)(n.code,{children:"[https://katalon-demo-cura.herokuapp.com/](https://katalon-demo-cura.herokuapp.com/)"}),"), there are two scenario outlines: login with a valid credential, and login with an invalid credential. In each scenario, there are specific ",(0,i.jsx)(n.strong,{children:"Given, When, Then"})," steps as shown below:"]}),"\n",(0,i.jsx)("img",{alt:"log in feature file",src:"/96219620-22b2-11ed-9930-0242fe3e4a3f/ks-840-login-feature-file.png",width:"500px"}),"\n",(0,i.jsx)(n.p,{children:(0,i.jsx)(n.strong,{children:"Sample Feature File Script:"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:'#Author: [[email protected]](mailto:[email protected])\n#Keywords Summary :\n#Feature: List of scenarios.\n#Scenario: Business rule through list of steps with arguments.\n#Given: Some precondition step\n#When: Some key actions\n#Then: To observe outcomes or validation\n#And,But: To enumerate more Given,When,Then steps\n#Scenario Outline: List of steps for data-driven as an Examples and <placeholder>
1\n#Examples: Container for s table\n#Background: List of steps run before each of the scenarios\n#""" (Doc Strings)\n#| (Data Tables)\n#@ (Tags/Labels):To group Scenarios\n#<> (placeholder)\n#""\n## (Comments)\n#Sample Feature Definition Template\n@Login\nFeature: Login Feature\n\n  As a user, I want to login to Cura System\n  so that I can make an appointment.\n\n  @Valid\n  Scenario Outline: Login with a valid credential\n    Given I navigate to Cura System homepage\n    When I click Make Appointment button\n    And I enter username <username> and password <password>\n    And I click Log in button\n    Then I should be able to login successfully\n\n    Examples:\n      | username | password           |\n      | John Doe | ThisIsNotAPassword |\n\n  @InValid\n  Scenario Outline: Login with an invalid credential\n    Given I navigate to Cura System homepage\n    When I click Make Appointment button\n    And I enter an invalid username <username> and password <password>\n    And I click Log in button\n    Then I should NOT be able to login successfully\n\n    Examples:\n      | username | password           |\n      | Jane Doe | ThisIsNotAPassword |\n'})}),"\n",(0,i.jsx)(n.h2,{id:"maintain-feature-files",children:"Maintain feature files"}),"\n",(0,i.jsx)(n.admonition,{type:"note",children:(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:[(0,i.jsx)(n.strong,{children:"Katalon Studio"})," code inspection can detect and highlight any missing step definitions in the feature file to help you create the required step definitions."]}),"\n"]})}),"\n",(0,i.jsx)(n.p,{children:"For better management, organize your feature files with a multi-level system. A feature file can contain many scenarios, however, it's recommended you have one scenario per feature file for easy maintenance."}),"\n",(0,i.jsxs)(n.p,{children:["In ",(0,i.jsx)(n.strong,{children:"Katalon Studio"}),", there are three options to help you maintain the feature file. Right-click anywhere in the feature file editor view and choose from the following options:"]}),"\n",(0,i.jsx)("img",{alt:"feature file editor view in **Katalon Studio**",src:"/1235f3a0-c155-11ed-a4d3-0242cfbc79b5/ks-maintain-feature-file.png",width:"500px"}),"\n",(0,i.jsxs)(n.table,{children:[(0,i.jsx)(n.thead,{children:(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.th,{children:"Option"}),(0,i.jsx)(n.th,{children:"Description"})]})}),(0,i.jsxs)(n.tbody,{children:[(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:"Pretty Format"}),(0,i.jsx)(n.td,{children:"Re-do the format when the current format is not organized properly."})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:"Find Step"}),(0,i.jsx)(n.td,{children:"Find relevant step of current Gherkin step in existing Step Definitions files."})]}),(0,i.jsxs)(n.tr,{children:[(0,i.jsx)(n.td,{children:"Recalculate steps"}),(0,i.jsx)(n.td,{children:"Recalculate steps in the feature file when there are changes in Step Definitions."})]})]})]}),"\n",(0,i.jsx)(n.h2,{id:"define-steps",children:"Define steps"}),"\n",(0,i.jsx)(n.h3,{id:"step-definitions",children:"Step definitions"}),"\n",(0,i.jsx)(n.p,{children:"After you added your feature files, you need to define and link steps before using the feature files."}),"\n",(0,i.jsxs)(n.p,{children:["Each Gherkin step in the feature files needs to be defined as a set of programming code so that ",(0,i.jsx)(n.strong,{children:"Katalon Studio"})," can execute the action of that step. These step definitions can be implemented in the ",(0,i.jsx)(n.strong,{children:"Keyword"})," folder by leveraging the ",(0,i.jsx)(n.strong,{children:"Script Mode"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.strong,{children:"Katalon Studio"})," built-in keywords can also be re-used in ",(0,i.jsx)(n.strong,{children:"Step Definition"})," files as well. When ",(0,i.jsx)(n.strong,{children:"Katalon Studio"})," executes any feature files in a test case, it also looks for the matching step definitions in the source folder."]}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.strong,{children:"Step Definitions"})," can be written in any Cucumber-supported programming languages, including Groovy and Java."]}),"\n",(0,i.jsx)(n.p,{children:"For example, for two scenario outlines (Login with a valid credential and login with an invali
1d credential), there are six (6) steps defined as shown below:"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:["Given I navigate to ",(0,i.jsx)(n.strong,{children:"Cura System"})," homepage"]}),"\n",(0,i.jsxs)(n.li,{children:["When I click ",(0,i.jsx)(n.strong,{children:"Make Appointment"})," button"]}),"\n",(0,i.jsxs)(n.li,{children:["And I enter username ",(0,i.jsx)(n.code,{children:"<username>"})," and password ",(0,i.jsx)(n.code,{children:"<password>"})]}),"\n",(0,i.jsxs)(n.li,{children:["And I click ",(0,i.jsx)(n.strong,{children:"Log in"})," button"]}),"\n",(0,i.jsx)(n.li,{children:"Then I should be able to login successfully"}),"\n",(0,i.jsx)(n.li,{children:"Then I should NOT be able to login successfully"}),"\n"]}),"\n",(0,i.jsx)("img",{alt:"step definition",src:"/96253fa0-22b2-11ed-9930-0242fe3e4a3f/ks-840-step-definition.png",width:"500px"}),"\n",(0,i.jsx)(n.p,{children:(0,i.jsx)(n.strong,{children:"Step Definitions Sample Script"})}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:'class MyStepDefinition {\n\n    /**\n     * The step definitions below match with Katalon sample Gherkin steps\n    **/\n\n    @Given("I navigate to Cura System homepage")\n    def I_navigate_to_Cura_System_homepage() {\n\n        WebUI.openBrowser("https://katalon-demo-cura.herokuapp.com/"){"\\n"}{"        "}//WebUI.waitForPageLoad(30)\n    }\n\n    @When("I click Make Appointment button")\n    def I_click_makeAppointment_button() {\n\n        WebUI.click(findTestObject(\'Page_CURA Healthcare Service/a_Make Appointment\'))\n    }\n\n    @And("I enter username (.) and password (.)")\n    def I_enter_valid_username_password(String username, String password) {\n\n        WebUI.setText(findTestObject(\'Page_CURA Healthcare Service/input_userName\'), username)\n        WebUI.setText(findTestObject(\'Page_CURA Healthcare Service/input_password\'), password)\n    }\n\n    @And("I click Log in button")\n    def I_click_login_btn() {\n\n        WebUI.click(findTestObject(\'Page_CURA Healthcare Service/button_Login\'))\n    }\n\n    @Then("I should be able to login successfully")\n    def I_login_successfully() {\n\n        WebUI.click(findTestObject(\'Page_CURA Healthcare Service/button_Login\'))\n        WebUI.verifyTextPresent(\'Make Appointment\', false)\n        WebUI.closeBrowser()\n    }\n\n    @And("I enter an invalid username (.) and password (.*)")\n    def I_enter_invalid_username_password(String username, String password) {\n\n        WebUI.setText(findTestObject(\'Page_CURA Healthcare Service/input_userName\'), username)\n        WebUI.setText(findTestObject(\'Page_CURA Healthcare Service/input_password\'), password)\n    }\n\n\n    @Then("I should NOT be able to login successfully")\n    def I_login_unsuccessfully() {\n\n        WebUI.verifyTextPresent(\'Login failed! Please ensure the username and password are valid.\', false)\n        WebUI.closeBrowser()\n    }\n\n}\n\n'})}),"\n",(0,i.jsx)(n.h4,{id:"how-to-define-steps",children:"How to define steps"}),"\n",(0,i.jsx)(n.p,{children:"Steps in the feature files must be defined before use."}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["In ",(0,i.jsx)(n.strong,{children:"Test Explorer"}),", navigate to the Include/scripts/groovy folder and create a sub-package. Then, right-click on the newly created package and choose ",(0,i.jsx)(n.strong,{children:"New > Step Definition"}),"."]}),"\n",(0,i.jsxs)(n.li,{children:["In the displayed Keyword dialog, choose your ",(0,i.jsx)(n.strong,{children:"Package"}),", then enter your ",(0,i.jsx)(n.strong,{children:"Class Name"}),". You can also enable the option to Generate sample ",(0,i.jsx)(n.code,{children:"@Given"}),", ",(0,i.jsx)(n.code,{children:"@When"}),", ",(0,i.jsx)(n.code,{children:"@Then"})," steps."]}),"\n"]}),"\n",(0,i.jsx)("img",{alt:"keyword",src:"/96262a00-22b2-11ed-9930-0242fe3e4a3f/ks-840-keyword.png",width:"500px"}),"\n",(0,i.jsxs)(n.ol,{start:"3",children:["\n",(0,i.jsxs)(n.li,{children:["Once you are done, click ",(0,i.jsx)(n.strong,{children:"OK"}),"."]}),"\n"]}),"\n",(0,i.jsx)("img",{alt:"new step definition",src:"/96284ce0-22b2-11ed-9930-0242fe3e4a3f/ks-840-new-step-definition.png",width:"500px"}),"\n",(0,i.jsx)(n.h3,{id:"set-the-default-package-for-step-definitions",children:"Set the default package for step definitions"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:["Starting with ",(0,i.jsx)(n.strong,{children:"Katalon Studio"})," 9.0.0 and later, setting the default package for step definitions is required."]}),"\n"]}),"\n",(0,i.jsxs)(n.p,{children:["To help Cucumber locate the step definitions file, you can use the ",(0,i.jsx)(n.code,{children:"CucumberKW.GLUE"})," keyword. The default value of ",(0,i.jsx)(n.code,{children:"CucumberKW.GLUE = ['']"})," is all packages, which means the test engine takes time to scan through all packages. To speed things up, you can specify the package locations, for example, ",(0,i.jsx)(n.code,{children:"CucumberKW.GLUE = ['package1', 'package2']"})," to narrow down where to find the step definitions."]}),"\n",(0,i.jsx)(n.p,{children:"We recommend putting the script declaring the package in a test listener."}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:"import 
1com.kms.katalon.core.annotation.AfterTestCase\nimport com.kms.katalon.core.annotation.BeforeTestCase\nimport com.kms.katalon.core.context.TestCaseContext\nimport com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW\n\nclass NewTestListener {\n    @BeforeTestCase\n    def beforeTestCase(TestCaseContext testCaseContext) {\n        CucumberKW.GLUE = ['package1', 'package2']\n    }\n}\n"})}),"\n",(0,i.jsxs)(n.p,{children:["Starting ",(0,i.jsx)(n.strong,{children:"Katalon Studio"})," 9.0.0 and later, for BDD projects created in version 8.x to work as before, you also need to include the following ",(0,i.jsx)(n.code,{children:"@BeforeTestCase"})," listener:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:"@BeforeTestCase\ndef beforeTestCase(TestCaseContext context) {\n  CucumberGlueGenerator.addDefaultPackages();\n}\n"})}),"\n",(0,i.jsxs)(n.p,{children:["However, if you are using Katalon Runtime Engine to run BDD projects, we recommend that you explicitly specify your step definition packages. See ",(0,i.jsx)(n.a,{href:"#best-practices-for-handling-glue",children:"Best Practices for Handling Glue"})," below for more details."]}),"\n",(0,i.jsx)(n.h3,{id:"best-practices-for-handling-glue",children:"Best Practices for Handling Glue"}),"\n",(0,i.jsxs)(n.ul,{children:["\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"The glue should be assigned to the step definition packages of the feature files, not the packages of the Cucumber runner."}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsxs)(n.p,{children:["If the glue is incorrectly set to the runner package (such as ",(0,i.jsx)(n.code,{children:'glue="com.vv.sailorApp.Runners"'}),"), the test may pass but no steps will be run. To fix this, ensure the glue points to the correct step definition packages, for example:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:"glue = ['com.vv.sailorApp.StepDefinitions', 'otherStepDefinitionPackages']\n"})}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsxs)(n.p,{children:["Make sure all Cucumber hooks, such as ",(0,i.jsx)(n.code,{children:"@Before"})," and ",(0,i.jsx)(n.code,{children:"@After"}),", are placed in the correct step definition folders. For example, move all the hooks from the files ",(0,i.jsx)(n.code,{children:"Test Listeners/SetupTestListener"}),", ",(0,i.jsx)(n.code,{children:"Keywords/com.vv.listener/InitialSetup.groovy"})," to the step definition folders, such as:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:"Include/scripts/groovy/CucumberHooksDefinitions/InitialSetup.groovy\nInclude/scripts/groovy/CucumberHooksDefinitions/SetupTestListener.groovy\n"})}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Add glue to these hooks in your Cucumber runner as well:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:"glue = ['stepDefinitionPackage1', 'Include/scripts/groovy/CucumberHooksDefinitions', 'otherStepDefinitionPackages']\n"})}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"For other Cucumber elements that are not executed via the Cucumber runner, you can add glue in setup steps like this:"}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:"@BeforeTestCase\ndef beforeTestCase(TestCaseContext context) {\nCucumberKW.GLUE = ['<all the step definition packages>']\n}\n"})}),"\n"]}),"\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsxs)(n.p,{children:["When running tests in ",(0,i.jsx)(n.strong,{children:"Katalon Runtime Engine"}),", avoid using ",(0,i.jsx)(n.code,{children:"CucumberGlueGenerator.addDefaultPackages()"})," in ",(0,i.jsx)(n.strong,{children:"Test Listeners"}),"."]}),"\n",(0,i.jsxs)(n.p,{children:["Always specify step definition packages explicitly, as automatic package discovery can cause ",(0,i.jsx)(n.code,{children:"NoClassDefFoundError"})," due to class isolation in ",(0,i.jsx)(n.strong,{children:"Katalon Runtime Engine"}),". For example:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:'@CucumberOptions(glue = "com.yourcompany.steps")\n'})}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(n.h2,{id:"run-feature-files",children:"Run feature files"}),"\n",(0,i.jsxs)(n.p,{children:[(0,i.jsx)(n.strong,{children:"Katalon Studio"})," allows you to run the feature files instantly by itself to make sure it works properly."]}),"\n",(0,i.jsxs)(n.p,{children:["To do so, go to ",(0,i.jsx)(n.strong,{children:"Include > features"})," and open the desired feature file. Click the ",(0,i.jsx)(n.strong,{children:"Run"})," button on the main toolbar, as shown below:"]}),"\n",(0,i.jsx)("img",{alt:"Steprun feature files in **Katalon Studio**.",src:"/84081eb0-be4c-11ed-825f-0242cfbc79b5/run-feature-file.png",width:"500px"}),"\n",(0,i.jsx)(n.h2,{id:"set-up-cucumber-hooks",children:"Set up Cucumber hooks"}),"\n",(0,i.jsx)(n.h3,{id:"create-cucumber-feature-files",children:"Create Cucumber feature files"}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsxs)(n.li,{children:["To create a Cucumber feature file, go to ",(0,i.jsx)(n.strong,{children:"File > New > BDD Feature File"}),"."]}),"\n"]}),"\n",(0,i.jsx)("img",{alt:"new BDD feature file",src:"/96223260-22b2-11ed-9930-0242fe3e4a3f/ks-840-new-feature-file.png",width:"500px"}),"\n",(0,i.jsxs)(n.p,{children:["Tick the ",(0,i.jsx)(n.strong,{children:"Generate sample Feature template"})," option for a sample feature file.The script below is a generated sample feature template:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:"#Sample Feature Definition Template\n@tag\nFeature: Title of your feature\nI want to use this template for my feature file\n\n@tag1\nScenario Outline: Title of your scenario outline\n    Given I want to write a step with <name>\n    When I check for the <value> in step\n    Then I verify the <status> in step\n\n    Examples:\n    | name  | value | status  |\n    | name1 |     5 | success |\n    | name2 |     7 | Fail    |\n"})}),"\n",(0,i.jsxs)(n.ol,{start:"2",children:["\n",(0,i.jsxs)(n.li,{children:["To create step definitions, go to ",(0,i.jsx)(n.strong,{children:"File > New > Groovy Script"}),"."]}),"\n"]}),"\n",(0,i.jsx)("img",{alt:"Create step definition",src:"/11a8ced0-c155-11ed-a4d3-0242cfbc79b5/KS-create-step-defintions.png",width:"500px"}),"\n",(0,i.jsx)(n.admonition,{title:"Attention",type:"tip",children:(0,i.jsx)(n.p,{children:"In previous versions, you can use custom keywords in BDD tests when the step definition belongs to the default package. From version 9.0.0 onwards, you cannot run BD
1D tests with custom keywords. This will be fixed in upcoming releases."})}),"\n",(0,i.jsxs)(n.p,{children:["Tick the ",(0,i.jsx)(n.strong,{children:"Generate sample @Given, @When, @Then steps"})," for sample step definitions.The script below is a generated sample ",(0,i.jsx)(n.code,{children:"@Given"}),", ",(0,i.jsx)(n.code,{children:"@When"}),", ",(0,i.jsx)(n.code,{children:"@Then"})," steps:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:'class Sample {\n\n    /**\n    * The step definitions below match with Katalon sample Gherkin steps\n    */\n    @Given("I want to write a step with (.*)")\n    def I_want_to_write_a_step_with_name(String name) {\n        println name\n    }\n\n    @When("I check for the (\\d+) in step")\n    def I_check_for_the_value_in_step(int value) {\n        println value\n    }\n\n    @Then("I verify the (.*) in step")\n    def I_verify_the_status_in_step(String status) {\n        println status\n    }\n}\n'})}),"\n",(0,i.jsx)(n.h3,{id:"add-cucumber-hooks",children:"Add Cucumber hooks"}),"\n",(0,i.jsxs)(n.ol,{children:["\n",(0,i.jsx)(n.li,{children:"Create another step definition or a custom keyword that includes the Cucumber hooks as shown below:"}),"\n"]}),"\n",(0,i.jsx)("img",{alt:"Step definitions with Cucumber hooks in **Katalon Studio**.",src:"/f7c607b0-51f2-11ee-bc71-0242c7a41fd4/ks-new-cucumber-hooks-script.png",width:"500px"}),"\n",(0,i.jsxs)(n.ol,{start:"2",children:["\n",(0,i.jsxs)(n.li,{children:["\n",(0,i.jsx)(n.p,{children:"Enter Cucumber hooks into the new step definition."}),"\n",(0,i.jsxs)(n.p,{children:["For example, to add ",(0,i.jsx)(n.code,{children:"@Before"})," and ",(0,i.jsx)(n.code,{children:"@After"})," scenario hooks, copy and paste the following script into the feature file:"]}),"\n",(0,i.jsx)(n.pre,{children:(0,i.jsx)(n.code,{className:"language-jsx",children:"class SampleTestHook {\n    @Before\n    public void beforeScenario(Scenario scenario) {\n        println 'This is a before scenario method: ' + scenario.getName()\n    }\n\n    @After\n    public void afterScenario(Scenario scenario) {\n        println 'This is a after scenario method: ' + scenario.getName()\n    }\n}\n"})}),"\n"]}),"\n"]})]})}function h(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,i.jsx)(n,{...e,children:(0,i.jsx)(d,{...e})}):d(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.