Contributions
Re: Random Date Project Property
Here is what is in my Groovy Script Test Step: //Start with a date of 14-06-01 def now = new Date().parse("yyyy-MM-dd", "2014-06-01") //Add to the month by adding a random integer to effectively range the date now.month = 6 + new Random().nextInt(18) //Add the result as a property to the TestCase context["randomDate"] = now.format("yyyy-MM-dd") log.info context["randomDate"] And the result is: Wed May 27 16:35:37 PDT 2015:INFO:2015-06-01 But when using ${=randomDate} in my Request TestStep, this is the error returned: <Message>The string 'No such property: randomDate for class: Script11' is not a valid AllXsd value.</Message> I take that to mean that it hasn't properly set the property. Is this something I must do manually as a Custom Property of the project, like I did with the one-liner? Thanks!3KViews0likes1CommentRe: Random Date Project Property
Rupert, You rock! I tried adding the context line to the Groovy Script TestStep (tried context.RandomDate also), but no matter how I format or sequence it, the Request keeps saying it cannot find the property. The one-liner works beautifully, though! I've accepted that as a Solution as well :) I would like to figure out why the script isn't working though, as you're correct - that would be a very helpful tool in the future. Thank you so much for all your help!3KViews0likes3CommentsRe: Random Date Project Property
HI Rupert, This works great in Groovy Script! I love how you have commented on each portion as well! However, I've been working on this for a couple of hours now and can't figure out how to get it into the SOAP request. Since this defines script variables and isn't using built-in commands like the previous one, I'm also not sure how to convert it to a property expansion. I tried piecing out the components: ${=new Date().parse("yyyy-MM-dd","2014-06-01") now.month = 6 + new Random().nextInt(18)} I also tried defining the variablesinside the property expansion: ${=def now = new Date().parse("yyyy-MM-dd","2014-06-01") + now.month = 6 + new Random().nextInt(18) + now.format("yyyy-MM-dd")} Tried using different expression aggregators like comma, +, etc... , Also tried simply ${=new Date().parse("yyyy-MM-dd","2014-06-01") + (6 + new Random().nextInt(18))} with no luck. I'm sorry for all of the trouble. Could I trouble you for one last hint?:smileyfrustrated: Thank you!!3KViews0likes5CommentsRe: Random Date Project Property
Thanks for all the help, Rupert! Just trying to wrap my head around the logic, really. I can't just change the (12)+1 to (6)+1 because then it won't do 1-5 for 2015. I wonder.. is there a methodto set up an array and randomly return from that? Could just set up the 18 dates in the array that way...6.1KViews0likes7CommentsRe: Random Date Project Property
Haha, I was actually coming back to the board to suggest this very thing. I'm using a SOAP request and it certainly looks like XML DateTime. So now I just need to figure out how to tell it to stop being smart and use it as a string. I will gladly mark your previous response as the answer, as it is definitely correct (and informative!) for the request.6.1KViews0likes11CommentsRe: Random Date Project Property
Hello Rupert, Thank you verymuch for your well thought-out and impressive reply! This is SO close! The property expansion returns2014-02-01T00:00:00 and I'm not sure where the extra "T00:00:00" part is coming from. Certainly gets me much farther than I was - and helps me learn the syntax - so I'm going to play around with it some more to see if I can get it the last 5% :) Cheers!6.1KViews0likes14CommentsHow to tell what a command returns?
Hello all, Novice at SoapUI coding, so apologies if this is a stupid question. Haven't been able to find an answer in the Help, though. Is there a way to tell exactly what a command is returning? For example, if I create a custom property and then call it in a Request, it just gives me an error. It would be very helpful if there were a tool I could use to tell exactly what the return of the command is instead. Example command:${=String.valueOf('2014-'&'(Math.Random() * (12 - 01) + 01)'&'-01')} Thank you!751Views0likes1CommentRandom Date Project Property
Hello all! I'm hoping that somebody can help me with this request - I'm a complete novice at this type of coding. I need to create a Project Property variable to randomize a datein my Soap Requestwith the following parameters: Year is 2014 or 2015 only Any month 01-12 (has to have the leading 0 if single digit) Day is always 01 Format example: YYYY-MM-DD (2014-06-01) So far - without even toggling between year of 2014 and 2015 - I have a value of${=String.valueOf('2014-'&'(Math.Random(01-12))'&'-01')}, but get error: The string 'No signature of method: java.lang.String.and() is applicable for argument types: (java.lang.String) values: [(Math.Random(01-12))] Possible solutions: any(), find(java.lang.String), any(groovy.lang.Closure), find(), find(groovy.lang.Closure), find(java.lang.String, groovy.lang.Closure)' is not a valid AllXsd value Another way to accomplish this could be using an array, but I'm not sure how to set that up in a Property one-liner either. Thank you. Any help or guidance would be greatly appreciated!!Solved6.9KViews2likes16Comments