4

I'm trying to use property as an input for API that requires a date. Since I'm remaking these tests every day, and will probably use them in future again, I want the value to be fluid. I encountered this tiny piece online for tomorrow

${=def lastWeek = new Date();lastWeek++;lastWeek.format("yy-MM-dd")}

But I have still yet to discover how to convince SoapUI NG Pro that I want a date one week from today.

Is there a possibility to make anything like this possible in SoapUI, and is my approach correct?

  • Can you try lastWeek - 7 rather than lastWeek++ – Swagin9 Feb 20 '17 at 22:26
  • 1
    today is 3 rd March, one week from today will be 10th March? Is that you want? – Rao Mar 3 '17 at 12:23
  • Can you give an example of what the parameter eventualyl should be? What should that date represent? – Alexey R. Aug 30 '17 at 15:18
1

All you need to do is to add a week to today as mentioned below:

${= def nextWeek = new Date() + 7; nextWeek.format("yy-MM-dd")}

For example, there is an element deliverDate:

<deliverDate>${= def nextWeek = new Date() + 7; nextWeek.format("yy-MM-dd")}</deliverDate>
  • @Mortynaut, have you tried the above solution? – Rao Mar 8 '17 at 2:05
1

I found it best to clear the date first to avoid conflicts

//Clear the date value in your variable
def current = new Date().clearTime()

//Set the date as 7 days ago
def lastWeek = (current - 7)

//Print out
lastWeek.each { println it }

Save that value as a property using a command like

testRunner.testCase.testSuite.project.setPropertyValue("yourProp", lastWeek)

Assuming the groovy script is run before that variable is used (or put into a tearup script) the date stored in that property will always be 1 week ago.

  • I was slightly unclear is you meant in the future or past, for a week in the future, simply change the value to +7 – ECiurleo Aug 30 '17 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.