TestFly and the Model Context Protocol
The testfly-mcp companion server connects TestFly to AI coding assistants such as Claude Desktop, Cursor, Copilot and Antigravity.
Connecting testfly-mcp
Add the server to your mcp_config.json:
{
"mcpServers": {
"testfly-mcp": {
"command": "npx",
"args": ["-y", "testfly-mcp@latest"]
}
}
}
Generating TestFly code from a user journey
Through MCP, the assistant launches a browser, records the interactions and writes TestFly code that uses accessibility-first locators. A checkout flow comes out like this:
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");
}
}
Self-healing locators
Turn on locators.selfHealing in testfly.yml:
locators:
selfHealing: true
If an element can't be found with its primary selector, TestFly's healing engine looks at the surrounding DOM attributes (accessible name, ARIA role, nearby text) to find it, and the CI pipeline stays green.
Top comments (0)