A simple BDD test framework that uses AI to automatically fix broken element locators.
One working test that demonstrates how AI can fix broken Selenium tests automatically. When an element locator fails, AI analyzes the page and suggests a new one!
- β One Working Test - Wikipedia search demo
- β AI Self-Healing - Automatically fixes broken locators
- β BDD with Reqnroll - Tests written in plain English
- β Free AI (Ollama) - Runs on your computer
- β Fully Commented Code - Easy to understand
- .NET 9 SDK - https://dotnet.microsoft.com/download/dotnet/9.0
- Google Chrome - https://www.google.com/chrome/
- Ollama - https://ollama.ai
# 1. Install Ollama AI model
ollama pull qwen3-coder:480b-cloud
# 2. Navigate to project
cd SeleniumSelfHealing.Reqnroll.Net9
# 3. Build
dotnet restore
dotnet build
# 4. Run the test
dotnet test --logger "console;verbosity=detailed"That's it! Watch AI fix the broken locator automatically! β¨
SeleniumSelfHealing.Reqnroll.Net9/
β
βββ Features/
β βββ WikipediaDemo.feature β Test in plain English
β
βββ StepDefinitions/
β βββ WikipediaDemoSteps.cs β Step implementations
β
βββ Pages/
β βββ WikipediaPage.cs β Page with WRONG locator (on purpose!)
β
βββ Utilities/
β βββ LlmClient.cs β AI communication (fully commented)
β βββ LlmConfig.cs β AI settings (fully commented)
β βββ WebDriverExtensions.cs β Self-healing magic (fully commented)
β
βββ Support/
βββ Hooks.cs β Test setup/teardown
Features/WikipediaDemo.feature:
Feature: Wikipedia Search Demo
@demo @working
Scenario: Search for Selenium on Wikipedia
Given I navigate to "https://www.wikipedia.org"
When I search for "Selenium"
Then the page should contain "Selenium"Simple! Written in plain English!
The test uses a WRONG locator on purpose:
// Pages/WikipediaPage.cs
private readonly By _searchBox = By.Id("searchBox"); // WRONG!
// Real ID is: "searchInput"1. Test tries By.Id("searchBox")
β Element not found!
2. AI analyzes the page HTML
π€ "I see an input with id='searchInput'"
3. AI suggests new locator
π‘ "Try: //input[@id='searchInput']"
4. Test tries AI's suggestion
β
Found it! Test continues!
βΆοΈ Step: When I search for "Selenium"
Element not found with By.Id: searchBox
Attempting self-healing for: Wikipedia search box
Asking AI for help (attempt 1/3)...
AI suggested: //input[@id='searchInput']
Self-healing successful! New locator works!
β
Entered text in: Wikipedia search box
β
Test Passed!
This proves AI self-healing works! π
All AI code is fully commented for beginners:
// STEP 1: Try finding element the normal way first
try
{
return driver.FindElement(locator); // Try original locator
}
catch (NoSuchElementException)
{
// Element not found - time for self-healing!
}
// STEP 2: Ask AI for help
var suggestedLocator = await aiClient.GetSuggestedLocator(
pageHTML, // The webpage code
failedLocator, // What didn't work
"Search box" // What we're looking for
);
// STEP 3: Try AI's suggestion
var element = driver.FindElement(By.XPath(suggestedLocator));
// β
It works!appsettings.json - AI settings:
{
"Provider": "Local",
"BaseUrl": "http://localhost:11434",
"Model": "qwen3-coder:480b-cloud",
"Temperature": 0.1,
"MaxTokens": 1000
}Use OpenAI instead? Change to:
{
"Provider": "OpenAI",
"ApiKey": "sk-your-api-key-here",
"BaseUrl": "https://api.openai.com/v1",
"Model": "gpt-4o"
}Starting test execution...
Passed! - Failed: 0, Passed: 1, Total: 1
β
1 test runs
β
AI self-healing activates
β
Test passes
Feature: My Test
Scenario: Test my website
Given I navigate to "https://mysite.com"
When I click the login button
Then I should see the login form[Given(@"I navigate to ""(.*)""")]
public async Task GivenINavigateTo(string url)
{
_driver.Navigate().GoToUrl(url);
}
[When(@"I click the login button")]
public async Task WhenIClickLogin()
{
// Uses self-healing automatically!
await _driver.Click(By.Id("login"), "Login button");
}dotnet testAI will fix broken locators automatically! β¨
Ollama isn't running. Start it:
# Mac/Linux
ollama serve
# Windows - Click Ollama icon in system trayInstall .NET 9 SDK from https://dotnet.microsoft.com/download/dotnet/9.0
dotnet clean
dotnet restore
dotnet build# Run test
dotnet test
# See detailed output (watch AI heal!)
dotnet test --logger "console;verbosity=detailed"
# Clean and rebuild
dotnet clean && dotnet restore && dotnet build- One Working Test - Wikipedia search demo
- Intentional Wrong Locator - Proves self-healing works
- Free AI - Uses Ollama (or paid OpenAI)
- Fully Commented - 430+ lines explaining everything
- Ready to Customize - Build your own tests easily
β
AI automatically fixing broken locators
β
No manual intervention needed
β
Tests that heal themselves
- Run the demo - See AI self-healing work
- Read the comments - Understand how it works
- Create your own test - Use as template
- Customize - Add your own pages and scenarios
- This file - Simple overview
- Code comments - Every line explained
# Everything in 3 commands:
ollama pull qwen3-coder:480b-cloud
dotnet restore && dotnet build
dotnet test --logger "console;verbosity=detailed"Ready to see AI fix your tests automatically? Run it now! π
For detailed explanations, check the commented code in Utilities/ folder!
