Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Convert To List Robot Framework

In Robot Framework, the keyword "Convert To List" is used to to convert the given items to a list. See the example below. 

 

*** Settings ***
Library           Collections

*** Test Cases ***
Convert To List Test
    ${tup1}    Set Variable    a    b    c    d    sm
    @{MyList}=    Convert To List    ${tup1}
    Log List    ${MyList}
    ${ListLength}=    Get Length    ${MyList}
    Log    'List Size is : ' ${ListLength}
    List Should Contain Value    ${MyList}    sm
 

Run the script above and see the result

Starting test: RobotCollectionsExample.Collections Keyword Test Suite.Convert To List Test
20150416 23:42:46.834 :  INFO : ${tup1} = [u'a', u'b', u'c', u'd', u'sm']
20150416 23:42:46.834 :  INFO : @{MyList} = [ a | b | c | d | sm ]
20150416 23:42:46.834 :  INFO : 
List length is 5 and it contains following items:
0: a
1: b
2: c
3: d
4: sm
20150416 23:42:46.844 :  INFO : Length is 5
20150416 23:42:46.844 :  INFO : ${ListLength} = 5
20150416 23:42:46.844 :  INFO : 'List Size is : ' 5
Ending test:   RobotCollectionsExample.Collections Keyword Test Suite.Convert To List Test

In the example above, we define a variable ${tup1} that contains few values: 'a','b','c','d','sm'; and then we convert the variable to a list @{MyList}; we logged list length and verified that the list contained the value sm.