Forum Discussion
nmrao
Champion Level 3
Just tried converting it into class / methods to achieve the same (equivalent of your script assertion)
The work is divided into two parts.
1. logging various details
2. comparing the response with a file
Hence, two methods created. and call the same in the script assertion.
So configure your script library as shown in the previous reply's documentation link.
And here comes the script assertion part.
//optional if you want to show the log statements Utility.showTestDetails(context, log) //Replace the filepath absolute path; this compares current test step response with given absolute file assert Utility.compare(context.response, '/file/path'), 'error message comparison failure'
If you don't want to trim new lines, then use as below to compare
//Pass 3rd optional argugemtn value as false; assert Utility.compare(context.response, '/file/path', false), 'error message comparison failure'
And here is the Utility class
class Utility { static def sanitize = { text -> text.trim().replace('\n', '').replace('\r', '') } static def showTestDetails(context, log) { log.with{ info "Project Path : ${context.testCase.testSuite.project.path}" info "Suite : ${context.testCase.testSuite.name}" info "Case : ${context.testCase.name}" info "Step : ${context.currentStep.name}" } } static def compare(response, fileName, isReplaceNewLine = true) { def fileContent = new File(fileName).text if (isReplaceNewLine) { sanitize(response) == sanitize(fileContent) } else { ressponse == fileContent } } }
TanyaYatskovska
5 years agoSmartBear Alumni (Retired)
Thanks for such great assistance, Rao, Richie!
jayantjayant, do the suggestions given here help you resolve the issue?
Related Content
- 5 years agoSiKing
- 2 years agoM_Schofer_1111