PageSourceSearch

https://docs-production-katalon.netlify.app/assets/js/2d4f8bfd.e4716c77.js

js docs-production-katalon.netlify.app collected 2026-10-03 10:39:47 UTC 6,123 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkKatalon_Docs=self.webpackChunkKatalon_Docs||[]).push([[211],{14972:(s,e,t)=>{t.r(e),t.d(e,{assets:()=>l,contentTitle:()=>i,default:()=>m,frontMatter:()=>r,metadata:()=>o,toc:()=>c});const o=JSON.parse('{"id":"keywords/custom-keywords/how-to-use-a-custom-keyword-from-other-custom-keywords-and-step-definition-classes-in-katalon-studio","title":"How to use a custom keyword from other custom keywords and step definition classes in Katalon Studio","description":"Besides built-in keywords, Katalon Studio also allows users to create custom keywords for these purposes:Creating reusable scriptsExtending testing capabilitySetting up testing projects with a specific pattern","source":"@site/docs/katalon-studio/keywords/custom-keywords/how-to-use-a-custom-keyword-from-other-custom-keywords-and-step-definition-classes-in-katalon-studio.md","sourceDirName":"keywords/custom-keywords","slug":"/keywords/custom-keywords/how-to-use-a-custom-keyword-from-other-custom-keywords-and-step-definition-classes-in-katalon-studio","permalink":"/katalon-studio/keywords/custom-keywords/how-to-use-a-custom-keyword-from-other-custom-keywords-and-step-definition-classes-in-katalon-studio","draft":false,"unlisted":false,"tags":[],"version":"current","lastUpdatedAt":1758935351000,"frontMatter":{"title":"How to use a custom keyword from other custom keywords and step definition classes in Katalon Studio"},"sidebar":"katalon-studio","previous":{"title":"How to perform Database Testing using Katalon Studio","permalink":"/katalon-studio/keywords/custom-keywords/how-to-perform-database-testing-using-katalon-studio"},"next":{"title":"Handling drag and drop testing for web applications with Katalon Studio","permalink":"/katalon-studio/keywords/custom-keywords/handling-drag-and-drop-testing-for-web-applications-with-katalon-studio"}}');var a=t(74848),n=t(28453);const r={title:"How to use a custom keyword from other custom keywords and step definition classes in Katalon Studio"},i=void 0,l={},c=[];function d(s){const e={code:"code",li:"li",p:"p",pre:"pre",ul:"ul",...(0,n.R)(),...s.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:["Besides built-in keywords, Katalon Studio also allows users to create custom keywords for these purposes:",(0,a.jsxs)("ul",{className:"ul",children:[(0,a.jsx)("li",{className:"li",children:(0,a.jsx)("p",{className:"p",children:"Creating reusable scripts"})}),(0,a.jsx)("li",{className:"li",children:(0,a.jsx)("p",{className:"p",children:"Extending testing capability"})}),(0,a.jsx)("li",{className:"li",children:(0,a.jsx)("p",{className:"p",children:"Setting up testing projects with a specific pattern"})})]})," "]}),"\n",(0,a.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"Initially, custom keywords are designed use in test cases. Combined with built-in keywords, custom keywords can help perform a complete test scenario."}),"\n",(0,a.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"Here is an example of a custom keyword, which prints out a parameter."}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsx)(e.code,{className:"language-jsx",children:"class ParamTypes {\n  @Keyword\n  def map_variables(Map <String, String> my_map) {\n    println my_map\n  }\n}\n"})}),"\n",(0,a.jsxs)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:["The keyword can be used in a test case via ",(0,a.jsx)("strong",{className:"ph b",children:"CustomKeywords"})," class"]}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsx)(e.code,{className:"language-jsx",children:"CustomKeywords.'ParamTypes.map_variables'([('last name') : 'smith', ('first name') : 'john'])\n"})}),"\n",(0,a.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"In Katalon Studio, the test case Script is not the only place that allows users to script. Users can script at the custom keyword class and the BDD step definition class. Unfortunately, you will get the following error message when calling the custom keyword in these classes:"}),"\n",(0,a.jsx)("pre",{xmlns:"http://www.w3.org/1999/xhtml",className:"pre codeblock",children:(0,a.jsxs)("code",{children:["Test Cases/Tips and Tricks/Custom Keywords/Params - Map FAILED because (of) (Stack trace: ","\n","groovy.lang.MissingPropertyException: No such property: CustomKeywords for class: com.common.types.ParamTypes","\n"]})}),"\n",(0,a.jsx)(e.p,{children:"In the custom keyword class and the BDD step definition class, custom keywords cannot be called directly as in test case via CustomKeywords class. They can be called as methods of a groovy class. Here are two options you can choose to get it work:"}),"\n",(0,a.jsxs)(e.ul,{children:["\n",(0,a.jsx)(e.li,{children:"Option 1: Create a new instance of the class and call the method"}),"\n"]}),"\n",(0,a.jsx)(e.pre,{children:(0,a.jsx)(e.code,{className:"language-jsx",children:"def param_types = new ParamTypes()\nparam_types.map_variables([('last name') : 'smith', ('first name') : 'john'])\n"})}),"\n",(0,a.jsxs)(e.ul,{children:["\n",(0,a.jsxs)(e.li,{children:["Option 2: Declare the custom keyword as static","\n",(0,a.jsx)(e.pre,{children:(0,a.jsx)(e.code,{className:"language-jsx",children:"class ParamTypes {\n  @Keyword\n  def static map_variables(Map <String, String> my_map) {\n    println my_map\n  }\n}\n"})}),"\n","and call the method","\n",(0,a.jsx)(e.pre,{children:(0,a.jsx)(e.code,{className:"language-jsx",children:"ParamTypes.map_variables([('last name') : 'smith', ('first name') : 'john'])\n"})}),"\n"]}),"\n"]})]})}function m(s={}){const{wrapper:e}={...(0,n.R)(),...s.components};return e?(0,a.jsx)(e,{...s,children:(0,a.jsx)(d,{...s})}):d(s)}},28453:(s,e,t)=>{t.d(e,{R:()=>r,x:()=>i});var o=t(96540);const a={},n=o.createContext(a);function r(s){const e=o.useContext(n);return o.useMemo((function(){return"function"==typeof s?s(e):{...e,...s}}),[e,s])}function i(s){let e;return e=s.disableParentContext?"function"==typeof s.components?s.components(a):s.components||a:r(s.components),o.createElement(n.Provider,{value:e},s.children)}}}]);

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.