엄지월드

API Call 본문

QA/Groovy

API Call

킨글 2021. 8. 15. 22:38

카탈론에서 아래와 같이 API콜이 가능하다.

 

import com.kms.katalon.core.testobject.TestObjectProperty
import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.impl.HttpTextBodyContent
import com.kms.katalon.core.testobject.ConditionType
import groovy.json.JsonSlurper

def guidanceSaveStep1(def rq){
  String path = "/path"
  String url = adminDomain+path;
  // TestObjectProperty header1 = new TestObjectProperty("AUToken", ConditionType.EQUALS, rq.createAUToken)
  
  ArrayList defaultHeaders = Arrays.asList(
  	new TestObjectProperty("Content-Type", ConditionType.EQUALS, "application/json"), 
    new TestObjectProperty("Cookie", ConditionType.EQUALS, rq.session)
   )

  String body = '{"data":"data"';

  RequestObject ro = new RequestObject("objectId")
  ro.setRestUrl(url)
  ro.setHttpHeaderProperties(defaultHeaders)
  ro.setRestRequestMethod("POST")
  ro.setBodyContent(new HttpTextBodyContent(body))
  ResponseObject respObj = WS.sendRequest(ro)
  println respObj.getResponseText()

  def jsonSlurper = new JsonSlurper()
  def json_guidanceSn = jsonSlurper.parseText(respObj.getResponseText())

  return json_guidanceSn.guidanceSn
}

'QA > Groovy' 카테고리의 다른 글

Chrome Headless  (2) 2021.08.15
Groovy 정규식 사용  (0) 2019.11.20
Comments