在机器人框架中使用For循环

时间:2015-12-10 03:33:59

标签: robotframework

我无法在Body中传递变量$ {ELEMENT}值,只是从列表中取出最后一个值。 我想迭代所有三个值

Create Http Context    localhost:8080    http
Set Request Header    Content-Type    application/json
@{RecipientPhoneNumber} =    Create List    2162692764    21    2162792985
: FOR    ${ELEMENT}    IN    @{RecipientPhoneNumber}
\    Log    ${ELEMENT}
Set Request Body  {"id":"123456-789", "value":"${ELEMENT}"}

1 个答案:

答案 0 :(得分:3)

将Set request body关键字放入for循环:

Create Http Context    localhost:8080    http
Set Request Header    Content-Type    application/json
@{RecipientPhoneNumber} =    Create List    2162692764    21    2162792985
: FOR    ${ELEMENT}    IN    @{RecipientPhoneNumber}
\    Log    ${ELEMENT}
\    Set Request Body  {"id":"123456-789", "value":"${ELEMENT}"}