Contributions
- 6 years agoPlace ReadyAPI QuestionsReadyAPI Questions1.4KViews0likes0Comments
Groovy script - help required
I have a groovy script, within which I'm trying to set some test properties i.e. today, tomorrow etc.... For one of the properties 'tommorowmonth' I need to work out the month, then use that result to lookup up a value from a list. This is so I can use the derived value later in tests as assertions against REST response. My code works when I hardcode the month value, but returns an error when I try to pass it in as a variable. As follows: Working code with hardcoded month = 9, this returns '1324' use(groovy.time.TimeCategory) { def now = new Date();now.format("yyyy-MM-dd") def tomorrow = now + 1.day def todayplus3m1d = now + 3.month + 1.day def tomorrowday = now + 1.day; tomorrowday.format("d") def tomorrowmonth = now + 1.day; tomorrowmonth.format("M") def map = [1: '1316', 2: '1317', 3:'1318', 4:'1319', 5:'1320', 6:'1321', 7:'1322', 8:'1323', 9:'1324', 10:'1325', 11:'1326', 12:'1327'] //def tm = tomorrowmonth.format("M") def item = map.find {key, value -> key==9} //this works with a hardcoded value //def item = map.find {key, value -> key==tomorrowmonth.format("M")} //this doesn't work and return the error below log.info item.value Error code with variable month = tomorrowmonth.format("M"), this returns an error ' Java.lang.NullPointerException: Cannot get property ‘value’ on null object error at line 1 ' use(groovy.time.TimeCategory) { def now = new Date();now.format("yyyy-MM-dd") def tomorrow = now + 1.day def todayplus3m1d = now + 3.month + 1.day def tomorrowday = now + 1.day; tomorrowday.format("d") def tomorrowmonth = now + 1.day; tomorrowmonth.format("M") def map = [1: '1316', 2: '1317', 3:'1318', 4:'1319', 5:'1320', 6:'1321', 7:'1322', 8:'1323', 9:'1324', 10:'1325', 11:'1326', 12:'1327'] def item = map.find {key, value -> key==tomorrowmonth.format("M")} log.info item.value Any help appreciated.Solved6 years agoPlace ReadyAPI QuestionsReadyAPI Questions1.5KViews0likes2CommentsRe: Retreiving data from Mongo db using Groovy and assigning it to a test case property
Thanks Todd, I worked though this in debug as you suggested and eventually manged to get some meaningful data out of Mongo DB. I now have it passing this data back into my test case.6 years agoPlace ReadyAPI QuestionsReadyAPI Questions9.9KViews0likes0CommentsRetreiving data from Mongo db using Groovy and assigning it to a test case property
Hi, I'm looking to create a test step that can connect toMongoDB, run a query, and then assign the result to a test case property. I have the connection working and I can retrieve a result as a row count. However I cannot get the actual result to assign it to a test case property. I know how to assign a value to a test case property but simply cannot get the result in order to do that. Below is my existing code. I'm connecting to a MongoDB called database called 'digital', within that there is a collection called 'QuoteSummary'. Within 'QuoteSummary' I'm searching for a "quoteRefNo" where "workReferenceNo" = GPE0024879. Its the resulting "quoteRefNo" that I want to assign to a test case property. import com.gmongo.GMongoClient import com.mongodb.MongoCredential import com.mongodb.ServerAddress import com.mongodb.BasicDBObject def credentials = MongoCredential.createCredential('hidden_user', 'digital', 'hidden_pwsd' as char[]) def serverAddress = new ServerAddress('hidden_servername_and_port') def mongo = new GMongoClient(serverAddress, [credentials]) def db = mongo.getDB('digital') BasicDBObject query = new BasicDBObject("workReferenceNo":"GPE0024879") BasicDBObject query1 = new BasicDBObject(quoteRefNo: 1,_id: 0) def collection = db.getCollection('QuoteSummary') //log.info(collection.find(query).count()) log.info(collection.find((query),(query1)).count())Solved9.9KViews0likes5CommentsRe: How to I set the value of a test case property from a groovy script
Thanks, eventual working code looks like this: use(groovy.time.TimeCategory) { def quoteexpirydate = context.expand ( '${#TestCase#quoteexpirydate}' ) def formated_quoteexpirydate = Date.parse("yyyy-MM-dd", quoteexpirydate) def onedayfromexpirydate = formated_quoteexpirydate + 1.day def testCaseProperty = testRunner.testCase.setPropertyValue("quoteexpirydate_plus", onedayfromexpirydate.format("yyyy-MM-dd")) }6 years agoPlace ReadyAPI QuestionsReadyAPI Questions1.5KViews0likes0CommentsHow to I set the value of a test case property from a groovy script
I have a working groovy script that adds 1 day onto a date stored in a property called 'quoteexpirydate'... the script works fine and I can see the result in the log.info window. My question is, how do I set the value of another property 'quoteexpirydate_plus' so I can use this in my next REST request message. Here is my existing Groovy script: use(groovy.time.TimeCategory) { def quoteexpirydate = context.expand ( '${#TestCase#quoteexpirydate}' ) def formated_quoteexpirydate = Date.parse("yyyy-MM-dd", quoteexpirydate) def onedayfromexpirydate = formated_quoteexpirydate + 1.day log.info onedayfromexpirydate.format("yyyy-MM-dd") }Solved6 years agoPlace ReadyAPI QuestionsReadyAPI Questions1.5KViews0likes2Comments