Selenium WebDriver Java Framework Course Limited Time Offer for $20

Selenium WebDriver Java Framework Course Limited Time Offer for $20

 

Print

Create List Robot Framework

In Robot Framework, Create List keyword is used to create a list object. To use the keyword, we need to import the library Collections.  See the example below. 

We create a list object named ${MyList} and assign values "item1", "item2", and "item3" when creating the list. Using the keyword "Append To List" to add another value "item4". We do assertion on item4. 

 

Note: we tagged the test case as "CollectionsTest".

*** Settings ***
Library           Collections

*** Test Cases ***
Create List Test Case
    [Tags]    CollectionsTest
    @{MyList}=    Create List    item1    item2    item3
    Append To List    ${MyList}    item4
    Log List    ${MyList}
    List Should Contain Value    ${MyList}    item4
 

Execute the script and see the result below:

Starting test: RobotExample.Collections Test Suite.Create List Test Case
20150415 23:51:46.481 :  INFO : @{MyList} = [ item1 | item2 | item3 ]
20150415 23:51:46.484 :  INFO : 
List length is 4 and it contains following items:
0: item1
1: item2
2: item3
3: item4
Ending test:   RobotExample.Collections Test Suite.Create List Test Case

The test passed