6

我需要制作一个循环填充的集合。所以,我需要一个全局集合,我需要在 For Loop 中使用 Robot Framework 使用该集合变量。

请看代码

*** 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

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

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

4

1 回答 1

13

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

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

@{ScoreList}=    Create List

完整代码是

*** 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
于 2017-06-28T05:17:17.240 回答