簡體   English   中英

如何使用機器人框架從另一個列表中刪除一個列表中存在的元素

[英]How to remove the element present in one list from another list using robotframework

我對 Robot 框架非常陌生,並試圖打印不常見的值:

$list1= ['test1','test2','test3','test4'] $list2= ['test1','test2','test3','test4','test5']

${difference}= $list2-$list1 記錄到控制台 ${difference}

這是差異關鍵字的一個可能示例:

*** Settings ***
Library           Collections

*** Test Cases ***
Difference of lists
    @{list1}=    Create List    test1    test2    test3    test4
    @{list2}=    Create List    test1    test2    test3    test4    test5
    @{list3}=    Create List    test4    test3    test1    test2
    ${diff_list}=    List Difference    ${list1}    ${list2}
    Log Many    @{diff_list}
    Should Be Equal As Strings    ${diff_list}    ['test5']
    ${diff_list}=    List Difference    ${list1}    ${list3}
    Log Many    @{diff_list}
    Should Be Equal As Strings    ${diff_list}    []

*** Keywords ***
List Difference
    [Arguments]    ${arg1}    ${arg2}
    @{new_list}=    Create List    @{arg1}    @{arg2}
    FOR    ${item}    IN    @{arg1}
        Remove Values From List    ${new_list}    ${item}
    END
    RETURN    ${new_list}
      

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM