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.3.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.3-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: robotframework_gemini-0.3.3.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.3.tar.gz
Algorithm Hash digest
SHA256 3befe317eca425486b372c75d379f02f760b0852ded4f94cac6911cfd184a81f
MD5 4db7e8dbbcf27f39ee16ba7839a6155f
BLAKE2b-256 77b5157487e47d95bc0a02a27a9749bcb430af40e2734aea6d1af5d78f852d3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for robotframework_gemini-0.3.3.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.3-py3-none-any.whl.

File metadata

File hashes

Hashes for robotframework_gemini-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e4baae34713b30a83691a9d0287166ed5af65407dd7319312aff8357815d1793
MD5 7295e92167e70aa42f85aa782b53ea79
BLAKE2b-256 7a6dfc268a450d052dbd4a26a4d3dae0db9995bb84810cb0b23655db4bb397a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for robotframework_gemini-0.3.3-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