覆盖Robot Framework中的默认错误消息

时间:2020-04-22 09:23:17

标签: python robotframework

我正在Robot Framework中编写一个自定义Python库,在这里我使用AppiumLibrary中的关键字:Element Should Contain Text

如果该元素不包含文本,则会收到如下错误消息:Element '<appium.webdriver.webelement.WebElement (session="d16b060d-e793-41a4-8cd6-3747434358f5", element="0.8110975792933841-31")>' should have contained text '0.0' but its text was '0'.

嗯,这不是一个非常友好的信息,我想实现以下目标:Element with locator ... should have contained text '0.0' but its text was '0'.

我在库中有一些自定义异常,并且引发了这些异常,但是在这种特定情况下,我无法检索元素的原始值来构造这样的错误消息。

带有自定义例外的示例:

        try:
            self.appiumlib.click_element(locator=element)
        except:
            raise ElementNotFoundException("Element with locator {} is not found!")

我的问题是,重写这些错误消息的最优雅的方法是什么?如果解决方案引发了自定义异常,我该如何访问元素的当前文本?

0 个答案:

没有答案
相关问题