Hi All,
I hope this article would be helpful for all salesforce automation testers.
Below code for Generating access token and storing access token in the global variable using script for above Post method
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import static org.assertj.core.api.Assertions.*
import com.kms.katalon.core.testobject.RequestObject as RequestObject
import com.kms.katalon.core.testobject.ResponseObject as ResponseObject
import com.kms.katalon.core.webservice.verification.WSResponseManager as WSResponseManager
import groovy.json.JsonSlurper as JsonSlurper
import groovy.json.JsonSlurper
tokenGen().toString()
def token
String tokenGen() {
def response = WS.sendRequest(findTestObject('GenerateAccessToken'))
def jsonSlurper = new JsonSlurper()
def slurper = new JsonSlurper()
def result = slurper.parseText(response.getResponseBodyContent())
def token = result.access_token
WS.verifyResponseStatusCode(response, 200)
println(token)
GlobalVariable.token = token
}
Creating POST method by configuration
Code for running POST method using script for above POST method
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.testobject.TestObjectProperty
import com.kms.katalon.core.testobject.ConditionType
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.testobject.RequestObject
'Get token'
String token = WebUI.callTestCase(findTestCase('Salesforce API Testing/AccessTokenGeneration'), [:], FailureHandling.CONTINUE_ON_FAILURE)
println(token)
'Scope to a project'
def request = (RequestObject)findTestObject('Object Repository/LeadCreation')
'Create new ArrayList'
ArrayList<TestObjectProperty> HTTPHeader = new ArrayList<TestObjectProperty>()
'Send token in HTTP header'
HTTPHeader.add(new TestObjectProperty('Authorization', ConditionType.EQUALS, "Bearer" + token))
HTTPHeader.add(new TestObjectProperty('Content-Type', ConditionType.EQUALS, 'application/json'))
'Set that token'
request.setHttpHeaderProperties(HTTPHeader)
'Get response text'
response = WS.sendRequest(findTestObject('Object Repository/LeadCreation'))
WS.verifyResponseStatusCode(response,200)