无法将Imagemagick上的图像与Windows环境中的机器人框架进行比较

时间:2017-10-16 15:25:27

标签: imagemagick robotframework

我正在使用Imagemagick比较Windows环境中的两个屏幕截图。

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

   *** Settings ***
Library   String
Library   OperatingSystem

*** Variables ***
${IMAGE_COMPARATOR_COMMAND}   C:\\"Program Files"\\ImageMagick-7.0.7-Q16\\convert.exe


*** Test Cases ***
Image Comparison Ok
  Compare Images    C:/Users/user/imagecompare/Test/src/reference-screenshots/reference-1.png    C:/Users/user/imagecompare/Test/src/test-screenshots/test-1.png   0.1


Image Comparison NOk
  Compare Images    C:/Users/user/imagecompare/Test/src/reference-screenshots/reference-1.png    C:/Users/user/imagecompare/Test/src/test-screenshots/test-1.png   0.1

*** Keywords ***
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              Executing: ${COMMAND}
   ${RC}            ${OUTPUT}=     Run And Return Rc And Output     ${COMMAND}
   Log              Return Code: ${RC}
   Log              Return Output: ${OUTPUT}
   ${RESULT}        Evaluate    ${OUTPUT} < ${Allowed_Threshold}
   Should be True   ${RESULT}

但是得到以下问题:

    KEYWORD BuiltIn . Log Return Output: ${OUTPUT}
Documentation:  
Logs the given message with the given level.
Start / End / Elapsed:  20171016 15:45:38.561 / 20171016 15:45:38.562 / 00:00:00.001
15:45:38.561    INFO    Return Output: The system cannot find the path specified.   
00:00:00.003KEYWORD ${RESULT} = BuiltIn . Evaluate ${OUTPUT} < ${Allowed_Threshold}
Documentation:  
Evaluates the given expression in Python and returns the results.
Start / End / Elapsed:  20171016 15:45:38.562 / 20171016 15:45:38.565 / 00:00:00.003
15:45:38.563    FAIL    Evaluating expression 'The system cannot find the path specified. < 0.1' failed: SyntaxError: invalid syntax (<string>, line 1)

2 个答案:

答案 0 :(得分:2)

如果您想在ImageMagick v7中使用&#34; legacy&#34; convert命令,则需要在安装 ImageMagick 那说&#34;安装传统工具&#34;

enter image description here

或者,使用以下新命令:

magick input.png ... output.png

而不是:

convert input.png ... output.png

因此,如果您知道如何将配置变量IMAGE_COMPARATOR_COMMAND更改为C:\\"Program File"\\ImageMagick-7.0.7-Q16\\magick,则可以在不重新安装ImageMagick的情况下执行此操作。

答案 1 :(得分:0)

$ {IMAGE_COMPARATOR_COMMAND} C:/“程序文件” /ImageMagick-7.0.10-Q16/convert.exe 参考 测试 -metric RMSE-比较-format“ %[distortion]”信息:

替换上面的IMAGE_COMPARATOR_COMMAND,并为您的路径进行适当的更改。 它为我工作。 谢谢