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?

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

2 Answers 2

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>
1
  • @Mortynaut, have you tried the above solution?
    – Rao
    Commented Mar 8, 2017 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.

1
  • 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
    Commented Aug 30, 2017 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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