hi-
i am validating a request where multple category eg-4 fetched in response and each category has a name
i want to validate each name exist or not in response but the code i have written validating only one caterofy name and this name is validating with all other name pls let me knwo how it will validate wiht all the name
below is my response ,script and result in excel.
waiting for your response its very urgent
==============================Response===================================
{
"limit" : 20,
"offset" : 0,
"count" : 4,
"total" : 4,
"results" : [
{
"id" : "2e7c7d14-6e8a-441f-a325-9ba1961f69a5",
"key" : "c2",
"version" : 20,
"name" : {
"de-DE" : "Redner",
"sv-SE" : "Högtalare",
"en-GB" : "Speakers",
"it" : "Speaker",
"en" : "Speaker",
"da-DK" : "Højttaler",
"de" : "Speaker"
},
"slug" : {
"de-DE" : "Speaker",
"sv-SE" : "Speaker",
"en-GB" : "Speaker",
"it" : "Speaker",
"en" : "Speaker",
"da-DK" : "Speaker",
"de" : "Speaker"
},
"description" : {
"da-DK" : "Category description",
"en-GB" : "Speakers description",
"de-DE" : "Category description",
"sv-SE" : "Category description"
},
"ancestors" : [ ],
"orderHint" : "0.00001533710213728513601",
"createdAt" : "2018-08-08T06:36:54.177Z",
"lastModifiedAt" : "2018-10-03T13:36:36.782Z",
"externalId" : "2",
"metaTitle" : {
"de-DE" : "Speaker DE",
"sv-SE" : "Speaker SV",
"en-GB" : "Speaker EN",
"it" : "Speaker",
"en" : "Speaker",
"da-DK" : "Speaker DA",
"de" : "Speaker"
},
"metaDescription" : {
"da-DK" : "Category description",
"en-GB" : "Category description",
"de-DE" : "Category description",
"sv-SE" : "Category description"
},
"custom" : {
"type" : {
"typeId" : "type",
"id" : "348d3f9f-f82a-4cb2-ad7b-042b7e263814"
},
"fields" : {
"type" : "category",
"imageUrl" : "https://www.beoplay.com/~/media/buymodules/beolit17/gallery_buymodule_beolit17/desktop/beolit17_black_hero.jpg"
}
},
"assets" : [ ],
"lastMessageSequenceNumber" : 2
},
{
"id" : "99e0d67f-d040-4dfc-ab0e-06401d51edf8",
"key" : "c3",
"version" : 17,
"name" : {
"de-DE" : "Kopfhörer",
"sv-SE" : "Hörlurar",
"en-GB" : "Headphones",
"it" : "Headphone",
"en" : "Headphone",
"da-DK" : "Hovedtelefon",
"de" : "Headphone"
},
"slug" : {
"de-DE" : "Headphone-DE",
"sv-SE" : "Headphone-SV",
"en-GB" : "Headphone-EN",
"it" : "Headphone",
"en" : "Headphone",
"da-DK" : "Headphone-DA",
"de" : "Headphone"
},
"description" : {
"da-DK" : "Category description DA",
"sv-SE" : "Category description SV",
"de-DE" : "Category description DE",
"en-GB" : "Category description EN"
},
"ancestors" : [ ],
"orderHint" : "0.000015337102137285136017",
"createdAt" : "2018-08-08T06:36:54.57Z",
"lastModifiedAt" : "2018-10-03T13:36:36.773Z",
"externalId" : "3",
"metaTitle" : {
"de-DE" : "Headphone DE",
"sv-SE" : "Headphone SV",
"en-GB" : "Headphone EN",
"it" : "Headphone",
"en" : "Headphone",
"da-DK" : "Headphone DA",
"de" : "Headphone"
},
"metaDescription" : {
"da-DK" : "Category description DA",
"sv-SE" : "Category description SV",
"de-DE" : "Category description DE",
"en-GB" : "Category description EN"
},
"custom" : {
"type" : {
"typeId" : "type",
"id" : "348d3f9f-f82a-4cb2-ad7b-042b7e263814"
},
"fields" : {
"type" : "category",
"imageUrl" : "https://www.beoplay.com/~/media/buymodules/ss18/h4/gallery/desktop/h4_steelblue_hero.jpg"
}
},
"assets" : [ ],
"lastMessageSequenceNumber" : 2
},
{
"id" : "b7393c4c-7164-4b82-96da-c6164c069ca9",
"key" : "c1",
"version" : 23,
"name" : {
"de-DE" : "Fernsehens",
"sv-SE" : "Televisions SV",
"en-GB" : "Televisions",
"it" : "Television",
"en" : "Television",
"da-DK" : "Televisions DA",
"de" : "Television"
},
"slug" : {
"de-DE" : "Television-DE",
"sv-SE" : "Television-SV",
"en-GB" : "Television-EN",
"it" : "Television",
"en" : "Television",
"da-DK" : "Television-DA",
"de" : "Television"
},
"description" : {
"de-DE" : "description DE",
"sv-SE" : "description SV",
"en-GB" : "description EN",
"da-DK" : "description DA",
"en-US" : "description"
},
"ancestors" : [ ],
"orderHint" : "0.000015337102137285136017055",
"createdAt" : "2018-08-08T06:36:53.728Z",
"lastModifiedAt" : "2018-10-03T10:36:46.066Z",
"externalId" : "1",
"metaTitle" : {
"de-DE" : "Television",
"sv-SE" : "Television",
"en-GB" : "Television",
"it" : "Television",
"en" : "Television",
"da-DK" : "Television",
"de" : "Television"
},
"metaDescription" : {
"de-DE" : "description DE",
"sv-SE" : "description SV",
"en-GB" : "description EN",
"da-DK" : "description DA",
"en-US" : "description"
},
"custom" : {
"type" : {
"typeId" : "type",
"id" : "348d3f9f-f82a-4cb2-ad7b-042b7e263814"
},
"fields" : {
"type" : "category",
"imageUrl" : "https://www.bang-olufsen.com/~/mediaV3/home/collection/collection-televisions/beovision-eclipse/1350/imgpicture31350retina-min.jpg"
}
},
"assets" : [ ],
"lastMessageSequenceNumber" : 2
},
{
"id" : "3b495228-a792-40de-9a90-988ba4d71779",
"key" : "st1",
"version" : 6,
"name" : {
"en-GB" : "Stories",
"da-DK" : "Historier",
"sv-SE" : "Berättelser",
"de-DE" : "Geschichten"
},
"slug" : {
"en-GB" : "stories",
"da-DK" : "historier",
"sv-SE" : "berttelser",
"de-DE" : "geschichten"
},
"description" : {
"en-GB" : "Stories",
"da-DK" : "Stories",
"sv-SE" : "Stories",
"de-DE" : "Stories"
},
"ancestors" : [ ],
"orderHint" : "0.0000153371021372851360170555",
"createdAt" : "2018-10-03T10:03:01.668Z",
"lastModifiedAt" : "2018-10-03T10:39:26.073Z",
"externalId" : "5",
"metaTitle" : {
"en-GB" : "Stories",
"da-DK" : "Historier",
"sv-SE" : "Berättelser",
"de-DE" : "Geschichten"
},
"metaDescription" : {
"en-GB" : "Stories",
"da-DK" : "Stories",
"sv-SE" : "Stories",
"de-DE" : "Stories"
},
"custom" : {
"type" : {
"typeId" : "type",
"id" : "348d3f9f-f82a-4cb2-ad7b-042b7e263814"
},
"fields" : {
"type" : "stories",
"imageUrl" : "https://www.bang-olufsen.com/~/mediaV3/home/main-menu/stories/stories-768.jpg"
}
},
"assets" : [ ],
"lastMessageSequenceNumber" : 1
}
]
}
==============================script===========================================================
import groovy.json.JsonSlurper
def response =context.expand('${SearchAllCategory#response}')
log.info response
def slurper=new JsonSlurper()
def json=slurper.parseText response
//def ActualResultForEmail=$.person_list[?(@.tax-category=='84b37207-4b3e-4227-92fa-a7f849816027')].key
def actualCount=json.count
def categoycount=actualCount.toString()
log.info(categoycount)
//int i=0;
//def categoryNameID=json.results.name.de[i]
//int i=0;
//log.info(categoryNameID)
//def categoryID=json.results.id[i]
//log.info(categoryID)
//def expectedLoginStatus = context.expand( '${StartLoop#ExpectedStatus}' )
//def expectedStatusCode = context.expand( '${DataSource#ExpectedStatusCode}' )
//def expectedResponse = context.expand('' )
//log.info expectedStatusCode
//def categoryName = context.expand( '${AllCategory#CategoryName}' )
//log.info categoryName
//def headers = context.testCase.getTestStepByName("ProductSearch").testRequest.response.responseHeaders["#status#"]
//def ActualResponsestatus=headers.toString()
//log.info ActualResponsestatus
//def actualName=json.results.key[0].name
//ProductName
if(categoycount.equals("4")){
for(int i=0;i<3;i++)
{
def categoryIDResponse=json.results.id[i]
log.info(categoryIDResponse)
def ExpctedcategoryID = context.expand( '${AllCategory#CategoryID}')
log.info "---"+ExpctedcategoryID
def categoryName=json.results.name[i].en
log.info(categoryName)
def ExpectedcategoryName = context.expand( '${AllCategory#CategoryName}' )
//log.info ExpectedcategoryName
if(categoryIDResponse.equals(ExpctedcategoryID)){
if(categoryName.equals(ExpectedcategoryName)){
context.testCase.setPropertyValue("result","Pass Category Name matched "+ExpectedcategoryName)
}}
else{
context.testCase.setPropertyValue("result","Fail - expected Category - "+ExpectedcategoryName+" not same in response it is--"+categoryName )
//assert actualName == productName
}
}}