How to ignore Get Table Text from Cell, if xpath of cell not match

孤人 提交于 2019-12-13 13:58:05

问题


How to ignore Get Table Text from Cell, if xpath of cell not match ? Becuase i want my test case still continues testing .

 ${tableFinal}    Set Variable   xpath=/html/body/div[2]/div[3]/div/form/table[3]
 ${totalPayAmount}      Get Table Text from Cell     ${tableFinal}         1   2

Thanks you


回答1:


Using either Run Keyword And Continue On Failure or Run Keyword And Ignore Error can help with this. In the documentation the entire family of Run Keyword .... keywords.

The difference between the two is that one just returns the value, whereas the other also provides the status of the Keyword execution.

*** Test Cases ***
Test Case
    ${CoF_Pass_1}    Run Keyword And Continue On Failure    KW Pass
    ${CoF_Fail}      Run Keyword And Continue On Failure    KW Fail
    ${CoF_Pass_2}    Run Keyword And Continue On Failure    KW Pass

    ${IE_Pass_1}    Run Keyword And Ignore Error    KW Pass
    ${IE_Fail}      Run Keyword And Ignore Error    KW Fail
    ${IE_Pass_2}    Run Keyword And Ignore Error    KW Pass 

*** Keywords ***
KW Pass
    [Return]    SomeRandomValue
KW Fail
    Fail    SomeFaileMessage

This then results into:

Starting test: Test Case
INFO : ${CoF_Pass_1} = SomeRandomValue
FAIL : SomeFaileMessage
INFO : ${CoF_Fail} = None
INFO : ${CoF_Pass_2} = SomeRandomValue
INFO : ${IE_Pass_1} = ('PASS', u'SomeRandomValue')
FAIL : SomeFaileMessage
INFO : ${IE_Fail} = ('FAIL', u'SomeFaileMessage')
INFO : ${IE_Pass_2} = ('PASS', u'SomeRandomValue')
Ending test: Test Case


来源:https://stackoverflow.com/questions/47446777/how-to-ignore-get-table-text-from-cell-if-xpath-of-cell-not-match

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