AppiumLibrary:元素不应为可见关键字?

AppiumLibrary:元素不应为可见关键字?,appium,robotframework,Appium,Robotframework,在AppiumLibrary中,从版本1.4.5开始,引入了一个名为元素的非常方便的关键字。但我也在寻找该关键字的相反版本,类似于元素不应可见。既然AppiumLibrary还没有,我们有什么方法可以实现这一点吗?总是有可能扩展库的python代码,这应该不是很难。基本上,您只需要克隆元素应该是可见的关键字定义,并更改条件以执行相反的操作 但是,如果您不可能这样做,也许您可以将关键字与您提到的关键字结合使用,元素应该是可见的。在不可见的元素上使用此关键字将引发错误,在这种特定情况下,这将是期望的

AppiumLibrary
中,从版本1.4.5开始,引入了一个名为
元素的非常方便的关键字。但我也在寻找该关键字的相反版本,类似于
元素不应可见。既然AppiumLibrary还没有,我们有什么方法可以实现这一点吗?

总是有可能扩展库的python代码,这应该不是很难。基本上,您只需要克隆
元素应该是可见的
关键字定义,并更改条件以执行相反的操作

但是,如果您不可能这样做,也许您可以将关键字与您提到的关键字结合使用,
元素应该是可见的
。在不可见的元素上使用此关键字将引发错误,在这种特定情况下,这将是期望的结果

但是,这是一个可疑的工作,这将不利于你的测试的可读性,你应该首先考虑扩大图书馆本身。我尝试了他建议的两种方法,两种方法似乎都非常简单。为了将来的参考,我在这里解释这两种方法

方法1:

AppiumeLibrary/keywords
目录下,有一个名为
\u element.py
的文件,它定义了
元素应该是可见的
关键字。我能够克隆它来创建我正在寻找的新关键字

下面是定义
元素应可见的代码段

    def element_should_be_visible(self, locator, loglevel='INFO'):
        """Verifies that element identified with locator is visible.

        Key attributes for arbitrary elements are `id` and `name`. See
        `introduction` for details about locating elements.

        New in AppiumLibrary 1.4.5
        """
        if not self._element_find(locator, True, True).is_displayed():
            self.log_source(loglevel)
            raise AssertionError("Element '%s' should be visible "
                             "but did not" % locator)
    def element_should_not_be_visible(self, locator, loglevel='INFO'):
        """Verifies that element identified with locator is visible.

        Key attributes for arbitrary elements are `id` and `name`. See
        `introduction` for details about locating elements.

        New in AppiumLibrary 1.4.5
        """
        if self._element_find(locator, True, True).is_displayed():
            self.log_source(loglevel)
            raise AssertionError("Element '%s' should not be visible "
                                 "but did" % locator)
在上面的代码段旁边,您可以添加以下代码段来定义新的关键字
元素不应可见

    def element_should_be_visible(self, locator, loglevel='INFO'):
        """Verifies that element identified with locator is visible.

        Key attributes for arbitrary elements are `id` and `name`. See
        `introduction` for details about locating elements.

        New in AppiumLibrary 1.4.5
        """
        if not self._element_find(locator, True, True).is_displayed():
            self.log_source(loglevel)
            raise AssertionError("Element '%s' should be visible "
                             "but did not" % locator)
    def element_should_not_be_visible(self, locator, loglevel='INFO'):
        """Verifies that element identified with locator is visible.

        Key attributes for arbitrary elements are `id` and `name`. See
        `introduction` for details about locating elements.

        New in AppiumLibrary 1.4.5
        """
        if self._element_find(locator, True, True).is_displayed():
            self.log_source(loglevel)
            raise AssertionError("Element '%s' should not be visible "
                                 "but did" % locator)
方法2

如果不想扩展现有库,可以使用现有关键字的组合,如下所示:

${isVisible}=  Run Keyword And Return Status   Element Should Be Visible   'someElementSelector'

Should Be Equal  ${isVisible}    ${FALSE}