Reputation: 70
I have a function in my (python) keyword library that returns a list, but when I pass it into the robot testcase, I get the error "Value of variable @{LIST} is not list or list-like". Here is my code
Robot code:
Generate Data
@{LIST}= Create Data
Do Thing For All Values In List
:FOR ${value} IN @{LIST}
\ Do The Thing ${value}
Python code for this:
def create_data():
data = []
for i in range(0, 10):
data_val = do_a_bunch_of_selenium_automation(i)
data.append(data_val)
return data
How do I do this correctly? Thanks all.
Upvotes: 0
Views: 3880
Reputation: 385970
In the code in your question, You are properly iterating over a list. However, you're creating the data in one test case and then trying to use it in another. The data is in a local variable in that first test case.
If you want to share data between test cases, you need to set the variable as a test suite variable, which you can do with the built-in keyword Set suite variable
Generate Data
@{LIST}= create data
set suite variable @{LIST}
Upvotes: 2
Reputation: 6961
To be honest your examples work for me. Made a few additions to get to a working example but nothing major:
ListCreationLibrary.py
class ListCreationLibrary(object):
ROBOT_LIBRARY_VERSION = 1.0
def __init__(self):
pass
def create_data(self):
data = []
for i in range(0, 10):
data_val = self.do_a_bunch_of_selenium_automation(i)
data.append(data_val)
return data
def do_a_bunch_of_selenium_automation(self, i):
return "some_string" + str(i)
test_script.robot
*** Settings ***
Library ListCreationLibrary
*** Test Cases ***
TC
${list_example} Create Data
Do Thing For All Values In List ${list_example}
*** Keywords ***
Do Thing For All Values In List
[Arguments] ${LIST}
:FOR ${value} IN @{LIST}
\ Do The Thing ${value}
Do The Thing
[Arguments] ${value}
Log ${value}
Put the two files in the same directory and you should be OK.
Upvotes: -1