Parsing SOAP XML Response Text

Hi,

Im trying to parse SOAP response and write response values into an excel workbook so as to use the data for the next test case. So far ive written this custom keyword that works. But the problem is that this keyword cannot be reused as i have explicitly declared the locator of the element value in the code(hard-coded).

@Keyword

def void writePiNToExcel(ResponseObject response, String locator, int row, int column){

String xml = response.responseBodyContent

def request = new XmlSlurper().parseText(response.responseBodyContent)

String pin = request.Body.GenOTPResponse.Password

FileInputStream file = new FileInputStream (new File(“C://Users/tmwaura1/git/CBSWebservices/Data Files/Test Data Sfc App.xlsx”))

XSSFWorkbook workbook = new XSSFWorkbook(file);

XSSFSheet sheet = workbook.getSheetAt(2);

Cell searchText = sheet.getRow(row).getCell(column);

searchText.setCellValue(pin);

file.close();

FileOutputStream outFile =new FileOutputStream(new File(“C://Users/tmwaura1/git/CBSWebservices/Data Files/Test Data Sfc App.xlsx”));

workbook.write(outFile);

outFile.close();

}

How can i make use of the inbuilt katalon functions to parse response object and the the locator and get the value to write to excel.

Thanks

Timothy,

Your approach is good, I think your “locator” is the Excel file path and you haven’t used in the code. If you replace the hardcode by the “locator”, it will be reused well.

Trong Bui said:

Timothy,

Your approach is good, I think your “locator” is the Excel file path and you haven’t used in the code. If you replace the hardcode by the “locator”, it will be reused well.

Hi,
How can i get transform this

def request = new XmlSlurper().parseText(response.responseBodyContent)

String pin = request.Body.GenOTPResponse.Password

So as to have something dynamic such as

String x = request.$locator
I mean. How have you implemented your extractor function to pass the just the locator and response object and get the value at the locator

Doing this requies some more complex code and personally, it will make the function not readable. For your purpose, I would suggest that you could make the function write a value to specific excel and the input is actual value.

The function will be something as writeToExcel(request.Body.GenOTPResponse.Password, col, row).

ok thanks @Trong Bui . It would be nice if you suggested this to the developers. to expose a way of getting the response elements.