Skip to main content

Google Gemini oracles for Robot Framework: text-only and multimodal (image) assertions.

Project description

robotframework-gemini

English | Português (Brasil)

Robot Framework keyword library for Google Gemini oracles: text-only evaluation (API payloads, logs, JSON, etc.) or multimodal checks with an image (PNG file or a Robot Framework Browser screenshot).

  • Multimodal: sends prompt text and the capture as a byte Part (google-genai).
  • Recommended flow: two inputs — context (test framing) and evaluation (criterion or yes/no question).
  • Browser optional: screenshot keywords need Library Browser; text keywords work without a browser.

Installation

pip install robotframework-gemini

With Robot Framework Browser (Playwright) screenshot support:

pip install "robotframework-gemini[browser]"
python -m pip install robotframework

Local development:

python -m pip install -e ".[dev]"

Environment variables and Library import

Variable / argument Purpose
GEMINI_API_KEY Gemini API key (required unless you pass api_key on the Library)
GEMINI_MODEL Model id (e.g. gemini-2.5-flash). If omitted, defaults to gemini-2.5-flash.
api_key (import) Overrides GEMINI_API_KEY at Library import
model (import) Overrides GEMINI_MODEL at Library import

By default the Library reads key and model from the environment. You can also pass them on import (useful in CI or suites that keep credentials in Robot variables):

*** Variables ***
${GEMINI_API_KEY}    %{GEMINI_API_KEY}
${GEMINI_MODEL}      gemini-2.5-flash

*** Settings ***
Library    GeminiLibrary    api_key=${GEMINI_API_KEY}    model=${GEMINI_MODEL}

Model only (key still comes from the environment):

Library    GeminiLibrary    model=gemini-2.5-flash

Explicit package import (equivalent):

Library    robotframework_gemini.library.GeminiLibrary    api_key=${GEMINI_API_KEY}    model=${GEMINI_MODEL}

Do not commit a literal API key; prefer %{GEMINI_API_KEY} or CI secrets.

Keyword documentation

Usage in Robot Framework

Note: examples use Set Variable and Catenate instead of the VAR keyword (Robot Framework 7.0+) to stay compatible with older Robot Framework versions.

Text only (no Browser)

*** Settings ***
Library    GeminiLibrary

*** Keywords ***
Validate API response
    ${context}=       Set Variable    {"status": "ok", "items": 3}
    ${evaluation}=    Set Variable    Does the payload indicate success with items?
    ${model_response}=    Gemini Evaluate Text    ${context}    ${evaluation}
    Log    ${model_response}

With a screenshot (Browser)

Import Browser before Gemini:

*** Settings ***
Library    Browser
Library    GeminiLibrary

*** Keywords ***
Check screen against a neutral criterion
    ${context}=       Set Variable    List filtered by Active status.
    ${evaluation}=    Set Variable    Do all visible items show Active status?
    ${model_response}=    Gemini Evaluate With Screen    ${context}    ${evaluation}
    Log    ${model_response}

Recommended import (RobotCode, runtime, and PyPI):

Library    GeminiLibrary    api_key=${GEMINI_API_KEY}    model=${GEMINI_MODEL}

Explicit package path (IDEs that prefer a full Python path):

Library    robotframework_gemini.library.GeminiLibrary    api_key=${GEMINI_API_KEY}    model=${GEMINI_MODEL}

IDE and RobotCode

Import form Resolved by
Library GeminiLibrary Top-level GeminiLibrary.py module (installed in the wheel or via src/ in a clone)
Library robotframework_gemini.library.GeminiLibrary Standard Python package path

In a repository clone, without installing:

With a local venv: pip install -e ".[dev]", then reload the IDE window after changes.

With an image file already saved:

Browser.Take Screenshot    ${OUTPUT_DIR}/screen.png
${model_response}=    Gemini Evaluate With Image File    ${context}    ${evaluation}    ${OUTPUT_DIR}/screen.png

Verdict via prompt (first line) and 1–5 score:

${model_response}=    Gemini Evaluate With Screen    ${context}    ${evaluation}
...    extra_instructions=Reply with one word on the first line: Yes or No.
${verdict}=    Get Line    ${model_response}    0
Should Be Equal As Strings    ${verdict}    Yes

# Score 1–5: two steps (log the reason) or one-line shortcut
${model_response}=    Gemini Evaluate Text Rating    ${context}    ${evaluation}
${rating_score}=    Gemini Parse Rating    ${model_response}

${rating_score}=    Gemini Evaluate Text Rating Score    ${context}    ${evaluation}

Details for the three rating keywords: Scores 1–5 (EN).

See also examples/demo_template.robot.

Tests

pytest

Tests mock generate_content; there are no real API calls.

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robotframework_gemini-0.3.4.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

robotframework_gemini-0.3.4-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file robotframework_gemini-0.3.4.tar.gz.

File metadata

  • Download URL: robotframework_gemini-0.3.4.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for robotframework_gemini-0.3.4.tar.gz
Algorithm Hash digest
SHA256 f4df5c4dece12e8246744f7073c445dba32e1ff2ba4e677f57f8a8feae172c8d
MD5 940e5b40d072054548d5621b2181debb
BLAKE2b-256 41e4362fcc511740db8052bea2da0011afb3713546b3c05ea135a022db9e5375

See more details on using hashes here.

Provenance

The following attestation bundles were made for robotframework_gemini-0.3.4.tar.gz:

Publisher: publish.yml on carlosnizolli/robotframework-gemini

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file robotframework_gemini-0.3.4-py3-none-any.whl.

File metadata

File hashes

Hashes for robotframework_gemini-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6e147e6c661d0a2e128f5acb97b48d77175685cba56f416888ef5c900f2b33ba
MD5 61c6f3dacf9b5ddb37aff8e42941c6bb
BLAKE2b-256 65a08c9250ea0c359b0644920e6b30bc4d60599c22c13903c5e13ea9de13967d

See more details on using hashes here.

Provenance

The following attestation bundles were made for robotframework_gemini-0.3.4-py3-none-any.whl:

Publisher: publish.yml on carlosnizolli/robotframework-gemini

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page