Create an Empty List and push data in an Iteration using Robot Framework

24,828

In your code you missed the declaration, in other words you need to create a List using the keyword Create List

To declare a List you need to use the following code

@{ScoreList}=    Create List

The Complete Code is

*** Settings ***
Library    Selenium2Library
Library    Collections

*** Keywords ***
Parent Routine
    @{ScoreList}=    Create List
    : For    ${i}     IN RANGE    1    5
    \    Append To List    ${ScoreList}    ${i}
    #\    Some other manipulation
    :FOR  ${item}  IN  @{ScoreList}
    \    log to console    ${item}


*** Test Cases ***
Sample Test Case
    [Documentation]   Simple test for Collection
    Parent Routine
Share:
24,828
Admin
Author by

Admin

Updated on June 28, 2020

Comments

  • Admin
    Admin almost 4 years

    I need to make a collection which is populated in a loop. So, I need a global collection and I need to use that collection variable in For Loop using Robot Framework.

    Kindly look at the code

    *** Settings ***
    Library    Selenium2Library
    Library    Collections
    
    *** Keywords ***
    Parent Routine
        ${ScoreList} ???
        : For    ${i}     IN RANGE    1    5
        \    Append To List    ${ScoreList}    ${i}
        #\    Some other manipulation
    
    
    *** Test Cases ***
    Sample Test Case
        [Documentation]   Simple test for Collection
        Parent Routine
    

    I referred the http://robotframework.org/robotframework/latest/libraries/Collections.html

    Kindly assist me how to achieve this.