5

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}

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

3 Comments

This is not working. It shows INFO ${success_num} = 0+1, yet it's always 0
I changed your code to this: Run Keyword If ${status} Set Test Variable ${success_num} ${success_num}+1 ELSE Set Test Variable ${success_num} ${success_num} and ran it. then it shows ${success_num} = 0+1 in the 1st iteration and ${success_num} = 0+1+1 in the 2nd iteration. and when I finally do ${fail_num} = BuiltIn . Evaluate ${total_num} - ${success_num} it gives me 7. this is ridiculous
@henry oh yes, I should have used "evaluate" instead of "Set Variable" (like you show in the other answer). I updated my answer accordingly.
1

Change the keyword Add Success to:

Add Success
    ${temp}    Evaluate    ${success_num} + 1
    Set Test Variable    ${success_num}    ${temp}

Comments

0

I recommend creating a Python function:

def Increment_Variable(p_num):
    return  int(p_num) + 1

and calling it as

${counter}=  Increment Variable  ${counter}
 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.