How to Verify Date Time difference in Parasoft
I want to verify the difference between two dates in Parasoft.
My responce looks like below:
<TodaysDate>06/28/2017 14:02:06</TodaysDate> <FutureDate>08/28/2017 16:18:55</FutureDate>
Along with the Date in my response Time is also displayed but I want only the date Difference.
Answers
-
The XML/JSON Assertor tools have a "Date Difference Assertion".
0 -
Thanks for the Reply.
According to Date Difference Assertion I converted my dates format to yyyy-MM-dd. I used following XPATH to change the date Format:/*:Envelope/*:Body/*:Response/*:FutureDate/concat(substring(., 7, 4), '-', substring(., 1, 2), '-', substring(., 4, 2))
But when I ran my test case I am getting following error:
Error Message:
An error occurred while processing an assertion: net.sf.saxon.trans.XPathException: Cannot convert
XPath value to Java object: required class is org.w3c.dom.NodeList; supplied value has type
xs:string0 -
Your XPath is constructing a string, but SOAtest currently requires that XPaths in the Assertor tools describe a node in the XML document. There may be an easier way, but another approach to solving this problem is use XML Data Bank to store both of the dates, and then to use a script like the following to compare them:
import com.parasoft.api.*; public boolean checkDates(Object obj, ScriptingContext context) { todaysDate = new Date(context.getValue(null, "Test 1: TodaysDate")); futureDate = new Date(context.getValue(null, "Test 1: FutureDate")); if (todaysDate.getYear() != futureDate.getYear() || todaysDate.getMonth() != futureDate.getMonth() || todaysDate.getDay() != futureDate.getDay()) { context.report(todaysDate.toString() + " does not match " + futureDate.toString()); } }
0