我的以下代码是否有替代方法?

时间:2019-08-24 06:41:05

标签: robotframework

我正在寻找另一种更聪明的方式来实现以下操作

***Keywords***

Insert Values
[Documentation]  Keyword is used to insert value
   ${Status1}               Run Keyword and Return Status       Wait Until Element is Visible     ${ONPDonorLocator}                1s
   ${Status2}               Run Keyword and Return Status       Wait Until Element is Visible     ${CustomerScoreLocator}           1s
   ${Status3}               Run Keyword and Return Status       Wait Until Element is Visible     ${ContractDurationLocator}        1s
   ${Status4}               Run Keyword and Return Status       Wait Until Element is Visible     ${OptionsInstalledLocator}        1s
   ${Status5}               Run Keyword and Return Status       Wait Until Element is Visible     ${OrderAddsDeletesLocator}        1s
   ${Status6}               Run Keyword and Return Status       Wait Until Element is Visible     ${SiteCategoryLocator}            1s
   Run Keyword If          '${Status1}'=='True'             Wait and Click    ${ONPDonor}               ${LocatorWaitTime}
   Run Keyword If          '${Status2}'=='True'             Wait and Click    ${CustomerScore}          ${LocatorWaitTime}
   Run Keyword If          '${Status3}'=='True'             Wait and Click    ${ContractDuration}       ${LocatorWaitTime}
   Run Keyword If          '${Status4}'=='True'             Wait and Click    ${OptionsInstalled}       ${LocatorWaitTime}
   Run Keyword If          '${Status5}'=='True'             Wait and Click    ${OrderAddsDeletes}       ${LocatorWaitTime}
   Run Keyword If          '${Status6}'=='True'             Wait and Click    ${SiteCategory}           ${LocatorWaitTime}

预期: 是否可以单击具有'${Status}'=='True'的定位器,而不是编写Status1Status2Status3等? 我不想写我上面写的方式。明天,如果我不得不再检查几个定位器的状态,那么这些行将继续增加。

注意:我仍在学习,欢迎提出任何建议。

1 个答案:

答案 0 :(得分:1)

是的,通过使用循环并仅存储可见的定位器;然后遍历存储的内容,然后单击它们:

${visible}=    Create List
FOR    ${locator}     IN     ${ONPDonorLocator}    ${CustomerScoreLocator}    # etc, the others
    ${Status}    Run Keyword and Return Status       Wait Until Element is Visible     ${locator}
    Run Keyword If    ${Status}    Append To List    ${visible}    ${locator}
END

FOR    ${locator}    IN    @{visible}
    Wait and Click    ${locator}
END

当您有更多元素要等待可见性然后单击时,只需在第一个循环中添加它们即可。

相关问题