我是机器人框架的新手,试图比较两个图像。我做了一些R
Link1:http://navinet.github.io/Robot-AppEyes/RobotAppEyes-KeywordDocumentation.html#Compare图像
Link2: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)
------------------------------------------------------------------------------
有人能借助机器人框架帮我进行图像对比吗?
这是我在评论中讨论后的回答。这不是迪帕克问题的完美答案,我意识到这一点,但他让我发布它。
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×~40px是它有问题的地方,尽管我还没有确切测量过),但是它对大图片效果很好,假设屏幕上存在精确的像素集。那是屏幕上的任何地方,不仅仅是DOM内,所以这是我用来在选项卡之间点击并与普通桌面交互的东西。
要使用此关键字,请将图片的本地副本作为绝对路径或相对路径提供给click_by_image()
,两者都可以,并且它将按文档所述工作。
我提到的具体代码是page. locateCentOnScreen()
,它来自pyautogui。它返回一组坐标,所以如果你没有得到那些坐标,那么你的图像就不会出现在屏幕上。如果你这样做了,那么你知道a)你的图像存在,b)它在哪里。
能够使用图像魔术解决此问题
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/