AI-powered smart locator with retry functionality for Robot Framework using OpenAI
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
Robot Framework DomRetryLibrary
A Robot Framework library with AI-powered fallback for locator variables, enhancing test reliability by using OpenAI to dynamically generate element locators when primary locators fail.
Installation
Install the library using pip:
pip install robotframework-domretrylibrary
Usage
Import the library in your Robot Framework test file:
*** Settings ***
Library SeleniumLibrary
Library DomRetryLibrary # Just use the direct class name
Define your locators and AI fallback descriptions:
*** Variables ***
${USERNAME_FIELD} css=#non_existent_username_id
${AI_USERNAME_FIELD} the username input field with placeholder 'Username'
Use the AI fallback in your tests:
*** Test Cases ***
Login Test
Open Browser https://example.com chrome
AI Fallback Locator Input Text USERNAME_FIELD myusername
Close Browser
New in Version 2.3.0: Direct AI Descriptions
You can now provide the AI description directly without needing to define an AI_ variable:
AI Fallback Locator Input Text css=#username myusername ai_description=the username input field
This approach is especially useful when you:
- Want to use a dynamic description
- Need to use locators without defining variable pairs
- Prefer inline descriptions for better readability
- Need to quickly test different descriptions
New in Version 2.4.0: Backward Compatibility for Existing Test Patterns
Version 2.4.0 adds intelligent backward compatibility for existing test patterns. It's now more forgiving and will:
- Handle empty locators by inferring from context
- Find any matching AI_ variable if none is explicitly specified
- Continue execution rather than failing when no description is found
This means your existing test structure will still work:
*** Keywords ***
Wait And Input Text
[Arguments] ${locator} ${text}
${status} ${error}= Run Keyword And Ignore Error Input Text ${locator} ${text}
Run Keyword If '${status}' == 'FAIL' AI Fallback Locator Input Text ${locator} ${text}
And empty locator variables will be handled gracefully:
*** Variables ***
${SUBMIT_BUTTON} # Empty locator
${AI_SUBMIT_BUTTON} the login button
*** Test Cases ***
Login Test
AI Fallback Locator Click Element ${SUBMIT_BUTTON} # Works with empty locator
API Key Setup
Store your OpenAI API key in a .env file in your project directory:
OPENAI_API_KEY=your_api_key_here
Or provide it when initializing the library:
*** Settings ***
Library DomRetryLibrary api_key=${OPENAI_API_KEY}
How It Works
- The library first attempts to use your primary locator
- If the primary locator fails, it uses OpenAI to generate a new locator based on your description
- The AI-generated locator is used as a fallback
- Successful fallbacks are logged for future reference
Library Parameters
When importing the library, you can set several parameters:
Library DomRetryLibrary
... api_key=${OPENAI_API_KEY}
... model=gpt-4o
... locator_storage_file=my_locators.json
| Parameter | Default | Description |
|---|---|---|
| api_key | None | OpenAI API key (falls back to environment variable) |
| model | gpt-4o | OpenAI model to use |
| locator_storage_file | locator_comparison.json | File to store successful AI locators |
Keywords
The library provides the following keywords:
AI Fallback Locator- Add AI fallback to any locator-based keyword
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file robotframework_domretrylibrary-2.4.0.tar.gz.
File metadata
- Download URL: robotframework_domretrylibrary-2.4.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c531ce6f00bc44e146b083ce7e279f3772b1f43ee53a82931f5adfefef01a17a
|
|
| MD5 |
a11279ee66639516e1736308a59f292b
|
|
| BLAKE2b-256 |
0933c1bd776920e65ebea5c14373814aaeef4ecdf825c2418e026b0066fe1c48
|
File details
Details for the file robotframework_domretrylibrary-2.4.0-py3-none-any.whl.
File metadata
- Download URL: robotframework_domretrylibrary-2.4.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
108da4c37e5376f3b039a80d9238a1af642cfe327e0b82d87fb1bdf4b42fa8de
|
|
| MD5 |
3615115c3f63dedc9f866ec85489426f
|
|
| BLAKE2b-256 |
6cd303338e31adb22f625e76ac250bc0d8872bdeff54420af45e2ba28f225d06
|