':For' loop under 'Run Keywords' not recognized even after using AND operator

48 views
Skip to first unread message

kmr21

unread,
Dec 11, 2016, 2:07:23 PM12/11/16
to robotframework-users
Hi All,

This is part of my code where I've to pass for loop to a run keywords and I get an an error for is not an keyword, but anything until AND is considered as one set and thus for loop should work I believe.

My below approach is hack for lack of switch case in robot - if condition is A i will need to a set of operations and if condition is B another set of operations I do.

Now here in a certain condition, my code has a for loop which isn't recognised by Run Keywords. Any help would get me to fix this up - thanks in advance.

My Code:
\   Run keyword If    '${server}' == '${session1_ip}'    cli    ${session1}    cd /tmp
        \   ${output}    Run keyword If    '${server}' == '${session1_ip}'    cli    ${session1}    cat ${filename} | grep ${filter}  timeout_exception=20
        \   @{all_lines}    Run keyword If    '${server}' == '${session1_ip}'    split string    ${output}    \n
        \   ${first_line}    Run keyword If    '${server}' == '${session1_ip}'    remove from list    ${all_lines}    0
        \   ${line_count}    Run keyword If    '${server}' == '${session1_ip}'    get line count    ${output}
        \   ${new_lc}    Run keyword If    '${server}' == '${session1_ip}'    evaluate    ${line_count} - 1
        \   Run keyword If    '${server}' == '${session1_ip}'    run keywords  :FOR    ${i}    IN RANGE    0  ${new_lc}  AND  ${line}    Run keyword If    '${server}' == '${session1_ip}'    get from list    ${all_lines}    ${i}  AND  ${log_level}    Run keyword If    '${server}' == '${session1_ip}'    get from list    ${line}    0  AND  Run keyword If    '${server}' == '${session1_ip}'    run keyword  AND  run keyword if    '${log_lvl}' < '${log_lvl_code}'    run keyword  log    Log level generated in box is less than configured log levels

Thanks,
KMR21

Tatu Aalto

unread,
Dec 12, 2016, 11:28:31 AM12/12/16
to badr...@gmail.com, robotframework-users
Ugh

Generally speaking, that kind of complex code would be better off as a library keyword. It would be more readable and therefore more maintainable.

That being said, the for loop can not be used as keyword. If you really want to use it, mask it under a keyword and then call the keyword.

-Tatu
Send from my mobile

--
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-users+unsub...@googlegroups.com.
To post to this group, send email to robotframework-users@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

kmr21

unread,
Dec 26, 2016, 9:21:47 AM12/26/16
to robotframework-users
Thanks Tatu for the clarification. 

Thanks,
KMR21


On Monday, December 12, 2016 at 9:58:31 PM UTC+5:30, Tatu Aalto wrote:
Ugh

Generally speaking, that kind of complex code would be better off as a library keyword. It would be more readable and therefore more maintainable.

That being said, the for loop can not be used as keyword. If you really want to use it, mask it under a keyword and then call the keyword.

-Tatu
Send from my mobile
On Dec 11, 2016 21:07, "kmr21"  wrote:
Hi All,

This is part of my code where I've to pass for loop to a run keywords and I get an an error for is not an keyword, but anything until AND is considered as one set and thus for loop should work I believe.

My below approach is hack for lack of switch case in robot - if condition is A i will need to a set of operations and if condition is B another set of operations I do.

Now here in a certain condition, my code has a for loop which isn't recognised by Run Keywords. Any help would get me to fix this up - thanks in advance.

My Code:
\   Run keyword If    '${server}' == '${session1_ip}'    cli    ${session1}    cd /tmp
        \   ${output}    Run keyword If    '${server}' == '${session1_ip}'    cli    ${session1}    cat ${filename} | grep ${filter}  timeout_exception=20
        \   @{all_lines}    Run keyword If    '${server}' == '${session1_ip}'    split string    ${output}    \n
        \   ${first_line}    Run keyword If    '${server}' == '${session1_ip}'    remove from list    ${all_lines}    0
        \   ${line_count}    Run keyword If    '${server}' == '${session1_ip}'    get line count    ${output}
        \   ${new_lc}    Run keyword If    '${server}' == '${session1_ip}'    evaluate    ${line_count} - 1
        \   Run keyword If    '${server}' == '${session1_ip}'    run keywords  :FOR    ${i}    IN RANGE    0  ${new_lc}  AND  ${line}    Run keyword If    '${server}' == '${session1_ip}'    get from list    ${all_lines}    ${i}  AND  ${log_level}    Run keyword If    '${server}' == '${session1_ip}'    get from list    ${line}    0  AND  Run keyword If    '${server}' == '${session1_ip}'    run keyword  AND  run keyword if    '${log_lvl}' < '${log_lvl_code}'    run keyword  log    Log level generated in box is less than configured log levels

Thanks,
KMR21

--
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-users+unsub...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages