Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

increase value of variable in iteration of for loop robot framework

Tags:

I need to increase ${success_num} test case variable in For Loop: But it is always 0, even after I add 1 to it. It's like it's been reset after each iteration. How can I increase its value?

*** Test Cases ***
    ...
    ...
    Set Test Variable    ${success_num}    ${0}
    App For Port    ${actual_app}
    ...
    ...

*** Keywords ***
App For Port    [Arguments]    ${app}
    : FOR    ${port_num}    IN    1    2
    \    ${PorF}    ${message}    Run Keyword And Ignore Error    applicationcontrol.Launch application    ${app}    ${port_num}
    \    Continue For Loop If    '${PorF}'=='FALSE'
    \    ${status}    Run Keyword And Return Status    Check launching status    ${app}    ${port_num}
    \    Continue For Loop If    '${status}'=='False'
    \    Run Keyword If    '${status}'=='True'   Add Success
    \    Exit For Loop

Add Success
    ${success_num}    Set Variable    ${success_num+1}
like image 306
Henry Avatar asked Dec 06 '16 16:12

Henry


2 Answers

You don't have to call a keyword to increase success_num:

App For Port    [Arguments]    ${app}
    : FOR    ${port_num}    IN    1    2
    \    ${PorF}    ${message}    Run Keyword And Ignore Error    applicationcontrol.Launch application    ${app}    ${port_num}
    \    Continue For Loop If    '${PorF}'=='FALSE'
    \    ${status}    Run Keyword And Return Status    Check launching status    ${app}    ${port_num}
    \    Continue For Loop If    '${status}'=='False'
    \    ${success_num} =  Run Keyword If    ${status}    Set Variable  ${success_num}+1    ELSE    Set Variable    ${success_num}
    \    ${temp} =  Run Keyword If    ${status}    Evaluate  ${success_num}+1    ELSE    Evaluate    ${success_num}
    \    Set Test Variable  ${success_num}  ${temp}
    \    Exit For Loop
like image 130
Laurent Bristiel Avatar answered Sep 26 '22 16:09

Laurent Bristiel


Change the keyword Add Success to:

Add Success
    ${temp}    Evaluate    ${success_num} + 1
    Set Test Variable    ${success_num}    ${temp}
like image 36
Henry Avatar answered Sep 25 '22 16:09

Henry