cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script for Assertion to check value

SOLVED
Highlighted
Community Hero

Re: Groovy Script Required to check assertion depending on Environments

Question is linked to previous question.

You were confident earlier regarding order despite saying. Can you go back to previous replies and identify how you can uniquely identify, logic can be written accordingly.


Regards,
Rao.
Highlighted
Community Hero

Re: Groovy Script Required to check assertion depending on Environments

Basically how can you say after this or before this when the response has duplicate ids? Why don't you go back to your team and check why is this happening at all?


Regards,
Rao.
Highlighted
Community Leader

Re: Groovy Script Required to check assertion depending on Environments

@doubtsreadyapi : Have you tried modifying the code which i provided earlier, if you try to modify that code you will be able to assert on your new requirement.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Contributor

Re: Groovy Script Required to check assertion depending on Environments

Hi @HimanshuTayal 

 

Thanks for the Update.

 

I tried modifying the Code like below, its working now.. Before i was facing error. it was failing in some environments

 

import groovy.json.JsonSlurper

def response = messageExchange.response.responseContent
def jsonsl = new JsonSlurper().parseText(response)
def Result = jsonsl.gr[0].args
def count = Result.size()
def flag = false
for (int i=0;i < count; i++){
	if (Result[i].Id == "abcd"){
		for (int j=i ; j < count; j++){
			def id = Result[j].Id
			if(id == "d1234"){				
				def status = Result[j].State
				assert id == "d1234" : "d1234 not found"
				assert status == 'success' : "d1234 failed"
				flag = true;
			}
		}
	}
}
assert flag , "d1234 is missing"

 

Thanks

View solution in original post

Highlighted
Community Leader

Re: Groovy Script Required to check assertion depending on Environments

@doubtsreadyapi :

 

Glag that you solved at your own, that way you will learn groovy 🙂

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors