Chi*_*gra 1 python robotframework
我遇到了一个问题,我必须将字典(或其他一些数据存储数据类型)作为参数传递给某个方法,该方法将从该方法中动态获取所有用户并执行所需的操作。我的问题是:
1) 在机器人框架中可以吗?
2)如果可能的话,我们将如何做到这一点?
Adding Participant
... Number_of_users= depend on participants name
... Participant name= x, y, z, etc..
Adding Participant
[Arguments] ${Number_of_users} ${Participant name}
:FOR ${ELEMENT} IN ${Participant name} --> [How this participant name will be stored dynamically ?]
\ Log ${ELEMENT}
\ Run Keyword ${ELEMENT} {?{?{?{It will do some operations for user x then in next loop y and so on}}}
Run Code Online (Sandbox Code Playgroud)
如何将字典作为关键字参数传递?- 与任何其他数据类型相同。在下面的示例中,您可以看到这一点,以及两种迭代(循环)字典键的简单方法:
*** Test Cases ***
A case
${a dict}= Create Dictionary key1=value1 key2=another value
My Keyword That Works With Dictionaries ${a dict}
*** Keywords ***
My Keyword That Works With Dictionaries
[Arguments] ${dct}
${the type}= Evaluate type($dct)
Log To Console The passed argument is of type ${the type} # will print dict
${all keys in the dict}= Get Dictionary Keys ${dct} # a list will all dictionary keys
# 1st way to iterate/loop
:FOR ${key} IN @{all keys in the dict}
\ Log To Console Working with key ${key}
\ ${value}= Get From Dictionary ${dct} ${key}
\ Log To Console Its value is "${value}" (another way to get it is ${dct['${key}']})
# the 2nd way
:FOR ${key} IN @{dct}
# this comes from the python's syntax "for key in dct:" - an
# iterator over a dictionary returns its keys
\ Log To Console Working with key ${key}
# and so on
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2784 次 |
| 最近记录: |