【问题标题】:How to compare image with robot framework如何将图像与机器人框架进行比较
【发布时间】:2018-03-18 18:57:34
【问题描述】:

我是机器人框架的新手,正在尝试比较两个图像。我做了一些研发,发现现有的 RobotAppEyes 库可以帮助比较图像。

链接1: http://navinet.github.io/Robot-AppEyes/RobotAppEyes-KeywordDocumentation.html#Compare%20Image

链接2: https://github.com/NaviNet/Robot-AppEyes

我使用相同的库来比较图像,但在比较两个图像时遇到以下问题。

** Settings ***
Library                 Selenium2Library
Library                 RobotAppEyes

*** Test Cases ***
RobotAppEyes 1.0 Test
    Open Browser    http://www.google.com.uk    gc      
    Maximize Browser Window     
    Open Eyes Session   http://www.google.com.uk    RobotAppEyes_Test   NaviNet_RobotAppEyes_Test1  JkaJK50dp1NTEhPufx08SaztsXmfBZas8z0MZVcaqcA110  
    # ${isOpen}=    Eyes Session Is Open                    
    # Log    ${isOpen}
    Compare Image        C:\\Users\\Downloads\\logo.png       C:\\Users\\user\\Downloads\\logo.png     ignore_mismatch=False    includeEyesLog=False     httpDebugLog=False
    Check Eyes Region   .//*[@id='splash']/div[1]       500     120     logo
    Run Keyword If  ${isOpen}==True Close Eyes Session
    Close Eyes Session

执行机器人脚本后的响应:

RobotAppEyes 1.0 Test                                                 | FAIL |
TypeError: _create_match_data_bytes() takes at least 6 arguments (5 given)
------------------------------------------------------------------------------

谁能帮助我在机器人框架的帮助下进行图像比较?

【问题讨论】:

  • _create_match_data_bytes 看起来可能是比较图像的子功能,但在阅读文档后,我找不到比较图像没有足够参数的原因。您是否碰巧知道它是否是您代码不同部分的子功能?
  • 是的,我想是的,请在下面的链接中找到更多详细信息:github.com/NaviNet/Robot-AppEyes/blob/master/RobotAppEyes/… 另外,如果有人知道任何其他具有工作示例的方法,请告诉我使用机器人框架进行图像比较。
  • 嗯...您是否正在寻找可以精确比较两个图像并在像素不完全相同时返回失败的东西?
  • 是的,我正在尝试比较两个图像。请帮助我提供工作示例。
  • 只是为了澄清一件事,以便我知道我的解决方案对您有用,您的眼睛是否可以同时在屏幕上看到两张图片?

标签: python robotframework


【解决方案1】:

这是我在 cmets 讨论后的回答。这不是 Dipak 问题的完美答案,我意识到这一点,但他让我发布它。

 from robot.libraries.BuiltIn import BuiltIn
    import pyautogui as pag

class click_by_image(object):
    def __init__(self):
        self.selenium_lib = None

    def click_by_image(self, image_name):
        """
        Click the center of a rectangle on the screen given the
        image_name of the image rectangle to search for
        :param image_name: Path to image
        """
        #   If ExtendedSelenium2Library instance is undefined
        if self.selenium_lib is None:
            # Instantiate ExtendedSelenium2Library
            self.selenium_lib = BuiltIn().get_library_instance('ExtendedSelenium2Library')
        pag.click(pag.locateCenterOnScreen(str(image_name)))

这是它来自的完整关键字。小图片很滑(~20px x ~40px 是有问题的地方,虽然我没有精确测量它),但它适用于大图片,假设屏幕上存在确切的像素集。这是屏幕上的任何地方,而不仅仅是在 DOM 中,所以这是我用来在选项卡之间单击并与普通桌面交互的地方。

要使用此关键字,请将图片的本地副本作为绝对路径或相对路径提供给 click_by_image(),两者都可以,并且会按照文档说明进行。

我提到的具体代码是pag.locateCenterOnScreen(),来自pyautogui。它返回一组坐标,所以如果你没有得到这些坐标,那么你的图像就不会出现在屏幕上。如果你这样做了,那么你就知道 a) 你的图像存在 b) 它在哪里。

【讨论】:

    【解决方案2】:

    能够使用 image Magic 解决此问题

    Compare Images
        [Arguments]      ${Reference_Image_Path}    ${Test_Image_Path}    ${Allowed_Threshold}
        ${TEMP}=         Replace String     ${IMAGE_COMPARATOR_COMMAND}    __REFERENCE__     ${Reference_Image_Path}
        ${COMMAND}=      Replace String     ${TEMP}    __TEST__     ${Test_Image_Path}
        Log              ${Allowed_Threshold}
        Log              Executing: ${COMMAND}
        ${RC}            ${OUTPUT}=     Run And Return Rc And Output    ${COMMAND}
        # ${RC}            ${OUTPUT}=     Run And Return Rc And Output    C:/"Program Files"/ImageMagick-7.0.7-Q16/convert.exe    C:/Users/user/imagecompare/Test/src/reference-screenshots/reference-1.png    C:/Users/user/imagecompare/Test/src/reference-screenshots/reference-11.png -metric RMSE -compare -format "%[distortion]" info:
        Log              Return Code: ${RC}
        Log              Return Output: ${OUTPUT}
        ${RESULT}        Evaluate    ${OUTPUT} < ${Allowed_Threshold}
        Should be True   ${RESULT}
    

    https://blog.codecentric.de/en/2017/09/robot-framework-compare-images-screenshots/

    【讨论】:

      猜你喜欢
      • 2018-03-28
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 2011-06-20
      • 2018-05-08
      • 2012-01-27
      • 2021-04-15
      相关资源
      最近更新 更多