cancel
Showing results for 
Search instead for 
Did you mean: 

problems of step return inconsistency

SOLVED
Highlighted
Frequent Contributor

problems of step return inconsistency

Hello,

I have a strange problem with my step result processing.

I have a step ("get all devices") that can return a list of devices. the result is always ["item1", "item2, ...] etc, even if I have only one item.

In a further step, I get this step's output and do a parsing :

items_list = jsonSlurper.parseText(items_list)

this works fine. I use this as the items can sometimes be listed as [{"uid1":"item1"}],etc.

The problem is that it sometimes fails because my input is incorrect.

If my first step provides me with two items or more ( ["item1", "item2, ...] ) the second step input (${get all devices#testResponse#$['result']}) gives me ["item1", "item2, ...] 

If my first step provides me with a single item (["item1]) the second step input is like [item1] => slight difference, but with the missing "" my json parsing fails

 

Does anyone knows why the format changes ?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Frequent Contributor

Re: problems of step return inconsistency

I found a workaround, though I really would like to know why this happens.

Here is the workaround :

 

if (items_list.tokenize('[,]').size() == 1)
{
    items_list = groovy.json.JsonOutput.toJson(items_list.tokenize('[,]'))
}

items_list = jsonSlurper.parseText(items_list)

[item1] becomes ["item1"] and can be parsed properly

View solution in original post

2 REPLIES 2
Highlighted
Frequent Contributor

Re: problems of step return inconsistency

I found a workaround, though I really would like to know why this happens.

Here is the workaround :

 

if (items_list.tokenize('[,]').size() == 1)
{
    items_list = groovy.json.JsonOutput.toJson(items_list.tokenize('[,]'))
}

items_list = jsonSlurper.parseText(items_list)

[item1] becomes ["item1"] and can be parsed properly

View solution in original post

Highlighted
Community Manager

Re: problems of step return inconsistency

Thanks for sharing the solution with us! 

I'm sure it will help someone in the future.

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Read the Latest News
JuneSCNJ
Top Kudoed Authors