Multiple list variables in :FOR LOOP

3,251 views
Skip to first unread message

Ergo Saar

unread,
Aug 8, 2013, 10:32:21 AM8/8/13
to robotframe...@googlegroups.com
hei again,
wondering if it is possible to add more then one variable in for loop. 

Example i did is not working, it will take the username as password. 

*** Test Cases ***
Test Login
    Open Browser    ${Test_URL}
    : FOR    ${user}    ${password}    IN    @{users}    @{passwords}
    \    Login
    \    Logout


*** Keyword ***
Login
    Input Text    name=userName    ${user}
    Input Text    name=password    ${password}
    Click Button    Login

Logout
    Click Image    alt=Logout

Kevin O.

unread,
Aug 8, 2013, 11:30:42 AM8/8/13
to robotframe...@googlegroups.com
Your data is stored in separate lists and the syntax requires the data to be interleaved in a single list.
There are several solutions to this problem. Here are two that use your existing data format and two that require storing the data differently:

    ${users}    Create List    foo    bar
    ${passwords}    Create List    saz    voo

    # zipping lists (makes data interleaved)
    ${logins}    Evaluate    [val for pair in zip(${users}, ${passwords}) for val in pair]
    :FOR    ${user}    ${password}    IN    @{logins}
    \    Log    user: ${user} password: ${password}

    # using a counter
    ${login count}    Get Length    ${users}
    :FOR    ${i}    IN RANGE    ${login count}
    \    Log    user: ${users[${i}]} password: ${passwords[${i}]}

    # using an alternative format for storing the data - interleaved list
    ${logins}    Create List    foo    saz    bar    voo
    :FOR    ${user}    ${password}    IN    @{logins}
    \    Log    user: ${user} password: ${password}

    # another alternative format for storing the data - dictionaries
    ${user 1}    Create Dictionary    user    foo    password    saz
    ${user 2}    Create Dictionary    user    bar    password    voo
    ${logins}    Create List    ${user 1}    ${user 2}
    :FOR    ${login}    IN    @{logins}
    \    Log    user: ${login['user']} password: ${login['password']}

prameet rathod

unread,
Aug 2, 2016, 9:08:35 PM8/2/16
to robotframework-users
Hello! This link is not working. I need to use multiple login and passwords to test a website. Can someone provide some material on that? Thanks!

Hélio Guilherme

unread,
Aug 3, 2016, 4:01:58 AM8/3/16
to robotframework-users

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages