Nested/Multi-Level Looping

Edited post for better clarity on problem statement

Situation: I have 2 screens, Screen A and Screen B. Screen A will process listA, and Screen B will process listB, depending on which data in listA is being processed.

listA and listB would be my 2 separate data sources, with a key being the link between the 2.

What I want to do is to first loop the data in listA, then based on a key from listA, I will filter and process the data from listB.

In coding terms, I guess, it’s similar to:

 listA = [ObjA, ObjB, ObjC, ObjD, ObjE]
 listB[ObjA] = [SubObjA1, SubObjA2, SubObjA3, SubObjA4]
 listB[ObjB] = []
 listB[ObjC] = [SubObjC1, SubObjC2, SubObjC3, SubObjC4]
 listB[ObjD] = [SubObjD1, SubObjD2, SubObjD3, SubObjD4]
 listB[ObjE] = []
 for var x = 0; x < listA.length; x++
    process listA[x]
    for var y = 0; y < listB[ listA[x] ].length; y++
             process listB[ listA[x] ][y]

In the end, the result flow should be like:
→ SubObjA1, SubObjA2, SubObjA3, SubObjA4

→ SubObjC1, SubObjC2, SubObjC3, SubObjC4
→ SubObjD1, SubObjD2, SubObjD3, SubObjD4

The key issue I’m having, I guess, is how to get persistent data; to only go back to looping in listA once the key in listB is not the same.

Hey @erik.yeow,
You can do it using Javascript with the ‘Execute JavaScript’ with parameters.

Is there a guide or sample on how to do it?

At a glance, for one, Im not sure how would the Javascript read from 2 separate data sources when we can only attach one to each test.
Then, there’s the persistence issue I mentioned and TestScript makes it kinda hard to verify data being parsed in when running from a data source.(ie not in Record mode)

@erik.yeow You can combine it with dynamic loops. You can read more about it here:

You will need to adapt the article information to your case.

This topic was automatically closed after 180 days. New replies are no longer allowed.