Metadata-Version: 2.5
Name: robotframework-doctestlibrary
Version: 0.35.0
Summary: A library for Visual Document Testing
Project-URL: Homepage, https://github.com/manykarim/robotframework-doctestlibrary
Project-URL: Repository, https://github.com/manykarim/robotframework-doctestlibrary
Author-email: Many Kasiriha <many.kasiriha@dbschenker.com>
Maintainer-email: Many Kasiriha <many.kasiriha@dbschenker.com>
License: Apache-2.0
License-File: LICENSE
Classifier: Framework :: Robot Framework
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.11
Requires-Dist: deepdiff; python_version < '3.12'
Requires-Dist: deepdiff>=6.0; python_version >= '3.12' and python_version < '3.15'
Requires-Dist: deepdiff>=9.2.1; python_version >= '3.15'
Requires-Dist: numpy>=1.26; python_version < '3.13'
Requires-Dist: numpy>=2.1.0; python_version >= '3.13' and python_version < '3.15'
Requires-Dist: numpy>=2.5.2; python_version >= '3.15'
Requires-Dist: opencv-python-headless<5,>=4.8
Requires-Dist: parsimonious>=0.10
Requires-Dist: pylibdmtx>=0.1.10
Requires-Dist: pymupdf<2,>=1.26.0
Requires-Dist: pytesseract>=0.3.10
Requires-Dist: pyzbar>=0.1.9
Requires-Dist: robotframework-assertion-engine>=3.0.3
Requires-Dist: robotframework>=4
Requires-Dist: scikit-image; python_version < '3.12'
Requires-Dist: scikit-image>=0.22.0; python_version == '3.12'
Requires-Dist: scikit-image>=0.25.0; python_version >= '3.13' and python_version < '3.15'
Requires-Dist: scikit-image>=0.27.0rc1; python_version >= '3.15'
Requires-Dist: setuptools; python_version >= '3.12'
Provides-Extra: ai
Requires-Dist: pydantic-ai-slim[openai]<3,>=1.107.7; extra == 'ai'
Requires-Dist: python-dotenv; extra == 'ai'
Provides-Extra: all
Requires-Dist: fastapi>=0.110; extra == 'all'
Requires-Dist: parsimonious>=0.10; extra == 'all'
Requires-Dist: pydantic-ai-slim[openai]<3,>=1.107.7; extra == 'all'
Requires-Dist: pydantic>=2.6; extra == 'all'
Requires-Dist: pylibdmtx>=0.1.10; extra == 'all'
Requires-Dist: python-dotenv; extra == 'all'
Requires-Dist: python-multipart>=0.0.9; extra == 'all'
Requires-Dist: pyzbar>=0.1.9; extra == 'all'
Requires-Dist: uvicorn>=0.29; extra == 'all'
Provides-Extra: barcode
Requires-Dist: pylibdmtx>=0.1.10; extra == 'barcode'
Requires-Dist: pyzbar>=0.1.9; extra == 'barcode'
Provides-Extra: browser
Requires-Dist: robotframework-browser; extra == 'browser'
Provides-Extra: dashboard
Requires-Dist: fastapi>=0.110; extra == 'dashboard'
Requires-Dist: pydantic>=2.6; extra == 'dashboard'
Requires-Dist: python-multipart>=0.0.9; extra == 'dashboard'
Requires-Dist: uvicorn>=0.29; extra == 'dashboard'
Provides-Extra: printjobs
Requires-Dist: parsimonious>=0.10; extra == 'printjobs'
Provides-Extra: selenium
Requires-Dist: robotframework-seleniumlibrary; extra == 'selenium'
Description-Content-Type: text/markdown

# robotframework-doctestlibrary
----
[Robot Framework](https://robotframework.org) DocTest library.  
Simple Automated Visual Document Testing.

See **keyword documentation** for

- [Visual Document Tests](https://manykarim.github.io/robotframework-doctestlibrary/VisualTest.html)
- [Web Visual Tests (Browser/Selenium)](https://manykarim.github.io/robotframework-doctestlibrary/WebVisualTest.html)
- [Print Job Tests](https://manykarim.github.io/robotframework-doctestlibrary/PrintJobTest.html)
- [Pdf Tests (very basic)](https://manykarim.github.io/robotframework-doctestlibrary/PdfTest.html)
- [Ai Keywords (optional)](https://manykarim.github.io/robotframework-doctestlibrary/Ai.html)

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest

*** Test Cases ***
Compare two Images and highlight differences
    Compare Images    Reference.jpg    Candidate.jpg
```

[Optional LLM for image comparison](https://manykarim.github.io/robotframework-doctestlibrary/Ai.html)

```RobotFramework
*** Settings ***
Library    DocTest.Ai
Library    DocTest.VisualTest
Library    DocTest.PdfTest

*** Test Cases ***
Review Visual Differences With LLM
    Compare Images With LLM    Reference.pdf    Candidate.pdf    llm_override=${True}

Extract Text From Document With LLM
    ${text}=    Get Text With LLM    Candidate.pdf    prompt=Return text and table contents
    Log    ${text}

Image Should Contain Object With LLM
    Image Should Contain    Candidate.png    Missing product logo

Count Items With LLM
    ${count}=    Get Item Count From Image    Candidate.png    item_description=number of pallets
    Should Be True    ${count} >= 0
```

[![DocTest Library presentation at robocon.io 2021](https://img.youtube.com/vi/qmpwlQoJ-nE/0.jpg)](https://youtu.be/qmpwlQoJ-nE "DocTest Library presentation at robocon.io 2021")

# Installation instructions

```bash
pip install --upgrade robotframework-doctestlibrary              # core library
pip install --upgrade robotframework-doctestlibrary[ai]          # + LLM-assisted comparisons
pip install --upgrade robotframework-doctestlibrary[dashboard]   # + visual review dashboard & mask editor
pip install --upgrade robotframework-doctestlibrary[all]         # ai + dashboard
```

What each install brings:

| Install | Adds | Notes |
|---|---|---|
| *(base)* | `VisualTest`, `PdfTest`, `PrintJobTests`, **`WebVisualTest`** | Web visual testing needs **no extra dependencies** — it drives the Browser Library or SeleniumLibrary you already use. |
| `[ai]` | LLM-assisted comparison keywords | Configure via `DOCTEST_LLM_*`. |
| `[dashboard]` | `doctest-dashboard` web app (review, baselines, mask editor) | The CLI stub is always present; the extra brings its server dependencies. |
| `[browser]` | `robotframework-browser` | Convenience: one-liner for web testing with Playwright (run `rfbrowser init` afterwards). |
| `[selenium]` | `robotframework-seleniumlibrary` | Convenience: one-liner for web testing with Selenium. |
| `[all]` | ai + dashboard | Web drivers stay an explicit choice. |

## Development setup (contributors)

The project is managed with [uv](https://docs.astral.sh/uv/) — one `pyproject.toml`, one lockfile:

```bash
uv sync --all-extras        # full dev environment (library, dashboard, test tooling)
uv run invoke tests         # unit + acceptance suites
uv run invoke multipython   # validate dependency resolution on Python 3.11–3.15
uv run pytest e2e --browser chromium   # dashboard end-to-end journeys
cd frontend && npm install && npm run build   # build the dashboard web UI once
```

## Optional LLM-Assisted Comparisons

You can optionally rely on a large language model to review detected differences and
decide whether a comparison should pass. This path is fully opt-in; nothing changes
for users who skip these dependencies.

1. Install the optional extra only when needed:
   ```bash
   pip install "robotframework-doctestlibrary[ai]"
   ```
   The extra supports [pydantic-ai](https://ai.pydantic.dev/) 1.107.7 up to (excluding) 3.0, so both
   the 1.x and 2.x series work. With the default `openai` provider, requests always use the
   Chat Completions API, so OpenAI-compatible endpoints configured via `DOCTEST_LLM_BASE_URL`
   (e.g. OpenRouter or a local server) keep working with pydantic-ai 2.x.
2. Create a `.env` file at the repository root (values here override existing environment variables):
   ```ini
   # OpenAI-compatible endpoints
   OPENAI_API_KEY=sk-...
   DOCTEST_LLM_MODEL=gpt-5,gpt-4o
   DOCTEST_LLM_VISION_MODEL=gpt-5-mini,gpt-4o-mini
   ```
   Azure OpenAI deployments can be configured with:
   ```ini
   AZURE_OPENAI_ENDPOINT=https://your-endpoint.openai.azure.com/
   AZURE_OPENAI_API_KEY=...
   AZURE_OPENAI_DEPLOYMENT=gpt-4o
   AZURE_OPENAI_API_VERSION=2024-06-01
   DOCTEST_LLM_PROVIDER=azure
   ```
   See `.env.example` for a combined template covering both providers.
3. Use the dedicated keywords (or pass `llm_enabled=${True}` to existing ones):

   ```RobotFramework
   *** Test Cases ***
   Review Visual Differences With LLM
       Compare Images With LLM    Reference.pdf    Candidate.pdf    llm_override=${True}

   Review Pdf Structure With LLM
       Compare Pdf Documents With LLM    reference.pdf    candidate.pdf    compare=structure
   ```

Set `llm_override=${True}` when an LLM approval should override SSIM/DeepDiff failures.
Without the override flag the AI feedback is logged for investigation while the original
assertion result is preserved.

Pass `llm_prompt=` (or the specialty variants `llm_visual_prompt=` / `llm_pdf_prompt=`) to
customise the prompt sent to the model for a particular comparison.

Python 3.11 or newer is supported. Tested with Python 3.11/3.12/3.13/3.14/3.15 on Linux and Windows.
Python 3.10 reached end of life; on 3.10, pin `robotframework-doctestlibrary<0.35`, the last release line that supports it.

## Install robotframework-doctestlibrary

### Installation via `pip` from PyPI (recommended)

* `pip install --upgrade robotframework-doctestlibrary`

### Installation via `pip` from GitHub

* `pip install git+https://github.com/manykarim/robotframework-doctestlibrary.git`  

or

* `git clone https://github.com/manykarim/robotframework-doctestlibrary.git`
* `cd robotframework-doctestlibrary`
* `pip install -e .`

## Install dependencies

Install Tesseract, Ghostscript, GhostPCL, ImageMagick binaries and barcode libraries (libdmtx, zbar) on your system.
<br>Hint: Since `0.2.0` Ghostscript, GhostPCL and ImageMagick are only needed for rendering `.ps` and `.pcl`files.
<br> Rendering and content parsing of `.pdf` is done via `MuPDF`
<br>In the future there might be a separate pypi package for `.pcl` and `.ps` files to get rid of those dependencies.

Linux
```bash
apt-get install imagemagick tesseract-ocr ghostscript libdmtx0b libzbar0
```

Windows
 * https://github.com/UB-Mannheim/tesseract/wiki
 * https://ghostscript.com/releases/gsdnld.html
 * https://ghostscript.com/releases/gpcldnld.html
 * https://imagemagick.org/script/download.php


## Some special instructions for Windows 

### Rename executable for GhostPCL to pcl6.exe (only needed for `.pcl` support)
The executable for GhostPCL `gpcl6win64.exe` needs to be renamed to `pcl6.exe`

Otherwise 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, `.pcl` and `.ps` support)
* C:\Program Files\ImageMagick-7.0.10-Q16-HDRI
* C:\Program Files\Tesseract-OCR
* C:\Program Files\gs\gs9.53.1\bin
* C:\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 commands
* `magick.exe`
* `tesseract.exe`
* `gswin64.exe`
* `pcl6.exe`

successfully from any folder/location

### Windows error message regarding pylibdmtx

[How to solve ImportError for pylibdmtx](https://github.com/NaturalHistoryMuseum/pylibdmtx/#windows-error-message)

If you see an ugly `ImportError` when importing `pylibdmtx` on
Windows you will most likely need the [Visual C++ Redistributable Packages for
Visual Studio 2013](https://www.microsoft.com/en-US/download/details.aspx?id=40784). Install `vcredist_x64.exe` if using 64-bit Python, `vcredist_x86.exe` if using 32-bit Python.

## ImageMagick

The library might return the error `File 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 the `sample.pdf` in the `testdata` directory:
```bash
convert sample.pdf sample.jpg 
convert-im6.q16: attempt to perform an operation not allowed by the security policy
```

Solution is to copy the `policy.xml` from the repository to the ImageMagick installation directory.

## Docker

You can also use the [docker images](https://github.com/manykarim/robotframework-doctestlibrary/packages) or create your own Docker Image
`docker build -t robotframework-doctest .`
Afterwards you can, e.g., start the container and run the povided examples like this:
* Windows
  * `docker run -t -v "%cd%":/opt/test -w /opt/test robotframework-doctest robot atest/Compare.robot`
* Linux
  * `docker run -t -v $PWD:/opt/test -w /opt/test robotframework-doctest robot atest/Compare.robot`

## Gitpod.io
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/manykarim/robotframework-doctestlibrary)  
Try out the library using [Gitpod](https://gitpod.io/#https://github.com/manykarim/robotframework-doctestlibrary)

# Web-App Visual Testing (Browser Library & SeleniumLibrary)

`DocTest.WebVisualTest` adds baseline-driven visual regression testing for web
apps on top of the comparison engine. It captures pages and elements through the
**Browser Library** or **SeleniumLibrary** session your suite already runs — no
extra dependency, the library you imported is auto-detected:

```robotframework
*** Settings ***
Library    Browser
Library    DocTest.WebVisualTest    result_json=true

*** Test Cases ***
Checkout Page Looks Right
    New Page    https://shop.example.com/checkout
    Compare Page To Baseline       checkout
    Compare Element To Baseline    id=price-table    checkout-prices
```

- **Baselines managed for you**: first run stores the capture as
  `visual_baselines/checkout.png` (passes with a warning); later runs compare
  against it. Update via `--variable REFERENCE_RUN:True` or by accepting in the
  review dashboard.
- **Flake resistance**: failing comparisons recapture and recompare until
  `retry_timeout` (default 3s) expires; Browser captures disable animations and
  normalize device pixel ratio (`scale=css`).
- **Full engine available**: every `Compare Images` option works — masks,
  thresholds, move tolerance, OCR pattern masks.

See [docs/web-visual-testing.md](./docs/web-visual-testing.md) for the full guide.

# Visual Review Dashboard & Mask Editor

The **doctest-dashboard** (shipped with the `[dashboard]` extra) is a locally runnable web app to review comparison results outside of `log.html`:

- browse runs and failing comparisons with diff thumbnails
- diff viewer with side-by-side / overlay / blink / swipe modes and next/previous-difference navigation
- **accept** a difference → the candidate is promoted to the new reference (plain file copy, git-diffable, SHA-256 audit trail)
- **reject** a difference → export a bug-data ZIP (reference + candidate + diffs + metadata)
- **visual mask editor** for coordinate, area, and text-pattern masks with live preview — including one-click *create mask from diff region* and instant re-comparison of past runs with the adjusted masks

Quick start:

```bash
pip install robotframework-doctestlibrary[dashboard]   # wheels include the web UI
doctest-dashboard serve                                 # open http://127.0.0.1:8008
doctest-dashboard ingest results/output.xml
```

Run your suites with the machine-readable sidecar enabled so the dashboard gets per-page data:

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest    result_json=true    take_screenshots=true    screenshot_format=png
```

See the full guide in [docs/dashboard.md](./docs/dashboard.md) for the review workflow, mask editor usage, team mode, and the API.

# Examples

Have a look at  
* [Visual Comparison Tests](./atest/Compare.robot)
* [PDF Content Tests](./atest/PdfContent.robot)
* [Print Job Tests](./atest/PrintJobs.robot)
* [AI-Assisted Tests](./atest/LLM.robot)

for more examples.

### Testing with [Robot Framework](https://robotframework.org)

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest

*** Test Cases ***
Compare two Images and highlight differences
    Compare Images    Reference.jpg    Candidate.jpg
```

### Use masks/placeholders to exclude parts from visual comparison

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest

*** Test Cases ***
Compare two Images and ignore parts by using masks
    Compare Images    Reference.jpg    Candidate.jpg    placeholder_file=masks.json

Compare two PDF Docments and ignore parts by using masks
    Compare Images    Reference.jpg    Candidate.jpg    placeholder_file=masks.json

Compare two Farm images with date pattern
    Compare Images    Reference.jpg    Candidate.jpg    placeholder_file=testdata/pattern_mask.json

Compare two Farm images with area mask as list
    ${top_mask}    Create Dictionary    page=1    type=area    location=top    percent=10
    ${bottom_mask}    Create Dictionary    page=all    type=area    location=bottom    percent=10
    ${masks}    Create List    ${top_mask}    ${bottom_mask}
    Compare Images    Reference.jpg    Candidate.jpg    mask=${masks}

Compare two Farm images with area mask as string
    Compare Images    Reference.jpg    Candidate.jpg    mask=top:10;bottom:10

```
#### Different Mask Types to Ignore Parts When Comparing
##### Areas, Coordinates, Text Patterns

Text pattern matching levels: `word_pattern` matches single words; `line_pattern` matches whole text lines (anchored, use `.*…​.*` to match anywhere); `pattern` matches single words — and when the regex contains whitespace it is searched anywhere within each line, masking **exactly the words the match span covers**. So `Robot Framework` masks just that phrase wherever it occurs, while `.*Robot Framework.*` extends the match over the whole line and masks all of it. Matching is case-sensitive; add `(?i)` for case-insensitive.
```python
[
    {
    "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"
    }
]
```

##### Creating and editing masks visually

The companion **doctest-dashboard** ships a visual mask editor with live preview of coordinate, area, and pattern masks — including one-click mask creation from detected diff regions and instant re-comparison of past runs with the adjusted masks. It reads and writes the exact JSON schema shown above. See [docs/dashboard.md](./docs/dashboard.md) for the full guide.

> **Deprecation note:** the tkinter tool `utilities/mask_editor.py` is superseded by the dashboard's mask editor and will be removed in a future release. It only supports pixel-based coordinate masks.

##### Machine-readable results for review tooling

Enable `result_json=true` on `DocTest.VisualTest` / `DocTest.PdfTest` to write a JSON sidecar per comparison into `{OUTPUT_DIR}/doctest_results/` (statuses, SSIM scores, diff regions, resolved masks, per-page renderings). The dashboard — and any other tooling — ingests these for review, accept/reject baseline management, and mask maintenance:

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest    result_json=true    take_screenshots=true    screenshot_format=png
```

### Accept visual different by checking move distance or text content

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest

*** Test Cases ***
Accept if parts are moved up to 20 pixels by pure visual check
    Compare Images    Reference.jpg    Candidate.jpg    move_tolerance=20

Accept if parts are moved up to 20 pixels by reading PDF Data
    Compare Images    Reference.pdf    Candidate.pdf    move_tolerance=20    get_pdf_content=${true}

Accept differences if text content is the same via OCR
    Compare Images    Reference.jpg    Candidate.jpg    check_text_content=${true}

Accept differences if text content is the same from PDF Data
    Compare Images    Reference.pdf    Candidate.pdf    check_text_content=${true}    get_pdf_content=${true}
```

#### Different options to detect moved parts/objects

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest   movement_detection=orb

*** Test Cases ***
Accept if parts are moved up to 20 pixels by pure visual check
    Compare Images    Reference.jpg    Candidate.jpg    move_tolerance=20
```	

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest   movement_detection=template

*** Test Cases ***
Accept if parts are moved up to 20 pixels by pure visual check
    Compare Images    Reference.jpg    Candidate.jpg    move_tolerance=20
```	

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest   movement_detection=classic

*** Test Cases ***
Accept if parts are moved up to 20 pixels by pure visual check
    Compare Images    Reference.jpg    Candidate.jpg    move_tolerance=20
```

#### Detection method for template matching

`movement_detection` only affects moved-object detection. The detection method
used by `Image Should Contain Template` is configured separately with
`template_detection` (`template`, `orb` or `sift`), so it does not have to be
repeated on every call:

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest   template_detection=sift

*** Test Cases ***
Find a logo using SIFT without repeating the detection argument
    Image Should Contain Template    document.pdf    logo.png
```

An explicit `detection` argument still wins for a single call. The
`Set Template Detection` keyword changes the default for the remainder of the
current test — the library uses Robot Framework's default `TEST` scope, so use
the import argument above to set it for a whole suite. Note that the `sift` and
`orb` methods ignore `threshold` and their return value contains no
`confidence` key.

### Options for taking additional screenshots, screenshot format and render resolution

Take additional screenshots or reference and candidate file.

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest   take_screenshots=${true}    screenshot_format=png
```
Take diff screenshots to highlight differences

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest   show_diff=${true}    DPI=300
```

### Experimental usage of Open CV East Text Detection to improve OCR

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest

*** Test Cases ***
Compare two Farm images with date pattern and east detection
    Compare Images    Reference.jpg    Candidate.jpg    placeholder_file=masks.json    ocr_engine=east
```

EAST recognizes each detected text region separately, so its accuracy depends on the Tesseract
language model more than full-page OCR does. Linux packages (`tesseract-ocr-eng`) and recent Windows
installers (5.5.3+) ship the small `tessdata_fast` model, which can misread text in busy images
(e.g. `XBCDEFCHI` instead of `ABCDEFGHI`). For best EAST results, replace `eng.traineddata` in your
`tessdata` folder with the one from [tessdata_best](https://github.com/tesseract-ocr/tessdata_best).

### Check content of PDF files

```RobotFramework
*** Settings ***
Library    DocTest.PdfTest

*** Test Cases ***
Check if list of strings exists in PDF File
    @{strings}=    Create List    First String    Second String
    PDF Should Contain Strings    ${strings}    Candidate.pdf
    
Compare two PDF Files and only check text content
    Compare Pdf Documents    Reference.pdf    Candidate.pdf    compare=text

Compare two  PDF Files and only check text content and metadata
    Compare Pdf Documents    Reference.pdf    Candidate.pdf    compare=text,metadata
    
Compare two  PDF Files and check all possible content
    Compare Pdf Documents    Reference.pdf    Candidate.pdf
```

### Ignoring dynamic fields in PDF comparisons

Both `Compare Pdf Documents` and `Compare Pdf Structure` now share the same helper options for masking boilerplate data:

- `mask` accepts inline JSON/dicts, Robot lists, or a path to a JSON file generated by the screenshot tooling. Add `unit=pt` when coordinates are already expressed in PDF points.
- `text_mask_patterns` lets you provide one or more regular expressions (string or `@{list}`) to drop matching lines from both PDFs before diffing. This is handy for timestamps, order numbers, etc.
- `ignore_ligatures=${True}` normalises glyphs such as `ﬁ`/`ﬂ` to their ASCII representation so small font engine differences do not fail the comparison.

```RobotFramework
*** Settings ***
Library    DocTest.PdfTest

*** Test Cases ***
Compare invoices while ignoring IDs
    ${mask}=    Set Variable    {"pages":[{"page":1,"rectangles":[{"left":410,"top":36,"right":560,"bottom":78}],"unit":"pt"}]}
    Compare Pdf Structure    ${CURDIR}/baseline.pdf    ${CURDIR}/candidate.pdf    mask=${mask}
    ...    text_mask_patterns=\\bINV-\d{6}\\b    ignore_ligatures=${True}    position_tolerance=5
```

### Normalizing special characters in PDF comparisons

PDFs may contain special Unicode characters that look identical to standard ASCII but fail string comparisons. Common examples include non-breaking spaces (`\u00A0`) instead of regular spaces, or typographic dashes (`\u2013`, `\u2014`) instead of hyphens.

Use the `character_replacements` parameter to normalize these characters:

```RobotFramework
*** Settings ***
# Apply character replacements to all keywords in the test suite
Library    DocTest.PdfTest    character_replacements={'\u00A0': ' '}
Library    DocTest.VisualTest    character_replacements={'\u00A0': ' ', '\u2013': '-'}

*** Test Cases ***
PDF comparison with normalized whitespace
    Compare Pdf Documents    reference.pdf    candidate.pdf    compare=text
    ...    character_replacements={'\u00A0': ' '}

Check PDF contains text with normalized characters
    PDF Should Contain Strings    Expected Text    candidate.pdf
    ...    character_replacements={'\u00A0': ' '}

Structure comparison with character normalization
    Compare Pdf Structure    reference.pdf    candidate.pdf
    ...    character_replacements={'\u00A0': ' ', '\u2013': '-'}
```

For `VisualTest` text extraction keywords that use assertion operators, use the `Set Character Replacements` keyword:

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest

*** Test Cases ***
Get text with normalized characters
    Set Character Replacements    {'\u00A0': ' '}
    ${text}=    Get Text    document.pdf    ==    Expected text
    Set Character Replacements    ${NONE}    # Clear when done
```

Common character replacements:
| Character | Unicode | Description | Replacement |
|-----------|---------|-------------|-------------|
| ` ` | `\u00A0` | Non-breaking space | ` ` (regular space) |
| `–` | `\u2013` | En dash | `-` (hyphen) |
| `—` | `\u2014` | Em dash | `-` (hyphen) |
| `‐` | `\u2010` | Unicode hyphen | `-` (hyphen) |

### Comparing PDFs with different page layouts (font/size changes)

When comparing PDF documents where font or size changes cause text to reflow across pages, use the `ignore_page_boundaries` option to compare only text content and order, ignoring page structure:

```RobotFramework
*** Settings ***
Library    DocTest.PdfTest

*** Test Cases ***
Compare PDFs ignoring page breaks due to font change
    [Documentation]    Reference has 2 pages, candidate has 3 pages due to larger font
    ...                Both contain identical text in the same order
    Compare Pdf Structure    reference.pdf    candidate_larger_font.pdf
    ...    ignore_page_boundaries=${True}

Compare PDF Documents with cross-page text matching
    Compare Pdf Documents    reference.pdf    candidate.pdf
    ...    compare=structure    ignore_page_boundaries=${True}
```

For finer control over what gets compared, use the `check_geometry` and `check_block_count` options:

| Parameter | Default | Description |
|-----------|---------|-------------|
| `ignore_page_boundaries` | `${False}` | Flatten text across all pages and compare only content and order. Automatically disables geometry and block count checks. |
| `check_geometry` | `${True}` | When `${False}`, skip line position/size comparison. Useful when layout differs but text matches. |
| `check_block_count` | `${True}` | When `${False}`, skip block count validation per page. Useful when text blocks are merged/split differently. |

```RobotFramework
*** Settings ***
Library    DocTest.PdfTest

*** Test Cases ***
Compare PDF content only (ignore positions)
    [Documentation]    Same text content, but positions differ due to formatting
    Compare Pdf Structure    reference.pdf    reformatted.pdf
    ...    check_geometry=${False}

Compare PDF without block structure validation
    [Documentation]    Text blocks may be merged or split differently
    Compare Pdf Structure    reference.pdf    candidate.pdf
    ...    check_block_count=${False}

Pure content comparison (most flexible)
    [Documentation]    Only compare that text content and order match
    Compare Pdf Structure    reference.pdf    candidate.pdf
    ...    check_geometry=${False}    check_block_count=${False}
```

**Note:** When comparisons fail, a single summary warning is shown at the top of `log.html` (e.g., "Comparison failed: 5 difference(s) found"). Individual differences are logged as INFO messages within the keyword output for detailed inspection without cluttering the log summary.

### Ignore Watermarks for Visual Comparisons
Store the watermark in a separate B/W image or PDF.
<br>
Watermark area needs to be filled with black color.
<br>
Watermark content will be subtracted from Visual Comparison result.

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest

*** Test Cases ***
Compare two Images and ignore jpg watermark
    Compare Images    Reference.jpg    Candidate.jpg    watermark_file=Watermark.jpg

Compare two Images and ignore pdf watermark
    Compare Images    Reference.pdf    Candidate.pdf    watermark_file=Watermark.pdf

Compare two Images and ignore watermark folder
    Compare Images    Reference.pdf    Candidate.pdf    watermark_file=${CURDIR}${/}watermarks
```

Watermarks can also be passed on Library import. This setting will apply to all Test Cases in Test Suite

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest   watermark_file=${CURDIR}${/}watermarks

*** Test Cases ***
Compare two Images and ignore watermarks
    Compare Images    Reference.jpg    Candidate.jpg
```

### Get Text From Documents or Images

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest

*** Test Cases ***
Get Text Content And Compare
    ${text}    Get Text From Document    Reference.pdf
    List Should Contain Value    ${text}    Test String
```

### Get Barcodes From Documents or Images

```RobotFramework
*** Settings ***
Library    DocTest.VisualTest

*** Test Cases ***
Get Text Content And Compare
    ${text}    Get Barcodes From Document    reference.jpg
    List Should Contain Value    ${text}    123456789
```

### Using pabot to run tests in parallel

Document Testing can be run in parallel using [pabot](https://pabot.org/).  
However, you need to pass the additional arguments `--artifacts` and `--artifactsinsubfolders` to the `pabot` command, to move the screenshots to the correct subfolder.  
Otherwise the screenshots will not be visible in the `log.html`

```
pabot --testlevelsplit --processes 8 --artifacts png,jpg,pdf,xml --artifactsinsubfolders /path/to/your/tests/
```

### Visual Testing of Web Applications

I experimented a bit and tried to use this library for Visual Testing of Web Applications.  
Please have a look at this pilot example [here](https://github.com/manykarim/robotframework-doctestlibrary/blob/main/atest/Browser.robot)

# Development

Feel free to create issues or pull requests.  
I'm always happy for any feedback.

## Core team

In order of appearance.

  * Many Kasiriha
  * April Wang

## Contributors

This project is community driven and becomes a reality only through the work of all the people who contribute.
