DEV Community

Cover image for TestFly Part 4: AI-Assisted Test Generation with testfly-mcp & Self-Healing Locators
Hakan GÜL
Hakan GÜL

Posted on Originally published at hakangul.lovable.app

TestFly Part 4: AI-Assisted Test Generation with testfly-mcp & Self-Healing Locators

The Next Frontier: Model Context Protocol & TestFly

TestFly bridges modern AI coding assistants (Claude Desktop, Cursor, Copilot, Antigravity) through the testfly-mcp companion server.


1. Connecting testfly-mcp

Add to your mcp_config.json:

{
  "mcpServers": {
    "testfly-mcp": {
      "command": "npx",
      "args": ["-y", "testfly-mcp@latest"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

2. Generating TestFly Code from User Journeys

The AI launches a browser via MCP, records interactions, and writes clean TestFly code utilizing accessibility-first locators:

package io.testfly.examples;

import io.testfly.test.BaseTest;
import io.testfly.locator.Role;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;

public class CheckoutFlowTest extends BaseTest {

    @Test
    public void userCompletesPurchase() {
        open("/products");
        getByRole(Role.BUTTON).withName("Add to Cart").click();
        getByRole(Role.LINK, "Checkout").click();
        getByLabel("Full Name").type("Hakan Gül");
        getByRole(Role.BUTTON).withName("Place Order").click();

        assertEquals(getByTestId("order-status").getText(), "CONFIRMED");
    }
}
Enter fullscreen mode Exit fullscreen mode

3. Self-Healing Locators (locators.selfHealing)

Enable locator self-healing in testfly.yml:

locators:
  selfHealing: true
Enter fullscreen mode Exit fullscreen mode

When an element is not found by its primary selector, TestFly's healing engine analyzes surrounding DOM attributes (accessible name, ARIA role, nearby text) to locate the element and keep your CI pipeline green.

Top comments (0)