简体   繁体   中英

How to compare image with robot framework

I am new to robot framework and trying to compare two images. I did some R&D from my end and found that there is existing RobotAppEyes library which helps t compare images.

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

Link2: https://github.com/NaviNet/Robot-AppEyes

I am using same library to compare images but facing below issue while comparing two images.

** 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

Response after executing robot script:

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

Can anyone help me image comparison with the help of robot framework ?

This is my answer after discussion in the comments. It is not a perfect answer to Dipak's problem and I realize this, but he asked me to post it.

 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)))

That's the full keyword it comes from. It's slippery with small pictures (~20px by ~40px is where it has problems, though I haven't exactly measured it), but it works very well with large ones, assuming the exact set of pixels exists on the screen. That's anywhere on the screen, not just within the DOM, so this is what I use to click between tabs and interact with a normal desktop.

To use this keyword, feed your local copy of the picture to click_by_image() as either an absolute or relative path, either works, and it'll work as documented.

The specific code I mentioned is pag.locateCenterOnScreen() , which comes from pyautogui. It returns a set of coordinates, so if you don't get those coordinates, then your image does not appear on the screen. If you do, then you know that a) your image exists and b) where it is.

Able to resolve this issue with 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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM