使用Robot Framework创建一个空列表并在迭代中推送数据

3 selenium pycharm robotframework selenium2library robotframework-ide

我需要进行一个循环填充的集合。因此,我需要一个全局集合,并且需要使用Robot Framework在For Loop中使用该集合变量。

请看一下代码

*** 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
Run Code Online (Sandbox Code Playgroud)

我提到了http://robotframework.org/robotframework/latest/libraries/Collections.html

请协助我如何实现这一目标。

B.B*_*dan 5

在您的代码中,您错过了声明,换句话说,您需要使用关键字创建一个列表 Create List

要声明列表,您需要使用以下代码

@{ScoreList}=    Create List
Run Code Online (Sandbox Code Playgroud)

完整的代码是

*** 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
Run Code Online (Sandbox Code Playgroud)