0
votes

Using Robot Framework, I am trying to create a FOR loop in which a random value is selected from the list. After the random value is selected, the page for that value is opened, then I want to do validate the data available for that party, etc. And then the loop should exit if the value is matched.

Currently, I'm able to select a random value and go to that value page but not able to perform further actions as the scripts fail as the FOR loop finds another value from the list.

@{ORGANISATIONAL_NAME}  JSK MARKETING  KEDARNATH COMOTRADE  PONDICHERRY SRI LAKSHMI

View Basic Info of the Party
    ${value} =  Evaluate  random.choice($ORGANISATIONAL_NAME)  random
    input text  ${SEARCH_BAR}  ${value}
    log to console  \nvalue: ${value}
    click element  ${SEARCH_BUTTON}
    log  ${value}
    Run Keyword If  '${value}' == 'JSK MARKETING'  click element  ${JSK_MARKETING}
     ...  ELSE IF  '${value}' == 'KEDARNATH COMOTRADE'  click element  ${KEDARNATH_COMOTRADE}
     ...  ELSE IF  '${value}' == 'PONDICHERRY SRI LAKSHMI'  click element  ${PONDICHERRY_SHRI_LAKSHMI}
     ...  ELSE  log to console  condition didn't met
    FOR  ${value}  IN  @{ORGANISATIONAL_NAME}
        log to console  ${value}
        click element  ${BASIC_INFO}
        wait until page contains  Summary
        Exit For Loop If  '${value}' == 'JSK MARKETING'
        click element  ${BASIC_INFO}
        wait until page contains  Summary
        Exit For Loop If  '${value}' == 'KEDARNATH COMOTRADE'
        click element  ${BASIC_INFO}
        wait until page contains  Summary
        Exit For Loop If  '${value}' == 'PONDICHERRY SRI LAKSHMI'
    END

The validations need to be performed over the selected random value from the list.

1
What is the error you are getting? - AutoTester213
@WojtekT The error is that first, it's taking the value say PONDICHERRY SRI LAKSHMI and when the FOR loop executes it takes another value say JSK MARKETING link - Gaurav Marothia

1 Answers

0
votes

Your problem is that you first select a random value. And then you iterate the list in the order in which it was created.

What is the reason for the for loop? Because I don't understand what you're trying to do in the loop

EDIT:

If only those 3 values ​​are going to exist on your list you could do this:

View Basic Info Of The Party
    ${value} =  Evaluate  random.choice($ORGANISATIONAL_NAME)  random
    Input Text  ${SEARCH_BAR}  ${value}
    Log To Console  \nvalue: ${value}
    Click Element  ${SEARCH_BUTTON}
    Log  ${value}
    Run Keyword If  '${value}' == 'JSK MARKETING'  Click Element  ${JSK_MARKETING}
    ...  ELSE IF    '${value}' == 'KEDARNATH COMOTRADE'  Click Element  ${KEDARNATH_COMOTRADE}
    ...  ELSE IF    '${value}' == 'PONDICHERRY SRI LAKSHMI'  Click Element  ${PONDICHERRY_SHRI_LAKSHMI}
    Log To Console  ${value}
    Click Element  ${BASIC_INFO}
    Wait Until Page Contains  Summary

If you are going to have more values ​​in the list and you only want to perform an action in one of those 3 cases try to do this:

View Basic Info Of The Party
    ${value} =  Evaluate  random.choice($ORGANISATIONAL_NAME)  random
    Input Text  ${SEARCH_BAR}  ${value}
    Log To Console  \nvalue: ${value}
    Click Element  ${SEARCH_BUTTON}
    Log  ${value}
    Run Keyword If  '${value}' == 'JSK MARKETING'  Click Element  ${JSK_MARKETING}
    ...  ELSE IF    '${value}' == 'KEDARNATH COMOTRADE'  Click Element  ${KEDARNATH_COMOTRADE}
    ...  ELSE IF    '${value}' == 'PONDICHERRY SRI LAKSHMI'  Click Element  ${PONDICHERRY_SHRI_LAKSHMI}
    ...  ELSE  Log To Console  condition didn\'t met
    Run Keyword If  '${value}' == 'JSK MARKETING' or '${value}' == 'KEDARNATH COMOTRADE' or '${value}' == 'PONDICHERRY SRI LAKSHMI'     Run Keywords
    ...  Log To Console  ${value}   AND
    ...  Click Element  ${BASIC_INFO}   AND
    ...  Wait Until Page Contains  Summary

I hope this helps.