2
votes

I'm trying to create a variable in Test Setup but it make error

*** Test Cases ***    
Set Volume Normalisation Level
[Setup]     Run Keywords     ${is_exist}=    Get Exist Element

            ...         AND             Pass Execution If   "${is_exist}" == "True"    Element is not exist
[Template]  Set Volume Normalisation Level
    value=25    actual_value=25
    value=50    actual_value=50
    value=75    actual_value=75
    value=100    actual_value=100
*** Keywords ***
Get Exist Element
    ${present}=    Run Keyword And Return Status    Page Should Contain Element   xpath://div[text()="Normalization"]
    Return From Keyword     ${present}

Set Volume Normalisation Level
    [Arguments]  ${value}  ${actual_value}
    Drag Vol Norm Slider To  ${value}
    Sleep  .5
    Vol Norm Slider Value Should Be  ${actual_value}

=> variable ${is_exist} not found.

Although I tried with Set Test Variable but it didn't work with keyword

*** Test Cases ***    
[Setup]     Run Keywords    Set Test Variable    ${is_exist}    Get Exist Element
            ...         AND             Pass Execution If   "${is_exist}" == "True"    Element is not exist

=> ${is_exist} get a string value: Get Exist Element How can I create variable in Test Setup get value from Keyword

1

1 Answers

3
votes

The easiest way is to create a new user keyword instead of using Run Keywords. In your case for example:

*** Keywords ***
My Test Setup Keyword
    ${is_exist}=    Get Exist Element
    Pass Execution If   "${is_exist}" == "True"    Element is not exist

*** Test Cases ***
Set Volume Normalisation Level
    [Setup]    My Test Setup Keyword
    # Rest of the test case