Today I'm excited to present ai-locators
for Playwright! π
// π Say goodbye to this complexity
page.locator("//div[contains(@class, 'header')]//button[contains(@class, 'login') and not(@disabled) and contains(text(), 'Sign In')]");
// π And hello to this simplicity!
page.locator("ai=the login button in the header that says Sign In");
π Check it out: https://github.com/lila-team/ai-locators
π« The Problem
Let's face it - maintaining locators in Playwright tests can be a real headache! π€ They depend on how elements are positioned and declared in the frontend, which changes constantly and breaks your tests.
Sure, you could follow best practices like maintaining test-ids or being consistent with roles and labels (check out these best practices). But let's be real - developers want to move fast, and tests that are hard to maintain often get left behind! πββοΈπ¨
π€ LLMs to the Rescue!
Here's where the magic happens! β¨ This project uses LLMs to generate selectors based on the HTML content and your natural description of the elements you want to find.
It's implemented as a custom selector engine so it fits perfectly into your existing Playwright codebase! π§©
// π Search the entire page
const element = page.locator("ai=the login button");
await element.click();
// π― Search inside a container
const container = page.locators('.main-div');
const element = container.locator("ai=search input");
await element.fill("foobar");
π¨ Choose Your LLM!
When registering the custom selector (check out our README for the how-to), you can pick your favorite LLM to power the magic - as long as it follows the OpenAI API! πͺ
π Great news! ai-locators is available in both python and node! Give it a try and let us know what you think! π
π Link to project: https://github.com/lila-team/ai-locators
ai-locators
is available for Python and for Node.
Top comments (0)