Forum Discussion

Department_of_T's avatar
Department_of_T
Contributor
11 years ago

Adding days to a date from a response

Hi
I have a X Path Assertion in which i am trying to add 1 Day to a date in a response file and verify it against a value in the database. I can easily validate the date if i use todays date
${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss").format(new Date() +1)}


But when i try and add one day to the date in the response it fails. Can anyone help?
${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss").format(${findVehicleRegistrationRenewal - Request 1#Response#declare namespace ns0='licensing.transport.wa.gov.au'; //ns0:findVehicleRegistrationRenewalResponse[1]/findVehicleRegistrationRenewalResponse[1]/registrationExpiryDate[1]} +1)}


registrationExpiryDate is in the format dd/mm/yyy
  • I tried adding the assert as a script response but i get the message "Cannot format given Object as a date"
  • I have it working. Thanks

    import groovy.time.TimeCategory
    def XMLDate = context.expand( '${JDBC Request to verify acc_account_items#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/DEALING_TO_DATE[1]}' )
    def SQLdate = context.expand('${JDBC Request to find vehicle#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/LICENCE_EXPIRY_DATE[1]}' )
    def shortSQLDate = new Date().parse("yyyy-MM-dd",SQLdate)
    def shortXMLDate = new Date().parse("yyyy-MM-dd",XMLDate)
    use(TimeCategory) {
    shortSQLDatePlusOne=shortSQLDate + 6.month
    }
    log.info shortSQLDatePlusOne
    log.info shortXMLDate
    assert shortSQLDatePlusOne == shortXMLDate