Skip to main content

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

Project description

robotframework-gemini

PyPI version Python versions License: MIT

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-flash-latest). If omitted, defaults to gemini-flash-latest.
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-flash-latest

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

Model only (key still comes from the environment):

Library    GeminiLibrary    model=gemini-flash-latest

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.

Related projects

Part of a Robot Framework tooling set:

Project Description
robotframework-gemini_exemplos Practical suites using this library
RobotToPGListener Persist RF test results to PostgreSQL
docker-robotframework Ubuntu image for RF + Browser CI/E2E
robotframework-docker-actions GitHub Action to run tests with the Docker image in CI
RoboCop Robocop as a GitHub Action

Tests

pytest

Tests mock generate_content; there are no real API calls.

Security

See SECURITY.md for how to report vulnerabilities privately.

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.5.tar.gz (12.7 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.5-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for robotframework_gemini-0.3.5.tar.gz
Algorithm Hash digest
SHA256 a0b22be646766eba1dca2547fb88791ee46d3f517271100ce37bc66d54e4998c
MD5 4be11fcbd8919dd3da134fda8175eb78
BLAKE2b-256 1263fc0f5d0c44ee13d0ccd628d5e80691a495322f91ba5d7c13718b0055ef92

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for robotframework_gemini-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 32454603cb708e212efb75607f18c9c8a283ad62ea7f7755ccc45da23c5341d4
MD5 4775b85edf297e3f58ad49fd9069e9d0
BLAKE2b-256 c1e60b37cf6301343833f06ac1b27608f0ccc61b42c6fb7edf9761e9e0cbb558

See more details on using hashes here.

Provenance

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