### Install robotframework-heal Source: https://github.com/manykarim/robotframework-heal/blob/main/README.md Install the library using pip. This is the first step to enable self-healing in your Robot Framework projects. ```bash pip install robotframework-heal ``` -------------------------------- ### Web Test with Full Self-Healing Configuration Source: https://context7.com/manykarim/robotframework-heal/llms.txt Example of a web test case using the SelfHealing library with a full configuration. Locators for 'Fill Text' and 'Click' operations will be monitored and healed if necessary. ```robotframework *** Settings *** Library SelfHealing ... fix=realtime ... collect_locator_info=True ... use_locator_db=True ... use_llm_for_locator_proposals=True *** Test Cases *** Test With Full Self-Healing Configuration New Page https://example.com # All locator operations will be monitored and healed if needed Fill Text id=username testuser Fill Text id=password secret123 Click id=loginbutton ``` -------------------------------- ### Basic Self-Healing Setup Source: https://github.com/manykarim/robotframework-heal/blob/main/README.md Add the SelfHealing library to your Robot Framework suite's Settings section to enable basic self-healing functionality. ```robotframework *** Settings *** Library SelfHealing ``` -------------------------------- ### Configure LLM Providers via Environment Variables Source: https://context7.com/manykarim/robotframework-heal/llms.txt Set environment variables to configure LLM providers like Ollama or OpenAI for the LiteLLM API used by SelfHealing. Ensure the correct API base, text model, locator model, and vision model are specified. ```bash # Using Ollama (local LLM) export LLM_API_BASE=http://localhost:11434 export LLM_TEXT_MODEL=ollama_chat/llama3.1 export LLM_LOCATOR_MODEL=ollama_chat/llama3.1 export LLM_VISION_MODEL=ollama_chat/llama3.2-vision # Using OpenAI export LLM_API_KEY=YOUR_OPENAI_API_KEY export LLM_TEXT_MODEL=gpt-3.5-turbo export LLM_LOCATOR_MODEL=gpt-3.5-turbo ``` -------------------------------- ### Configure OpenAI LLM for Self-Healing Source: https://github.com/manykarim/robotframework-heal/blob/main/README.md Set environment variables to connect robotframework-heal to OpenAI's API for text and locator generation. Replace 'YOUR_OPENAI_API_KEY' with your actual key. ```bash LLM_API_KEY=YOUR_OPENAI_API_KEY LLM_TEXT_MODEL=gpt-3.5-turbo LLM_LOCATOR_MODEL=gpt-3.5-turbo ``` -------------------------------- ### Full Configuration for Self-Healing Library Source: https://context7.com/manykarim/robotframework-heal/llms.txt Configure SelfHealing with all available arguments for real-time healing and locator information collection. Ensure 'locator_db_file' is set if 'use_locator_db' is true. ```robotframework Library SelfHealing ... fix=realtime # Mode: "realtime" for immediate healing ... collect_locator_info=True # Collect locator details during successful runs ... use_locator_db=True # Use stored locator info for better healing decisions ... use_llm_for_locator_proposals=True # Use LLM for generating locator proposals ... heal_assertions=False # Experimental: heal assertion failures ... locator_db_file=locator_db.json # Path to locator database file ``` -------------------------------- ### Running Robot Framework Tests with Self-Healing Source: https://context7.com/manykarim/robotframework-heal/llms.txt Execute Robot Framework tests normally using the 'robot' command. The self-healing listener activates automatically on locator failures. Use --loglevel DEBUG to see healing messages. ```bash # Run tests with default settings robot --outputdir results tests/ # Run with specific browser and headless mode robot --variable BROWSER:firefox --variable HEADLESS:True tests/todo_broken_llm.robot # Run with verbose output to see healing messages robot --loglevel DEBUG tests/ # Run Appium mobile tests robot --include appium tests/appium_saucedemo.robot ``` -------------------------------- ### Basic Usage with LLM-Powered Healing Source: https://context7.com/manykarim/robotframework-heal/llms.txt Configure SelfHealing library with LLM support enabled for AI-powered locator recovery. Ensure Browser library and other necessary configurations are set up. ```robotframework *** Settings *** Library Browser timeout=5s Library SelfHealing use_llm_for_locator_proposals=True Suite Setup New Browser browser=${BROWSER} headless=${HEADLESS} Test Setup New Context viewport={'width': 1280, 'height': 720} Test Teardown Close Context Suite Teardown Close Browser ALL *** Variables *** ${BROWSER} chromium ${HEADLESS} True *** Test Cases *** Add Two ToDos And Check Items [Documentation] Checks if ToDos can be added and ToDo count increases [Tags] Add ToDo Given ToDo App is open When I Add A New ToDo "Learn Robot Framework" And I Add A New ToDo "Write Test Cases" Then Open ToDos should show "2 items left!" *** Keywords *** ToDo App is open New Page https://todomvc.com/examples/react/dist/ I Add A New ToDo "${todo}" # Even if .todo selector breaks, SelfHealing will find the correct input Fill Text .todo ${todo} Press Keys .todo Enter Open ToDos should show "${text}" Get Text span.todo-count == ${text} ``` -------------------------------- ### Configure Ollama LLM for Self-Healing Source: https://github.com/manykarim/robotframework-heal/blob/main/README.md Set environment variables to connect robotframework-heal to a local Ollama LLM instance for text and locator generation. ```bash LLM_API_BASE=http://localhost:11434 LLM_TEXT_MODEL=ollama_chat/llama3.1 LLM_LOCATOR_MODEL=ollama_chat/llama3.1 LLM_VISION_MODEL=ollama_chat/llama3.2-vision ``` -------------------------------- ### Locator Database for Improved Healing Source: https://context7.com/manykarim/robotframework-heal/llms.txt Enable locator database collection and usage to improve healing accuracy. Run the 'First Run' test case to build the database, then subsequent runs will utilize it. ```robotframework *** Settings *** Library Browser timeout=5s # Enable locator database collection and usage Library SelfHealing ... collect_locator_info=True ... use_locator_db=True ... locator_db_file=my_locator_db.json *** Test Cases *** First Run - Collect Locator Information [Documentation] Run this first to build the locator database New Page https://todomvc.com/examples/react/dist/ # Successful locator interactions are stored in the database Fill Text .new-todo Learn Robot Framework Press Keys .new-todo Enter Click input.toggle Get Text span.todo-count == 0 items left! Second Run - Healed Locators Use Database [Documentation] Subsequent runs use stored info for better healing decisions New Page https://todomvc.com/examples/react/dist/ # If .todo-input is broken, the database helps select the best replacement Fill Text .todo-input Write Test Cases Press Keys .todo-input Enter ``` -------------------------------- ### Check Output Directory Source: https://context7.com/manykarim/robotframework-heal/llms.txt After running tests, check the output directory for generated files like HTML reports and XML output. ```bash ls -la results/ ``` -------------------------------- ### SelfHealing Library Arguments Details Source: https://github.com/manykarim/robotframework-heal/blob/main/docs/index.md Detailed explanation of each argument for the SelfHealing library. ```APIDOC ## Arguments * `fix`: Specifies the mode of operation, set to "realtime" for real-time healing. Default is "realtime". * `collect_locator_info`: Boolean flag to enable or disable the collection of locator information. Default is false. * `use_locator_db`: Boolean flag to enable or disable the use of a locator database. Default is false. * `use_llm_for_locator_proposals`: Boolean flag to enable or disable the use of a language model for generating locator proposals. If true, locator proposals will be identified from DOM Tree via LLM. If set to false, locator proposals are generated via CSS/XPATH generator. Default is false. * `heal_assertions`: Boolean flag to enable or disable the healing of assertions. Default is false. (not implemented yet) * `locator_db_file`: Specifies the filename for the locator database. Default is "locator_db.json". ``` -------------------------------- ### Basic Usage with CSS/XPath Parser (No LLM) Source: https://context7.com/manykarim/robotframework-heal/llms.txt Configure SelfHealing library without LLM support, using the built-in CSS/XPath generator for locator recovery. This is suitable for environments without AI integration. ```robotframework *** Settings *** Library Browser timeout=5s Library SelfHealing use_llm_for_locator_proposals=False Suite Setup New Browser browser=${BROWSER} headless=${HEADLESS} Test Setup New Context viewport={'width': 1280, 'height': 720} Test Teardown Close Context Suite Teardown Close Browser ALL *** Variables *** ${BROWSER} chromium ${HEADLESS} True *** Test Cases *** Add ToDo And Mark Same ToDo [Tags] Mark ToDo Given ToDo App is open When I Add A New ToDo "Learn Robot Framework" And I Mark ToDo "Learn Robot Framework" Then Open ToDos should show "0 items left!" *** Keywords *** ToDo App is open New Page https://todomvc.com/examples/react/dist/ I Add A New ToDo "${todo}" Fill Text .todo ${todo} Press Keys .todo Enter I Mark ToDo "${todo}" # Self-healing will recover this locator if the HTML structure changes Click input.toggle >> "${todo}" Open ToDos should show "${text}" Get Text span.todo-count == ${text} ``` -------------------------------- ### SelfHealing Library Arguments Configuration Source: https://context7.com/manykarim/robotframework-heal/llms.txt Configure the SelfHealing library using arguments in the Settings section to control healing behavior, locator database usage, and LLM integration. ```robotframework *** Settings *** ``` -------------------------------- ### Jinja2 Template for Displaying Test Result Details Source: https://github.com/manykarim/robotframework-heal/blob/main/src/SelfHealing/template.html Jinja2 template syntax for rendering specific test result details like broken locators, fixed locators, suite names, test names, file paths, line numbers, and screenshots. Includes conditional logic for screenshot availability. ```html {{ row.broken_locator }} {{ row.fixed_locator }} Copy Copied! {{ row.suite_name }} {{ row.test_name }} [{{ row.source }}](vscode://file/{{ row.source }}:{{ row.lineno }}) {{ row.lineno }} {% if row.screenshot %} ![Screenshot](data:image/png;base64,{{ row.screenshot }}) {% else %} No screenshot available {% endif %} ``` -------------------------------- ### Advanced Self-Healing with LLM Locator Proposals Source: https://github.com/manykarim/robotframework-heal/blob/main/README.md Configure the SelfHealing library to use LLMs for generating locator proposals. Ensure necessary environment variables for LLM access are set. ```robotframework *** Settings *** Library Browser timeout=5s Library SelfHealing use_llm_for_locator_proposals=True Suite Setup New Browser browser=${BROWSER} headless=${HEADLESS} Test Setup New Context viewport={'width': 1280, 'height': 720} Test Teardown Close Context Suite Teardown Close Browser ALL *** Variables *** ${BROWSER} chromium ${HEADLESS} True *** Test Cases *** Login with valid credentials New Page https://the-internet.herokuapp.com/login Fill Text id=user tomsmith Fill Text id=pass SuperSecretPassword! Click id=loginbutton Get Text id=flash *= You logged into a secure area! ``` -------------------------------- ### Configuring LLM Environment Variables Source: https://github.com/manykarim/robotframework-heal/blob/main/docs/index.md Set environment variables to configure the LLM interface for self-healing. ```bash # Example with Ollama LLM LLM_API_BASE=http://localhost:11434 LLM_TEXT_MODEL=ollama_chat/llama3.1 LLM_LOCATOR_MODEL=ollama_chat/llama3.1 LLM_VISION_MODEL=ollama_chat/llama3.2-vision # Example with OpenAI LLM_API_KEY=YOUR_OPENAI_API_KEY LLM_TEXT_MODEL=gpt-3.5-turbo LLM_LOCATOR_MODEL=gpt-3.5-turbo ``` -------------------------------- ### SelfHealing Library Arguments Source: https://github.com/manykarim/robotframework-heal/blob/main/docs/index.md Available arguments for configuring the SelfHealing library. ```robotframework # Example with arguments *** Settings *** Library SelfHealing fix=realtime collect_locator_info=True use_locator_db=True use_llm_for_locator_proposals=True heal_assertions=True locator_db_file=my_locators.json ``` -------------------------------- ### Appium Mobile Testing with Self-Healing Source: https://context7.com/manykarim/robotframework-heal/llms.txt Integrate SelfHealing with AppiumLibrary for Android mobile testing. Configure SelfHealing to disable LLM proposals if not needed. Locators are automatically healed. ```robotframework *** Settings *** Library AppiumLibrary Library Process Library OperatingSystem Library SelfHealing use_llm_for_locator_proposals=False Test Tags appium *** Variables *** ${ANDROID_AUTOMATION_NAME} UIAutomator2 ${ANDROID_APP} ${CURDIR}${/}demoapp${/}SauceLabsDemo.apk ${ANDROID_PLATFORM_NAME} Android ${ANDROID_PLATFORM_VERSION} %{ANDROID_PLATFORM_VERSION=8} *** Test Cases *** Start Demo App with broken username and password Open Test Application Wait Until Element Is Visible //android.widget.EditText[@text,"Username"] # These locators will be healed if they become outdated Input Text //android.widget.EditText[@content-desc="User"] standard_user Input Text //android.widget.EditText[@content-desc="Password"] secret_sauce Click Element Login Wait Until Page Contains text=PRODUCTS Close unexpected permission popup # SelfHealing automatically detects and closes permission popups Open Test Application Login Click Element //android.view.ViewGroup[@content-desc="test-Menu"] Click Element //android.widget.TextView[contains(@text, 'QR CODE SCANNER')] Sleep 1 # If a permission dialog appears, it will be automatically handled Click Element //android.view.View[@resource-id="com.swaglabsmobileapp:id/texture_view"] *** Keywords *** Open Test Application Open Application http://127.0.0.1:4723 automationName=${ANDROID_AUTOMATION_NAME} ... platformName=${ANDROID_PLATFORM_NAME} platformVersion=${ANDROID_PLATFORM_VERSION} ... appPackage=com.swaglabsmobileapp appActivity=com.swaglabsmobileapp.MainActivity ... newCommandTimeout=300 Login Wait Until Element Is Visible //android.widget.EditText[@text,"Username"] Input Text //android.widget.EditText[@text="Username"] standard_user Input Text //android.widget.EditText[@text="Password"] secret_sauce Click Element //android.widget.TextView[@text="LOGIN"] Wait Until Page Contains text=PRODUCTS ``` -------------------------------- ### Jinja2 Template for Test Data Iteration Source: https://github.com/manykarim/robotframework-heal/blob/main/src/SelfHealing/template.html A Jinja2 template snippet used to iterate over test result data. It dynamically generates table rows based on the provided data. ```html {% for row in data %} {% endfor %} ``` -------------------------------- ### Self-Healing Process Flow Source: https://github.com/manykarim/robotframework-heal/blob/main/docs/features.md Visual representation of the self-healing workflow triggered upon keyword failure. ```mermaid graph TD A[end_library_keyword] --> B{Status?}; B -->|FAIL| C{Broken Locator?}; C --> |YES| D[Get Fixed Locator]; D --> F{Get Locator proposals via} F --> |LLM| G[Use LLM for Locator Proposals]; F --> |CSS/XPATH| H[Use CSS/XPATH Generator]; G --> J[Add Details to Locator Proposals]; H --> J[Add Details to Locator Proposals]; B ----->|PASS| E[Continue with Execution]; J --> LLM[Send Locator Proposals to LLM] --> K{Fixed Locator Found?}; K -->|YES| E; K -->|NO| I; C -------> |NO| I[FAIL]; ``` -------------------------------- ### Fixed Locators HTML Structure Source: https://context7.com/manykarim/robotframework-heal/llms.txt The fixed_locators.html file provides a report detailing healed locators, including test and suite names, keywords, line numbers, source files, broken locators, and their fixed counterparts. ```html ``` -------------------------------- ### HTML Structure for Test Results Table Source: https://github.com/manykarim/robotframework-heal/blob/main/src/SelfHealing/template.html Defines the CSS styling for the test results table, including fonts, borders, and row highlighting. Used for presenting test case outcomes. ```html body { font-family: 'Roboto', sans-serif; } table { width: 100%; border-collapse: collapse; } th, td { padding: 8px; text-align: left; border: 1px solid #ddd; position: relative; } th { background-color: #4CAF50; color: white; } tr:nth-child(even) { background-color: #f2f2f2; } tr:hover { background-color: #ddd; } .copy-btn { padding: 5px 10px; background-color: #e0e0e0; color: black; border: 1px solid #ccc; cursor: pointer; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); } .copy-btn:hover { background-color: #d0d0d0; } .copy-message { display: none; color: green; margin-left: 10px; } ``` -------------------------------- ### JavaScript Function to Copy Text to Clipboard Source: https://github.com/manykarim/robotframework-heal/blob/main/src/SelfHealing/template.html A JavaScript function that copies provided text to the user's clipboard and displays a confirmation message. It dynamically creates a textarea element for the copy operation. ```javascript function copyToClipboard(text) { const textarea = document.createElement('textarea'); textarea.value = text; document.body.appendChild(textarea); textarea.select(); document.execCommand('copy'); document.body.removeChild(textarea); const message = event.target.nextElementSibling; message.style.display = 'inline'; setTimeout(() => { message.style.display = 'none'; }, 2000); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.