【Appium】循环等待文本

2022-01-05 16:02:00 浏览数 (1)

循环等待某个文本

循环等待某个文本在页面出现,循环xx次。

代码语言:javascript复制
wait4text
    [Arguments]    ${text}    ${xx}
    FOR    ${celldata}    IN RANGE    ${xx}
        ${status}    Run Keyword And Return Status    page should contain text    ${text}
        run keyword if    ${status}==False    sleep    2
        ...    ELSE    Exit For Loop
    END
    [Return]    ${status}

循环等待两个文本中其中一个

Appium判断二种元素出来一种即可继续,例如:如果弹出提示则点击提示,如果页面显示某字符则不需要等待弹框。

代码语言:javascript复制
循环等待其中一个文本
    [Arguments]    ${text}    ${text2}    ${xx}
    FOR    ${celldata}    IN RANGE    ${xx}
        sleep    2
        ${status1}    Run Keyword And Return Status    page should contain text    ${text}
        ${status2}    Run Keyword And Return Status    page should contain text    ${text2}
        run keyword if    ${status1}==True    Exit For Loop
        run keyword if    ${status2}==True    Exit For Loop
    END
    Return From Keyword If    ${status1}==True    1
    Return From Keyword If    ${status2}==True    2
    Return From Keyword    0

调用示例

下面是调用的例子

代码语言:javascript复制
test
    sleep    2
    click element    ${kongjianku['home']}
    Wait Until Page Contains    首页    5
    click element    ${kongjianku['page_action1']}
    Wait Until Page Contains    页面信息    5
    click element    ${kongjianku['page_action2']}
    ${dzckcxstatus}    wait4test    温馨提示    10
    run keyword if    ${dzckcxstatus}==True    click element    //*[@text="确定"]
    sleep    2
    click element    ${kongjianku['page_action3']}
    Wait Until Page Contains    页面2信息    5
    click element    ${kongjianku['page_action4']}
    ${jpckcxstatus}    wait4tests    温馨提示    起始号码    10
    run keyword if    ${jpckcxstatus}==1    click element    //*[@text="重试"]

0 人点赞