如何从Robot Framework获取错误消息?

时间:2017-07-22 09:46:18

标签: robotframework

当我使用Robot Framework编写测试用例时,我使用Robot Framework API logger.error(msg, html=False)编写了一些错误日志,测试完成后,如何获取错误消息?

例如,测试完成后,日志如下: enter image description here

如何获取红色矩形标记的错误消息?

2 个答案:

答案 0 :(得分:0)

@Alex Bruce。我遇到了同样的问题。使用"运行关键字并忽略错误"面前可变。该变量将具有您正在寻找的失败结果。

> *** Settings *** Documentation     Test Suite Teardown    Close All Browsers Library           Selenium2Library    timeout=10
> 
> *** Variables *** ${BROWSER}        chrome ${SLEEP}          3
> 
> *** Test Cases *** Testing
>     Error Logging
> 
> *** Keywords *** Open Google
>     Open Browser    http://google.com/    ${BROWSER}
>     Wait Until Page Contains    Damn    timeout=1
> 
> Error Logging
>     ${ErrorChk} =    Run Keyword And Ignore Error    Open Google
>     log    ${ErrorChk[1]}

Starting test: Error.Testing
20170731 17:57:13.874 :  INFO : Opening browser 'chrome' to base url 'http://google.com/'
20170731 17:57:19.131 :  INFO : </td></tr><tr><td colspan="3"><a href="selenium-screenshot-1.png"><img src="selenium-screenshot-1.png" width="800px"></a>
20170731 17:57:19.132 :  FAIL : Text 'Damn' did not appear in 1 second
20170731 17:57:19.133 :  INFO : ${ErrorChk} = ('FAIL', u"Text 'Damn' did not appear in 1 second")
20170731 17:57:19.133 :  INFO : Text 'Damn' did not appear in 1 second
Ending test:   Error.Testing

答案 1 :(得分:0)

您好@AlexBruce也许您可以使用此KW:

Run Keyword If    '${status}'=='FAIL'    FAIL    msg=${message}

您可以选择$ {message}中的消息