有没有办法在机器人框架中没有任何项目匹配的情况下检查循环耗尽?

时间:2018-05-30 11:33:10

标签: robotframework

select msgbox by title and check
[Arguments]    ${title}    ${msg}
@{wins}    Get Window Handles
:FOR    ${win}    IN    @{wins}
\    Select Window    ${win}
\    ${current_win_title}    Get Title
\    run keyword if    "${current_win_title}" == "${title}"    run keywords    Element Text Should Be    contentTD    ${msg}
\    ...    AND    Exit For Loop

嗨,我使用SeleniumLibrary和robotframework来测试网站,我需要通过窗口标题切换到特定窗口并检查窗口中的元素文本。

我的问题是在某些情况下所有窗口都与for循环中的if条件不匹配且循环耗尽,有没有办法检查这种情况并再次运行for循环或剂量机器人框架for循环有其他在这种情况下参与for循环?

1 个答案:

答案 0 :(得分:1)

使用布尔变量是条件满足,并在循环后检查其值:

select msgbox by title and check
[Arguments]    ${title}    ${msg}

@{wins}    Get Window Handles
${found}=    Set Variable    ${False}
:FOR    ${win}    IN    @{wins}
\    Select Window    ${win}
\    ${current_win_title}    Get Title
\    ${found}=    Set Variable If     "${current_win_title}" == "${title}"    ${True}   ${False}
\    run keyword if    ${found}    run keywords    Element Text Should Be    contentTD    ${msg}
\    ...    AND    Exit For Loop

Run Keyword If    not ${found}    Fail      The title was not found