【问题标题】:Robot Framework Collections.Remove Values From List removes all valuesRobot Framework Collections.Remove Values From List 删除所有值
【发布时间】:2018-10-13 01:24:03
【问题描述】:

我将一些输出拆分为一个列表,然后我试图清理该列表,因为列表中有一些我不需要的值。我想删除任何不是节点或日期的列表项;但是,Remove Values From List 关键字会返回一个空列表。任何建议将不胜感激。

Create And Clean Times List   
    @{times}    Split String    ${output}       separator=${\n}
    Log List    ${times}
    ${value}=   Set Variable     @{times}[0]
    @{times2}=  Remove Values From List    ${value}
    Log List    ${times2}

>

KEYWORD Collections . Log List ${times}
Start / End / Elapsed:  20181012 12:16:32.635 / 20181012 12:16:32.636 / 
00:00:00.001
12:16:32.636    INFO    List length is 28 and it contains following items:
0: META: ran handlers
1: node1 | SUCCESS | rc=0 >>
2: Fri Oct 12 16:16:29 GMT 2018
3: node2 | SUCCESS | rc=0 >>
4: Fri Oct 12 16:16:29 GMT 2018
5: node3 | SUCCESS | rc=0 >>
6: Fri Oct 12 16:16:29 GMT 2018
7: node4 | SUCCESS | rc=0 >>
8: Fri Oct 12 16:16:29 GMT 2018
9: node5 | SUCCESS | rc=0 >>
10: Fri Oct 12 16:16:29 GMT 2018
11: node6 | SUCCESS | rc=0 >>
12: Fri Oct 12 16:16:30 GMT 2018
13: node7 | SUCCESS | rc=0 >>
14: Fri Oct 12 16:16:31 GMT 2018
15: node8 | SUCCESS | rc=0 >>
16: Fri Oct 12 16:16:31 GMT 2018
17: node9 | SUCCESS | rc=0 >>
18: Fri Oct 12 16:16:31 GMT 2018
19: node10 | SUCCESS | rc=0 >>
20: Fri Oct 12 16:16:31 GMT 2018
21: node11 | SUCCESS | rc=0 >>
22: Fri Oct 12 16:16:31 GMT 2018
23: node12 | SUCCESS | rc=0 >>
24: Fri Oct 12 16:16:32 GMT 2018
25: META: ran handlers
26: META: ran handlers
27: [sysadmin@basebox ~]$   

00:00:00.001KEYWORD ${value} = BuiltIn . Set Variable @{times}[0]
Start / End / Elapsed:  20181012 12:16:32.637 / 20181012 12:16:32.638 / 00:00:00.001
12:16:32.638    INFO    ${value} = META: ran handlers
00:00:00.001KEYWORD @{times2} = Collections . Remove Values From List value='${value}'
Documentation:  
Removes all occurrences of given values from list.

Start / End / Elapsed:  20181012 12:16:32.639 / 20181012 12:16:32.640 / 00:00:00.001
12:16:32.640    INFO    @{times2} = [ ] 

Start / End / Elapsed:  20181012 12:16:32.640 / 20181012 12:16:32.641 / 00:00:00.001
00:00:00.001KEYWORD Collections . Log List ${times2}
Documentation:  
Logs the length and contents of the list using given level.

Start / End / Elapsed:  20181012 12:16:32.642 / 20181012 12:16:32.643 / 00:00:00.001
12:16:32.643    INFO    List is empty.

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    Remove values from list 不会返回新列表,它会从原始列表中删除值。

    这是一个说明:

    *** Settings ***
    Library  Collections
    
    *** Variables ***
    @{full_list}   one  two  three
    @{short_list}  one  three
    
    *** Test Cases ***
    Example
        ${result}=  remove values from list  ${full_list}  two
        should be equal  ${result}  ${NONE}
        should be equal  ${full_list}  ${short_list}
    

    【讨论】:

    • 感谢您的帮助!推荐的步骤效果很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 2014-06-28
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    • 2019-02-21
    • 2017-04-09
    相关资源
    最近更新 更多