Robotframework + Selenium2Library 本地 Py 关键字 Run_on_failure
我在使用自定义的Robot Framework关键字时,遇到了一些问题,想让selenium2library在失败时触发运行。
我写了一个Python关键字,按理说它应该正常工作,但当我抛出一个AssertionError(断言错误)时,Selenium2Library的Run_On_Failure(失败时运行)关键字没有被调用。
我还尝试把这个关键字放在一个用户定义的Robot Framework关键字里,但Run_On_Failure还是没能触发。不过,当我让S2L的关键字失败时,Run_On_Failure就能正常工作,这让我很困惑。
我希望在我的RFpy关键字失败时,Run_On_Failure能够被调用。有没有人能给点建议?
这是我的关键字:
def compare_text(self, actualString, expectedString):
"""Compares two strings of text, this differs from the Selenium2Library
text compare routines because we do not require an element locator, just
the `actual` and `expected` strings. String matching failure will cause
the test to Assert an error and the test to fail.
"""
print("Actual Here: %s") % (actualString)
print("Expected Here: %s") % (expectedString)
if actualString != expectedString:
raise AssertionError("ERROR: Actual and Expected strings don't match!")
1 个回答
1
这个解决办法是一个内置的RF关键字,叫做“如果测试失败则运行关键字”。