Robot-Framework: how to get list from keyword and verify items

Viewed 2173

So in my test i have keyword that return list:

@{channels}=        Get Channels

For example the return list is ['1', '4', '11']

And i want to loop over this list and verify that 1, 4 and 11 exist at that list.

This is what i have try:

FOR     ${ELEMENT}        IN      @{channels}
            Log     ${ELEMENT}
            List Should Contain Sub List  @{channels}  ${ELEMENT}
END

And i received this error:

TypeError: Expected argument 1 to be a list or list-like, got string instead.

1 Answers

the problem is in how you use the first variable. With the decorators you only tell robot framework how to work with the variables. You can read more about list variables and decorators here.

${channels}=        Get Channels

just save the result as is($) using List Should Contain Value should match better since in your ${ELEMENT} there is no sublist.

FOR     ${ELEMENT}        IN      @{channels}
            Log     ${ELEMENT}
            List Should Contain Value    ${channels}    ${ELEMENT}
END
Related