机器人框架工作迭代列表问题

时间:2017-02-03 06:33:08

标签: python python-2.7 list robotframework

您好我正在尝试遍历列表并在字符串中使用列表中的每个元素。但整个列表将被复制到字符串中,而不是逐个元素。我的测试用例和日志如下,请帮助。

test
    ${list}    Create List    first
    : FOR    ${i}    IN RANGE    1    17
    \    log    ${i}
    \    Append To List    ${list}    ${i}
    log    ${list}
    :FOR    ${i}    IN    ${list}
    \    log    show:all interfaces-state interface "gfast 0/${i}"

LOG

    TEST CASE: test
Full Name:  NEW CPE UPGRADE.test
Start / End / Elapsed:  20170203 11:52:31.963 / 20170203 11:52:32.079 / 00:00:00.116
Status: PASS (critical)
00:00:00.001KEYWORD: ${list} = BuiltIn.Create List first
00:00:00.101FOR: ${i} IN RANGE [ 1 | 17 ]
00:00:00.008KEYWORD: BuiltIn.Log ${list}
Documentation:  
Logs the given message with the given level.
Start / End / Elapsed:  20170203 11:52:32.069 / 20170203 11:52:32.077 / 00:00:00.008
11:52:32.069    TRACE   Arguments: [ [u'first', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] ]    
11:52:32.077    INFO    [u'first', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]   
11:52:32.077    TRACE   Return: None    
00:00:00.002FOR: ${i} IN [ ${list} ]
Start / End / Elapsed:  20170203 11:52:32.077 / 20170203 11:52:32.079 / 00:00:00.002
00:00:00.002VAR: ${i} = [u'first', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
Start / End / Elapsed:  20170203 11:52:32.077 / 20170203 11:52:32.079 / 00:00:00.002
00:00:00.000KEYWORD: BuiltIn.Log show:all interfaces-state interface "gfast 0/${i}" oper-status
Documentation:  
Logs the given message with the given level.
Start / End / Elapsed:  20170203 11:52:32.078 / 20170203 11:52:32.078 / 00:00:00.000
11:52:32.078    TRACE   Arguments: [ u'show:all interfaces-state interface "gfast 0/[u\'first\', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]" oper-status' ] 
11:52:32.078    INFO    **show:all interfaces-state interface "gfast 0/[u'first', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]" oper-status** 
11:52:32.078    TRACE   Return: None

1 个答案:

答案 0 :(得分:3)

您需要遍历以下列表::FOR ${i} IN @{list}