2

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 Answer 1

3

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

2 Comments

Awesome. This is the easiest way! By the way, my purpose is ignore TEMPLATE and TEARDOWN if keyword in SETUP return false. I tried run keyword Get Exist Element both inside Template and Teardown. It worked. Is there any better way? Thank you so much!
@HieuNguyen Doing it in the setup is the best way I think. That is the righ place to to decisions and preparations prior test run.

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.