Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Count Values In List Robot Framework

Count Values In List Returns the number of occurrences of the given value in list. See the example below. 

 

*** Settings ***
Library           Collections

*** Test Cases ***
Count Values In List Test
    Comment    Returns the number of occurrences of the given value in list.
    @{MyList}=    Create List    1
    Append To List    ${MyList}    2
    Append To List    ${MyList}    2
    Append To List    ${MyList}    3
    ${count}=    Count Values In List    ${MyList}    2
    Log    ${count}
    Should Be Equal    '${count}'    '2'

Copy List Test
    comment    Returns a copy of the given list
    @{MyList}=    Create List    Foo1    Foo2    Foo3
    Log List    ${MyList}
    @{CopiedList}=    Copy List    ${MyList}
    Log List    ${CopiedList}
    List Should Contain Value    ${CopiedList}    Foo3

Run the script and see the result below. The value "2" appeared twice in the list, so the assertion passed in the test

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Count Values In List Test
20150424 00:09:56.644 :  INFO : @{MyList} = [ 1 ]
20150424 00:09:56.654 :  INFO : ${count} = 2
20150424 00:09:56.654 :  INFO : 2
20150424 00:09:56.654 :  INFO : 
Argument types are:
<type 'unicode'>
<type 'unicode'>
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Count Values In List Test