How to write a loop while in Robot Framework

前提是你 提交于 2020-06-10 03:32:56

问题


I make my first simple test case, and I have one problem.

Is it possible write a loop in Robot Framework?

I want to retrieve the value from the address and the address of the modified variable "i". I want to perform until such an address exists, because it is a row in the table.

${f1}       A
${f_temp}   B

While   ${f1} != ${f_temp}
or
While element xpath=//${i} is visible


\  ${F_temp}                Get Text     xpath=//${i}
\  ${i}                     ${i}+1
\  Run Keyword And Continue On Failure   Should be equal  ${f_temp}  ${f1}

Any ideas?


回答1:


Robot Framework does not have a while loop. You must use the FOR-loop and "exit for loop if" keywords to exit. It will run in a finite time, but if you select a large enough number in range, it is close enough for practical purposes.

*** Test Cases ***
For Test
    :FOR    ${i}    IN RANGE    999999
    \    Exit For Loop If    ${i} == 9
    \    Log    ${i}
    Log    Exited



回答2:


You might be looking for the Wait Until Keyword Succeeds keyword, which enables you to do a similar construction to a while loop. It is much more readable than FOR cycles with conditional exiting.

You then use your custom keyword, which fails when you need to end the "loop".




回答3:


As the above answer said, Robot doesn't support native WHILE loop. But this one may help if you insist. https://github.com/robotframework/robotframework/issues/3235



来源:https://stackoverflow.com/questions/36328595/how-to-write-a-loop-while-in-robot-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!