PageSourceSearch

https://docs-production-katalon.netlify.app/assets/js/2282ad7b.cb1828b6.js

js docs-production-katalon.netlify.app collected 2026-10-03 10:40:55 UTC 19,203 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkKatalon_Docs=self.webpackChunkKatalon_Docs||[]).push([[4989],{10192:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>c,default:()=>p,frontMatter:()=>l,metadata:()=>a,toc:()=>d});const a=JSON.parse('{"id":"data-driven-testing/data-driven-testing-with-restful-web-service-requests","title":"Data-driven testing with RESTful Web Service requests","description":"Katalon Studio allows you to perform data-driven testing (DDT) with Web Service Objects.","source":"@site/docs/katalon-studio/data-driven-testing/data-driven-testing-with-restful-web-service-requests.md","sourceDirName":"data-driven-testing","slug":"/data-driven-testing/data-driven-testing-with-restful-web-service-requests","permalink":"/katalon-studio/data-driven-testing/data-driven-testing-with-restful-web-service-requests","draft":false,"unlisted":false,"tags":[],"version":"current","lastUpdatedAt":1763948956000,"frontMatter":{"title":"Data-driven testing with RESTful Web Service requests"},"sidebar":"katalon-studio","previous":{"title":"Specify iteration names in data-driven testing reports","permalink":"/katalon-studio/data-driven-testing/specify-iteration-names-in-data-driven-testing-reports"},"next":{"title":"Configure database connection for data-driven testing in Katalon Studio","permalink":"/katalon-studio/data-driven-testing/configure-database-connection-for-data-driven-testing-in-katalon-studio"}}');var i=t(74848),r=t(28453),n=t(86025);const l={title:"Data-driven testing with RESTful Web Service requests"},c=void 0,o={},d=[{value:'<a class="anchor_top_offset"></a>Create Web Service request objects with variables',id:"create-web-service-request-objects-with-variables",level:2},{value:'<a class="anchor_top_offset"></a>Create a POST request with variables',id:"create-a-post-request-with-variables",level:3},{value:'<a class="anchor_top_offset"></a>Create a GET request with variables',id:"create-a-get-request-with-variables",level:3},{value:'<a class="anchor_top_offset"></a>Create a test case with associated Web Service requests',id:"create-a-test-case-with-associated-web-service-requests",level:2},{value:'<a class="anchor_top_offset"></a>Bind data in the test suite',id:"bind-data-in-the-test-suite",level:2}];function h(e){const s={a:"a",h2:"h2",h3:"h3",...(0,r.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"Katalon Studio allows you to perform data-driven testing (DDT) with Web Service Objects."}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"This tutorial shows you how to create Web Service requests and test cases with variables, then bind data files to the associated request objects and test cases."}),"\n",(0,i.jsxs)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:["You can download the sample project here: ",(0,i.jsx)("a",{className:"xref j-external-link",href:"https://github.com/katalon-studio-samples/web-service-tests",target:"_blank",children:"Web Service Tests"}),"."]}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"In our example, we want to send the user information with dynamic data, including username, password, age, gender, and avatar to the server to create an account, then receive a user ID as the response. After creating the new user, we will find that user by the user ID."}),"\n",(0,i.jsxs)(s.h2,{id:"create-web-service-request-objects-with-variables",children:[(0,i.jsx)("a",{id:"id_1",class:"anchor_top_offset"}),"Create Web Service request objects with variables"]}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"Here we need to create two RESTful requests with variables:"}),"\n",(0,i.jsxs)("ul",{xmlns:"http://www.w3.org/1999/xhtml",className:"ul",children:["   ",(0,i.jsx)("li",{className:"li",children:"A POST request with variables to register a new user."}),"   ",(0,i.jsx)("li",{className:"li",children:"A GET request with variables to get a user by ID."})," "]}),"\n",(0,i.jsxs)(s.h3,{id:"create-a-post-request-with-variables",children:[(0,i.jsx)("a",{id:"id_2",class:"anchor_top_offset"}),"Create a POST request with variables"]}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"We use the POST request to send the user information, including username, password, age, gender, and avatar to the server to create an account, then expect a user ID as the response."}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"Follow these steps to create and configure the POST request:"}),"\n",(0,i.jsxs)("ol",{xmlns:"http://www.w3.org/1999/xhtml",className:"ol",children:[(0,i.jsxs)("li",{className:"li",children:[(0,i.jsxs)("p",{className:"p",children:["Create a Web Service request. From the main menu, select ",(0,i.jsx)("strong",{className:"ph b",children:"File > New > Web Service Request"}),". In the displayed ",(0,i.jsx)("strong",{className:"ph b",children:"New"})," dialog, name the request and specify the request type as ",(0,i.jsx)("strong",{className:"ph b",children:"RESTful"})," request."]}),(0,i.jsxs)("p",{className:"p",children:[(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-new-web-request-POST.png"),alt:"New Web request dialog"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]})]}),(0,i.jsxs)("li",{className:"li",children:[(0,i.jsxs)("p",{className:"p",children:["Specify the API endpoint. In our example, the API endpoint is ",(0,i.jsx)("code",{className:"ph codeph",children:(0,i.jsx)(s.a,{href:"https://sample-web-service-aut.herokuapp.com/api/users/json",children:"https://sample-web-service-aut.herokuapp.com/api/users/json"})}),"."]}),(0,i.jsxs)("p",{className:"p",children:[(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-New-POST-API-endpoint.png"),alt:"POST request API endpoint"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]}),(0,i.jsxs)("p",{className:"p",children:["To learn more about API endpoint management, refer to this document: ",(0,i.jsx)("a",{className:"xref",href:"/katalon-studio/get-started/supported-applications-under-test-aut/introduction-to-api-testing-in-katalon-studio#api-testing-best-practices",children:"API testing best practices"}),"."]})]}),(0,i.jsxs)("li",{className:"li",children:[(0,i.jsxs)("p",{className:"p",children:["In the ",(0,i.jsx)("strong",{className:"ph b",children:"Variables"})," tab, input ",(0,i.jsx)("code",{className:"ph codeph",children:"username"}),", ",(0,i.jsx)("code",{className:"ph codeph",children:"password"}),", ",(0,i.jsx)("code",{className:"ph codeph",children:"gender"}),", ",(0,i.jsx)("code",{className:"ph codeph",children:"age"}),", and ",(0,i.jsx)("code",{className:"ph codeph",children:"avatar"})," variables."]}),(0,i.jsxs)("p",{className:"p",children:[(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-POST-request-variable-tab.png"),alt:"POST Variables tab"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]})]}),(0,i.jsxs)("li",{className:"li",children:[(0,i.jsxs)("p",{className:"p",children:["To call a variable in a Web Service object, use the ",(0,i.jsxs)("code",{className:"ph codeph",children:["$","{","<variable_name>","}"]})," syntax as a placeholder in any of the supported locations."]}),(0,i.jsxs)("p",{className:"p",children:["Here we use the syntax to specify the variables in the ",(0,i.jsx)("strong",{className:"ph b",children:"HTTP Body"})," tab."]}),(0,i.jsxs)("p",{className:"p",children:[(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-POST-request-HTTP-body.png"),alt:"HTTP Body tab"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]})]})]}),"\n",(0,i.jsxs)(s.h3,{id:"create-a-get-request-with-variables",children:[(0,i.jsx)("a",{id:"id_3",class:"anchor_top_offset"}),"Create a GET request with variables"]}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"Next, we use the GET request to find a user by ID. We expect the server to return the user information, including username, password, gender, age, and avatar in the response."}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"Follow these steps to configure the GET request:"}),"\n",(0,i.jsxs)("ol",{xmlns:"http://www.w3.org/1999/xhtml",className:"ol",children:[(0,i.jsxs)("li",{className:"li",children:["     ",(0,i.jsxs)("p",{className:"p",children:["Create a Web Service request. From the main menu, select ",(0,i.jsx)("strong",{className:"ph b",children:"File > New > Web Service Request"}),". In the displayed ",(0,i.jsx)("strong",{className:"ph b",children:"New"})," dialog, name the request and specify the request type as ",(0,i.jsx)("strong",{className:"ph b",children:"RESTful"})," request."]}),"     ",(0,i.jsxs)("p",{className:"p",children:[" ",(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-new-web-request-GET.png"),alt:"New Web request dialog"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{}),"     "]}),"   "]}),(0,i.jsxs)("li",{className:"li",children:["     ",(0,i.jsxs)("p",{className:"p",children:["Specify the API endpoint. Our API endpoint for the GET request is ",(0,i.jsx)("code",{className:"ph codeph",children:(0,i.jsx)(s.a,{href:"https://sample-web-service-aut.herokuapp.com/api/users/",children:"https://sample-web-service-aut.herokuapp.com/api/users/"})}),"."]}),"   "]}),(0,i.jsxs)("li",{className:"li",children:["     ",(0,i.jsxs)("p",{className:"p",children:["To pass a variable to the GET API, add the ",(0,i.jsxs)("code",{className:"ph codeph",children:["$","{","<variable_name>","}"]})," placeholder at the end of the API endpoint."]}),"     ",(0,i.jsxs)("p",{className:"p",children:["Here we specify the ",(0,i.jsx)("code",{className:"ph codeph",children:"id"})," variable using the ",(0,i.jsxs)("code",{className:"ph codeph",children:["$","{","id","}"]})," syntax as follows: ",(0,i.jsx)("code",{className:"ph codeph",children:(0,i.jsx)(s.a,{href:"https://sample-web-service-aut.herokuapp.com/api/users/$%7B'%7B'%7Did%7B'%7D'%7D",children:"https://sample-web-service-aut.herokuapp.com/api/users/${'{'}id{'}'}"})}),"."]}),"   "]}),(0,i.jsxs)("li",{className:"li",children:["     ",(0,i.jsxs)("p",{className:"p",children:["In the ",(0,i.jsx)("strong",{className:"ph b",children:"Variables"})," tab, input the ",(0,i.jsx)("code",{className:"ph codeph",children:"id"})," variable."]}),"     ",(0,i.jsxs)("p",{className:"p",children:[" ",(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-GET-request-object-config.png"),alt:"GET request variables tab"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{}),"     "]}),"   "]})]}),"\n",(0,i.jsxs)(s.h2,{id:"create-a-test-case-with-associated-web-service-requests",children:[(0,i.jsx)("a",{id:"id_4",class:"anchor_top_offset"}),"Create a test case with associated Web Service requests"]}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"After creating two RESTful Web Service requests with variables, we create a test case to send the POST request to register a new user and extract the user ID from the response. With the returned user ID, we send the GET request to retrieve user information and verify it."}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"Follow these steps to set up the test case:"}),"\n",(0,i.jsxs)("ol",{xmlns:"http://www.w3.org/1999/xhtml",className:"ol",children:[(0,i.jsxs)("li",{className:"li",children:["     ",(0,i.jsxs)("p",{className:"p",children:["Open a new test case. In the ",(0,i.jsx)("strong",{className:"ph b",children:"Script"})," tab, enter the following code snippet to set up the test case:"]}),"     ",(0,i.jsx)("pre",{className:"pre codeblock",children:(0,i.jsxs)("code",{children:["// Send a POST request to create a new user","\n","// The response contains the id of the newly created user","\n","post_response = WS.sendRequest(findTestObject('POST a new user', [('username') : username, ('password') : password, ('gender') : gender, ('age') : age]))","\n","\n","// Extract the id value from the response","\n","user_id = WS.getElementPropertyValue(post_response, 'id')","\n",'println("ID of user " + username + ": " + user_id.toString())',"\n","\n","// Send a GET request to retrieve user information by id","\n","get_response = WS.sendRequest(findTestObject('GET user by id', ['id' : user_id]))","\n",'println("The response is: " + get_response.getResponseText())',"\n","\n","// Verify that the returned values match the user information","\n","WS.verifyElementPropertyValue(get_response, 'username', username)","\n","WS.verifyElementPropertyValue(get_response, 'password', password)","\n","\n"]})}),"   "]}),(0,i.jsxs)("li",{className:"li",children:["     ",(0,i.jsxs)("p",{className:"p",children:["To input variables into the test case, switch to the ",(0,i.jsx)("strong",{className:"ph b",children:"Variables"})," tab and pass the variables defined in the POST request object."]}),"     ",(0,i.jsxs)("p",{className:"p",children:["Here, we specify the ",(0,i.jsx)("code",{className:"ph codeph",children:"username"}),", ",(0,i.jsx)("code",{className:"ph codeph",children:"password"}),", ",(0,i.jsx)("code",{className:"ph codeph",children:"gender"}),", ",(0,i.jsx)("code",{className:"ph codeph",children:"age"}),", and ",(0,i.jsx)("code",{className:"ph codeph",children:"avatar"})," variables."]}),"     ",(0,i.jsxs)("p",{className:"p",children:[" ",(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("/99077800-22b2-11ed-9930-0242fe3e4a3f/KS-830-Tc-variables.png")})]}),"   "]}),(0,i.jsxs)("li",{className:"li",children:["     ",(0,i.jsxs)("p",{className:"p",children:["Run the test case and verify the test message in the ",(0,i.jsx)("strong",{className:"ph b",children:"Console"})," log:"]}),"     ",(0,i.jsxs)("p",{className:"p",children:[" ",(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-Console-log-test-case-result.png"),alt:"Test case run result"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{}),"     "]}),"   "]})]}),"\n",(0,i.jsxs)(s.h2,{id:"bind-data-in-the-test-suite",children:[(0,i.jsx)("a",{id:"id_5",class:"anchor_top_offset"}),"Bind data in the test suite"]}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"After configuring the test case with associated Web Service requests, we bind the test case to the test data in a test suite."}),"\n",(0,i.jsx)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:"Follow these steps:"}),"\n",(0,i.jsxs)("ol",{xmlns:"http://www.w3.org/1999/xhtml",className:"ol",children:[(0,i.jsxs)("li",{className:"li",children:[(0,i.jsxs)("p",{className:"p",children:["To create a test data file, from the main menu, select ",(0,i.jsx)("strong",{className:"ph b",children:"New > File > Test Data"}),". In the displayed dialog, name the test data file and specify the data type."]}),(0,i.jsxs)("p",{className:"p",children:[(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-New-Test-Data-dialog.png"),alt:"New Test Data dialog"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]}),(0,i.jsx)("p",{className:"p",children:"In our example, we use an Excel file that contains user information."}),(0,i.jsxs)("p",{className:"p",children:[(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-Test-Data-User-Information-Table.png"),alt:"Test Data table of user information"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]})]}),(0,i.jsxs)("li",{className:"li",children:[(0,i.jsxs)("p",{className:"p",children:["Open a new test suite, click on the ",(0,i.jsx)("strong",{className:"ph b",children:"Add"})," button and include the associated test case."]}),(0,i.jsxs)("p",{className:"p",children:[(0,i.jsx)("img",{className:"image",src:(0,n.
1Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-Test-Suite-add-test-case.png"),alt:"Test Data table of user information"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]})]}),(0,i.jsxs)("li",{className:"li",children:[(0,i.jsxs)("p",{className:"p",children:["To open the ",(0,i.jsx)("strong",{className:"ph b",children:"Data Binding"})," section, click on the ",(0,i.jsx)("strong",{className:"ph b",children:"Show Data Binding"})," button."]}),(0,i.jsxs)("p",{className:"p",children:[(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-Test-Suite-Show-Data-Binding.png"),alt:"Test Data table of user information"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]})]}),(0,i.jsxs)("li",{className:"li",children:[(0,i.jsxs)("p",{className:"p",children:["You need to specify the test data file and configure the variable binding. Follow the steps in this guide to configure the binding: ",(0,i.jsx)("a",{className:"xref",href:"/katalon-studio/data-driven-testing/manage-data-binding",children:"Manage Data Binding"}),"."]}),(0,i.jsxs)("p",{className:"p",children:[" ",(0,i.jsx)("img",{className:"image",width:650,src:(0,n.Ay)("/990925b0-22b2-11ed-9930-0242fe3e4a3f/KS-830-Manage-data-binding.png")})]})]}),(0,i.jsxs)("li",{className:"li",children:[(0,i.jsxs)("p",{className:"p",children:["Once configured, run the test suite and verify the result in the ",(0,i.jsx)("strong",{className:"ph b",children:"Log Viewer"}),"."]}),(0,i.jsxs)("p",{className:"p",children:[(0,i.jsx)("img",{className:"image",src:(0,n.Ay)("https://github.com/katalon-studio/docs-images/raw/master/katalon-studio/docs/ddt-web-service/KS-DDT-Test-Result.png"),alt:"Test Data table of user information"}),(0,i.jsx)("br",{}),(0,i.jsx)("br",{})]})]})]}),"\n",(0,i.jsxs)("p",{xmlns:"http://www.w3.org/1999/xhtml",className:"p",children:[" ",(0,i.jsx)("strong",{className:"ph b",children:"See also"}),":"]}),"\n",(0,i.jsx)("ul",{xmlns:"http://www.w3.org/1999/xhtml",className:"ul",children:(0,i.jsx)("li",{className:"li",children:(0,i.jsx)("a",{className:"xref",href:"/katalon-studio/data-driven-testing/data-driven-testing-with-katalon-studio",children:"Data-driven Testing with Katalon Studio"})})})]})}function p(e={}){const{wrapper:s}={...(0,r.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(h,{...e})}):h(e)}},28453:(e,s,t)=>{t.d(s,{R:()=>n,x:()=>l});var a=t(96540);const i={},r=a.createContext(i);function n(e){const s=a.useContext(r);return a.useMemo((function(){return"function"==typeof e?e(s):{...s,...e}}),[s,e])}function l(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:n(e.components),a.createElement(r.Provider,{value:s},e.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.