Package: robotframework-doctestlibrary
robotframework-doctestlibraryRobot FrameworkDocTest library.Simple Automated Visual Document Testing.Seekeyword documentationforVisual Document TestsPrint Job TestsPdf Tests (very basic)*** Settings ***LibraryDocTest.VisualTest*** Test Cases ***Compare two Images and highlight differencesCompare ImagesReference.jpgCandidate.jpgInstallation instructionspip install --upgrade robotframework-doctestlibraryOnly Python 3.X or newer is supported. Tested with Python 3.8/3.11/3.12Install robotframework-doctestlibraryInstallation viapipfrom PyPI (recommended)pip install --upgrade robotframework-doctestlibraryInstallation viapipfrom GitHubpip install git+https://github.com/manykarim/robotframework-doctestlibrary.gitorgit clone https://github.com/manykarim/robotframework-doctestlibrary.gitcd robotframework-doctestlibrarypip install -e .Install dependenciesInstall Tesseract, Ghostscript, GhostPCL, ImageMagick binaries and barcode libraries (libdmtx, zbar) on your system.Hint: Since0.2.0Ghostscript, GhostPCL and ImageMagick are only needed for rendering.psand.pclfiles.Rendering and content parsing of.pdfis done viaMuPDFIn the future there might be a separate pypi package for.pcland.psfiles to get rid of those dependencies.Linuxapt-getinstallimagemagicktesseract-ocrghostscriptlibdmtx0blibzbar0Windowshttps://github.com/UB-Mannheim/tesseract/wikihttps://ghostscript.com/releases/gsdnld.htmlhttps://ghostscript.com/releases/gpcldnld.htmlhttps://imagemagick.org/script/download.phpSome special instructions for WindowsRename executable for GhostPCL to pcl6.exe (only needed for.pclsupport)The executable for GhostPCLgpcl6win64.exeneeds to be renamed topcl6.exeOtherwise it will not be possible to render .pcl files successfully for visual comparison.Add tesseract, ghostscript and imagemagick to system path in windows (only needed for OCR,.pcland.pssupport)C:\Program Files\ImageMagick-7.0.10-Q16-HDRIC:\Program Files\Tesseract-OCRC:\Program Files\gs\gs9.53.1\binC:\Program Files\gs\ghostpcl-9.53.1-win64(The folder names and versions on your system might be different)That means: When you open the CMD shell you can run the commandsmagick.exetesseract.exegswin64.exepcl6.exesuccessfully from any folder/locationWindows error message regarding pylibdmtxHow to solve ImportError for pylibdmtxIf you see an uglyImportErrorwhen importingpylibdmtxon
Windows you will most likely need theVisual C++ Redistributable Packages for
Visual Studio 2013. Installvcredist_x64.exeif using 64-bit Python,vcredist_x86.exeif using 32-bit Python.ImageMagickThe library might return the errorFile could not be converted by ImageMagick to OpenCV Image: <path to the file>when comparing PDF files.
This is due to ImageMagick permissions. Verify this as follows with thesample.pdfin thetestdatadirectory:convertsample.pdfsample.jpgconvert-im6.q16:attempttoperformanoperationnotallowedbythesecuritypolicySolution is to copy thepolicy.xmlfrom the repository to the ImageMagick installation directory.DockerYou can also use thedocker imagesor create your own Docker Imagedocker build -t robotframework-doctest .Afterwards you can, e.g., start the container and run the povided examples like this:Windowsdocker run -t -v "%cd%":/opt/test -w /opt/test robotframework-doctest robot atest/Compare.robotLinuxdocker run -t -v $PWD:/opt/test -w /opt/test robotframework-doctest robot atest/Compare.robotGitpod.ioTry out the library usingGitpodExamplesHave a look atVisual Comparison TestsPDF Content TestsPrint Job Testsfor more examples.Testing withRobot Framework*** Settings ***LibraryDocTest.VisualTest*** Test Cases ***Compare two Images and highlight differencesCompare ImagesReference.jpgCandidate.jpgUse masks/placeholders to exclude parts from visual comparison*** Settings ***LibraryDocTest.VisualTest*** Test Cases ***Compare two Images and ignore parts by using masksCompare ImagesReference.jpgCandidate.jpgplaceholder_file=masks.jsonCompare two PDF Docments and ignore parts by using masksCompare ImagesReference.jpgCandidate.jpgplaceholder_file=masks.jsonCompare two Farm images with date patternCompare ImagesReference.jpgCandidate.jpgplaceholder_file=testdata/pattern_mask.jsonCompare two Farm images with area mask as list${top_mask}Create Dictionarypage=1type=arealocation=toppercent=10${bottom_mask}Create Dictionarypage=alltype=arealocation=bottompercent=10${masks}Create List${top_mask}    ${bottom_mask}Compare ImagesReference.jpgCandidate.jpgmask=${masks}Compare two Farm images with area mask as stringCompare ImagesReference.jpgCandidate.jpgmask=top:10;bottom:10Different Mask Types to Ignore Parts When ComparingAreas, Coordinates, Text Patterns[{"page":"all","name":"Date Pattern","type":"pattern","pattern":".*[0-9]{2}-[a-zA-Z]{3}-[0-9]{4}.*"},{"page":"1","name":"Top Border","type":"area","location":"top","percent":5},{"page":"1","name":"Left Border","type":"area","location":"left","percent":5},{"page":1,"name":"Top Rectangle","type":"coordinates","x":0,"y":0,"height":10,"width":210,"unit":"mm"}]Accept visual different by checking move distance or text content*** Settings ***LibraryDocTest.VisualTest*** Test Cases ***Accept if parts are moved up to 20 pixels by pure visual checkCompare ImagesReference.jpgCandidate.jpgmove_tolerance=20Accept if parts are moved up to 20 pixels by reading PDF DataCompare ImagesReference.pdfCandidate.pdfmove_tolerance=20get_pdf_content=${true}Accept differences if text content is the same via OCRCompare ImagesReference.jpgCandidate.jpgcheck_text_content=${true}Accept differences if text content is the same from PDF DataCompare ImagesReference.pdfCandidate.pdfcheck_text_content=${true}get_pdf_content=${true}Different options to detect moved parts/objects*** Settings ***LibraryDocTest.VisualTestmovement_detection=orb*** Test Cases ***Accept if parts are moved up to 20 pixels by pure visual checkCompare ImagesReference.jpgCandidate.jpgmove_tolerance=20*** Settings ***LibraryDocTest.VisualTestmovement_detection=template*** Test Cases ***Accept if parts are moved up to 20 pixels by pure visual checkCompare ImagesReference.jpgCandidate.jpgmove_tolerance=20*** Settings ***LibraryDocTest.VisualTestmovement_detection=classic*** Test Cases ***Accept if parts are moved up to 20 pixels by pure visual checkCompare ImagesReference.jpgCandidate.jpgmove_tolerance=20Options for taking additional screenshots, screenshot format and render resolutionTake additional screenshots or reference and candidate file.*** Settings ***LibraryDocTest.VisualTesttake_screenshots=${true}screenshot_format=pngTake diff screenshots to highlight differences*** Settings ***LibraryDocTest.VisualTestshow_diff=${true}DPI=300Experimental usage of Open CV East Text Detection to improve OCR*** Settings ***LibraryDocTest.VisualTest*** Test Cases ***Compare two Farm images with date pattern and east detectionCompare ImagesReference.jpgCandidate.jpgplaceholder_file=masks.jsonocr_engine=eastCheck content of PDF files*** Settings ***LibraryDocTest.PdfTest*** Test Cases ***Check if list of strings exists in PDF File@{strings}=Create ListFirst StringSecond StringPDF Should Contain Strings${strings}Candidate.pdfCompare two PDF Files and only check text contentCompare Pdf DocumentsReference.pdfCandidate.pdfcompare=textCompare twoPDF Files and only check text content and metadataCompare Pdf DocumentsReference.pdfCandidate.pdfcompare=text,metadataCompare twoPDF Files and check all possible contentCompare Pdf DocumentsReference.pdfCandidate.pdfIgnore Watermarks for Visual ComparisonsStore the watermark in a separate B/W image or PDF.Watermark area needs to be filled with black color.Watermark content will be subtracted from Visual Comparison result.*** Settings ***LibraryDocTest.VisualTest*** Test Cases ***Compare two Images and ignore jpg watermarkCompare ImagesReference.jpgCandidate.jpgwatermark_file=Watermark.jpgCompare two Images and ignore pdf watermarkCompare ImagesReference.pdfCandidate.pdfwatermark_file=Watermark.pdfCompare two Images and ignore watermark folderCompare ImagesReference.pdfCandidate.pdfwatermark_file=${CURDIR}${/}watermarksWatermarks can also be passed on Library import. This setting will apply to all Test Cases in Test Suite*** Settings ***LibraryDocTest.VisualTestwatermark_file=${CURDIR}${/}watermarks*** Test Cases ***Compare two Images and ignore watermarksCompare ImagesReference.jpgCandidate.jpgGet Text From Documents or Images*** Settings ***LibraryDocTest.VisualTest*** Test Cases ***Get Text Content And Compare${text}Get Text From DocumentReference.pdfList Should Contain Value${text}Test StringGet Barcodes From Documents or Images*** Settings ***LibraryDocTest.VisualTest*** Test Cases ***Get Text Content And Compare${text}Get Barcodes From Documentreference.jpgList Should Contain Value${text}123456789Using pabot to run tests in parallelDocument Testing can be run in parallel usingpabot.However, you need to pass the additional arguments--artifactsand--artifactsinsubfoldersto thepabotcommand, to move the screenshots to the correct subfolder.Otherwise the screenshots will not be visible in thelog.htmlpabot --testlevelsplit --processes 8 --artifacts png,jpg,pdf,xml --artifactsinsubfolders /path/to/your/tests/Visual Testing of Web ApplicationsI experimented a bit and tried to use this library for Visual Testing of Web Applications.Please have a look at this pilot examplehereDevelopmentFeel free to create issues or pull requests.I'm always happy for any feedback.Core teamIn order of appearance.Many KasirihaApril WangContributorsThis project is community driven and becomes a reality only through the work of all the people who contribute.