如何退出Robot Framework 4.0中ride 1.7.4.2中的嵌套for循环

发布于 2025-01-12 13:40:18 字数 1051 浏览 0 评论 0原文

我想在 ${port} == 3 时退出所有嵌套的 for 循环,但是无论我使用什么关键字,例如 '退出 for 循环' 或 '退出 for 循环 if ${port} == 3' ,它仍然会继续整个嵌套的 for 循环。同时,Robot Frameworkride 告诉我“break”是保留关键字,不能使用。 我的代码如下。

*** Test Cases ***
demo_01
    ${port}    Set Variable    0
FOR    ${i}    IN RANGE    2
FOR    ${j}    IN RANGE    2
FOR    ${k}    IN RANGE    2
    ${port}    Evaluate    ${port} + 1
    Log    ${port}
    IF    ${port} == 3
    Exit FOR Loop
END
END
END
END

结果就在这里 在此处输入图像描述

它刚刚退出内部 for 循环。 :(

所以我想知道如何退出 Robot Framework Ride 中的嵌套 for 循环。谢谢大家。 顺便说一句,这是我的 pip 列表

robotframework                  4.1.2
robotframework-databaselibrary  1.2.4
robotframework-pythonlibcore    3.0.0
robotframework-ride             1.7.4.2
robotframework-selenium2library 3.0.0
robotframework-seleniumlibrary  3.0.0
robotframework-sshlibrary       3.8.0

,我的 python 版本是

C:\WINDOWS\system32>python -V
Python 3.7.9

谢谢

I wanna exit all nested for loops when ${port} == 3,however whatever keywords I use, such as
'Exit for loop' or 'Exit for loop if ${port} == 3' ,it will still continue the whole nested for loop. Meanwhile Robot Framework ride tells me that 'break' is a reserved keyword and can't be used.
My code is below.

*** Test Cases ***
demo_01
    ${port}    Set Variable    0
FOR    ${i}    IN RANGE    2
FOR    ${j}    IN RANGE    2
FOR    ${k}    IN RANGE    2
    ${port}    Evaluate    ${port} + 1
    Log    ${port}
    IF    ${port} == 3
    Exit FOR Loop
END
END
END
END

And the result is here
enter image description here

It just exited the inner for loop. :(

So I wanna know how to exit a nested for loop in Robot Framework Ride. Thank you all.
BTW here is my pip list below

robotframework                  4.1.2
robotframework-databaselibrary  1.2.4
robotframework-pythonlibcore    3.0.0
robotframework-ride             1.7.4.2
robotframework-selenium2library 3.0.0
robotframework-seleniumlibrary  3.0.0
robotframework-sshlibrary       3.8.0

And my python version is

C:\WINDOWS\system32>python -V
Python 3.7.9

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落墨 2025-01-19 13:40:18

实现此目的的最简单方法是将封闭的 FOR 循环移至关键字中,然后在满足条件时从该循环返回。在你的情况下,它看起来像这样:

*** Keywords ***
Log ports
    [Return]    Return when port 3 is reached

    ${port}    Set Variable    0
    FOR    ${i}    IN RANGE    2
        FOR    ${j}    IN RANGE    2
            FOR    ${k}    IN RANGE    2
                ${port}    Evaluate    ${port} + 1
                Log    ${port}
                IF    ${port} == 3
                    Return From Keyword
                END
            END
        END
    END

然后在测试中你只需调用上面的关键字:

*** Test Cases ***
demo_01
    Log ports

Easiest way to achieve this is to move the enclosing FOR loops into a keyword and then return from it whenever a condition is met. In your case it will look like this:

*** Keywords ***
Log ports
    [Return]    Return when port 3 is reached

    ${port}    Set Variable    0
    FOR    ${i}    IN RANGE    2
        FOR    ${j}    IN RANGE    2
            FOR    ${k}    IN RANGE    2
                ${port}    Evaluate    ${port} + 1
                Log    ${port}
                IF    ${port} == 3
                    Return From Keyword
                END
            END
        END
    END

Then in the test you just call the above keyword:

*** Test Cases ***
demo_01
    Log ports
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文