{"id":67,"date":"2025-09-06T09:07:07","date_gmt":"2025-09-06T09:07:07","guid":{"rendered":"https:\/\/blog.kerjarapi.com\/?p=67"},"modified":"2025-09-06T09:07:07","modified_gmt":"2025-09-06T09:07:07","slug":"how-to-parameterize-test-objects-in-katalon-studio","status":"publish","type":"post","link":"https:\/\/blog.kerjarapi.com\/?p=67","title":{"rendered":"How to Parameterize Test Objects in Katalon Studio"},"content":{"rendered":"\n<p>There will come a time when doing automation when we have to parameterize our Test Objects. Either to make our Test Object more flexible or because we want to integrate data into our Test Objects. In this blog I want to share how to create a parameterized Test Object, and how to call the Object in Test Case. This means we can use variables in our Test Object and when we call on the Object, we can throw in the values we want.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create a Parameter in Web Test Object and Calling it in a Test Case<\/h2>\n\n\n\n<p>To create a parameterized Web Test Object, first we need to have selected the web element and save it in the Object Repository folder as a Test Object. For example, in <a href=\"https:\/\/demoqa.com\/webtables\" target=\"_blank\" rel=\"noopener\"><em>this<\/em><\/a> page I have selected the cell \u201cCierra\u201d using XPath:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/div&#91;text()='Cierra']\n<\/code><\/pre>\n\n\n\n<p>And save it in the Object Repository as a Test Object.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"842\" height=\"623\" src=\"https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-13.png\" alt=\"\" class=\"wp-image-68\" srcset=\"https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-13.png 842w, https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-13-300x222.png 300w, https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-13-768x568.png 768w\" sizes=\"auto, (max-width: 842px) 100vw, 842px\" \/><\/figure>\n\n\n\n<p>Now to parameterize this object, we have to modify the XPath and put \u201c${variableName}\u201d on our object. This syntax is important, in case you want to parameterize anything. For example in our case it would be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/div&#91;text()='${CellData}']\n<\/code><\/pre>\n\n\n\n<p>The single quotes mean that the value should be a String, and the name of our variable in this case is \u201cCellData\u201d. Now it\u2019s time to call our object in a Test Case and see if we can give it value and verify if a cell value \u201cCierra\u201d exists. Here\u2019s how to do that, in the Test Case script view:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>WebUI.openBrowser('&lt;https:\/\/demoqa.com\/webtables>')\n\nWebUI.maximizeWindow()\n\nWebUI.verifyElementPresent(findTestObject('Table_Cell', &#91;('CellData') : 'Cierra']), 2)\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"721\" height=\"275\" src=\"https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-1-3.png\" alt=\"\" class=\"wp-image-69\" srcset=\"https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-1-3.png 721w, https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-1-3-300x114.png 300w\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" \/><\/figure>\n\n\n\n<p>In the Test Case, when calling the Test Object, we can throw in the value \u201cCierra\u201d so that it will try to find a cell with the value \u201cCierra\u201d.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example of Integrating Data into a Parameterized Web Test Object<\/h2>\n\n\n\n<p>In a Test Case we can try to declare an Array that has cell data we want to verify. Then make a for loop to loop through our Array and verify if the element is present.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>WebUI.openBrowser('&lt;https:\/\/demoqa.com\/webtables>')\n\nWebUI.maximizeWindow()\n\nString&#91;] CellData= &#91;'Cierra', 'Vega', '39', 'Email', 'cierra@example.com', '10000', 'Insurance']\n\nfor(int i=0; i &lt; CellData.size(); i++) {\n\tWebUI.verifyElementPresent(findTestObject('Table_Cell', &#91;('CellData') : CellData&#91;i]]), 2)\n}\n\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"259\" src=\"https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-2-2-1024x259.png\" alt=\"\" class=\"wp-image-70\" srcset=\"https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-2-2-1024x259.png 1024w, https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-2-2-300x76.png 300w, https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-2-2-768x194.png 768w, https:\/\/blog.kerjarapi.com\/wp-content\/uploads\/2025\/09\/image-2-2.png 1390w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>From this example, we can see how flexible it is to use a parameterized test object with for loops, if statements, or other data we want to implement. Even though this example is pretty basic, I hope it can help you tackle a more advanced challenge.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Have More Than One Parameter in a Test Object<\/h2>\n\n\n\n<p>What if we want to have more than one parameter in our Test Object? We can certainly do that in Katalon Studio. For example for this XPath below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/div&#91;@class='rt-td' and text()='Cierra']\n<\/code><\/pre>\n\n\n\n<p>We can parameterize it by switching the values into \u201c${variableName}\u201d, so this turns into:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/div&#91;@class='${className}' and text()='${CellData}']\n<\/code><\/pre>\n\n\n\n<p>To call this Test Object in our Test Case, we should throw in two variables. Example of doing that, we can do:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>WebUI.verifyElementPresent(findTestObject('Table_Cell', &#91;('className') : 'rt-td', ('CellData') : 'Cierra']), 2)<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There will come a time when doing automation when we have to parameterize our Test Objects. Either to make our Test Object more flexible or because we want to integrate data into our Test Objects. In this blog I want to share how to create a parameterized Test Object, and how to call the Object [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,7],"tags":[],"class_list":["post-67","post","type-post","status-publish","format-standard","hentry","category-en","category-katalon-auto"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/blog.kerjarapi.com\/index.php?rest_route=\/wp\/v2\/posts\/67","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kerjarapi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kerjarapi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kerjarapi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kerjarapi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=67"}],"version-history":[{"count":1,"href":"https:\/\/blog.kerjarapi.com\/index.php?rest_route=\/wp\/v2\/posts\/67\/revisions"}],"predecessor-version":[{"id":71,"href":"https:\/\/blog.kerjarapi.com\/index.php?rest_route=\/wp\/v2\/posts\/67\/revisions\/71"}],"wp:attachment":[{"href":"https:\/\/blog.kerjarapi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=67"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kerjarapi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=67"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kerjarapi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=67"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}