Good day Everyone! I hope there will be someone that can answer my query.
I’m having trouble using Variable set in a Test Case and used in a Restful Web Service Request.
I am trying to get and loop the value that was get from a Test Data from Excel.
But when the variable value is used in the Web Service it Fails… Is there a way to fix or a work around for this? I appreciate the help and suggestion from anyone. Thanks in Advance!!
Please provide us with:
- Your test case script
- Your web service request file (.rs file)
- Your test data file and excel file.
- The log of failed test case
Test Case Script:
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 org.apache.poi.ss.usermodel.Cell as Cell
import org.apache.poi.ss.usermodel.Row as Row
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 GlobalVariableTestData data_General = findTestData(‘SFC/SC/Filter’)
TestData filter_values_sheet = findTestData(‘SFC/SC/Filter Values’)
TestData data_JSON = findTestData(‘SFC/SC/JSON Filter Values’)
lastRow = (filter_values_sheet.getRowNumbers() - 1)
def filter_values_fieldname = filter_values_sheet.getValue(1,1)
//1-32
for (def counter : (1…32)) {
def filter_command = data_General.getValue(1, 18) //Use only 1 filter for now, targeting to also loopdef filter_values = filter_values_sheet.getValue(4, counter) def request = WS.sendRequest(findTestObject('Smart Commands/Filter by/Filter Values_1/Filter Values'))
WS.verifyElementPropertyValue(request, ‘ReturnCode’, ‘SUCCESS’, FailureHandling.CONTINUE_ON_FAILURE)
WS.verifyElementPropertyValue(request, ‘FilterField[0].Field’, data_JSON.getValue(2,1), FailureHandling.CONTINUE_ON_FAILURE)
WS.verifyElementPropertyValue(request, ‘FilterField[0].ActualName’, data_JSON.getValue(3,1),
FailureHandling.CONTINUE_ON_FAILURE)WS.verifyElementPropertyValue(request, ‘FilterField[0].Operator’, data_JSON.getValue(4,1), FailureHandling.CONTINUE_ON_FAILURE)
WS.verifyElementPropertyValue(request, ‘FilterField[0].Value’, data_JSON.getValue(5,1), FailureHandling.CONTINUE_ON_FAILURE)
WS.verifyElementPropertyValue(request, ‘FilterField[0].Word’, data_JSON.getValue(6,1), FailureHandling.CONTINUE_ON_FAILURE)
println('Logging, we are at ' + filter_values) println('Filter command is :' + filter_command)
}
RS File (.RS file not available to be uploaded)
Excel File:
Failed Test Case Log:
SLF4J: The requested version 1.7.16 by your slf4j binding is not compatible with [1.6]
SLF4J: See SLF4J Error Codes for further details.
2020-02-12 09:34:50.148 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2020-02-12 09:34:50.158 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/SMART COMMANDS/Filter by/By Values/Corporate Group
2020-02-12 09:34:51.651 DEBUG testcase.Corporate Group - 1: data_General = findTestData(“SFC/SC/Filter”)
2020-02-12 09:34:53.350 DEBUG testcase.Corporate Group - 2: filter_values_sheet = findTestData(“SFC/SC/Filter Values”)
2020-02-12 09:34:53.532 DEBUG testcase.Corporate Group - 3: data_JSON = findTestData(“SFC/SC/JSON Filter Values”)
2020-02-12 09:34:53.575 ERROR c.k.katalon.core.main.TestCaseExecutor - Test Cases/SMART COMMANDS/Filter by/By Values/Corporate Group FAILED.
Reason:
java.lang.IllegalArgumentException: Cannot find test data with id ‘Data Files/SFC/SC/JSON Filter Values’ because (of) ‘java.lang.IllegalArgumentException: Test data with id ‘Data Files/SFC/SC/JSON Filter Values’ does not exist’
at com.kms.katalon.core.testdata.TestDataFactory.findTestData(TestDataFactory.java:122)
at com.kms.katalon.core.testdata.TestDataFactory$findTestData.callStatic(Unknown Source)
at Corporate Group.run(Corporate Group:22)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1581471285657.run(TempTestCase1581471285657.groovy:21)
Hi @jayveeolchondra69,
According to the execution log, your test fail because the test data with id ‘Data Files/SFC/SC/JSON Filter Values’ cannot be found. Please check whether the ID is correct.
Hi @huynguyen, thanks for the reply… I’ve checked and it’s correct. I tried to manually use the value from the excel into the Web Service Request and it works fine.
Do I have to create one of each values in the excel into a Web Service Request, or is there a way that I can continuously get those in One Web Service Request?
Hi @jayveeolchondra69,
Of course we should not do it that way, as it is very time-consuming for even moderate test data size. Moreover, once there are changes in you request definition, you have to modify all the web service requests you have made.
I think we should try to fix the root cause that the test data cannot be found. If possible, can you send me the whole project so that I can take a quick look to find the issue? To make it private, you can send your project via email in this forum.