Getting Started
Get your first TestFly test running in under 5 minutes.
Prerequisites
- Java 21+
- Maven 3.8+ or Gradle 8.5+
- Chrome, Firefox, or Edge installed (network mocking, device emulation and geolocation need Chrome or Edge, see Browser Support)
No WebDriver binaries required — Selenium Manager handles browser driver downloads automatically.
You can scaffold a production-ready TestFly Java 21 project with a single command:
npx @testfly/mcp init my-test-suite
This generates pom.xml, testfly.yml, and ready-to-run sample tests. Learn more in the TestFly MCP & CLI Guide.
Manual Setup
If adding TestFly to an existing project, follow the steps below:
Step 1 — Add the dependency
The examples below use the 1.1.0 source version. Before the release is published, check Maven Central for availability or use the latest published version instead.
- Maven (pom.xml)
- Gradle Groovy (build.gradle)
- Gradle Kotlin (build.gradle.kts)
<dependency>
<groupId>io.github.hakanngul</groupId>
<artifactId>testfly</artifactId>
<version>1.1.0</version>
</dependency>
dependencies {
testImplementation 'io.github.hakanngul:testfly:1.1.0'
}
test {
useTestNG()
systemProperties System.properties
}
dependencies {
testImplementation("io.github.hakanngul:testfly:1.1.0")
}
tasks.test {
useTestNG()
systemProperties(System.getProperties().mapKeys { it.key.toString() })
}
See the full Gradle Setup Guide for parallel config, JUnit 5, optional deps, and report locations.
Step 2 — Create the configuration file
Create testfly.yml in your project root (next to pom.xml or build.gradle):
execution:
mode: local
baseUrl: https://your-app.com
browser:
name: chrome
headless: false
retry:
enabled: true
maxAttempts: 2
timeouts:
explicit: 10
pageLoad: 30
execution.mode, execution.baseUrl, browser.name, timeouts.explicit, and timeouts.pageLoad are mandatory. If any of them is missing, TestFly stops at startup with a configuration error. Everything else has a sensible default.
Step 3 — Write your first test
import io.testfly.test.BaseTest;
import org.testng.annotations.Test;
public class LoginTest extends BaseTest {
@Test(description = "Valid user can log in")
public void loginTest() {
open(); // navigates to baseUrl
// your test steps here
softAssert().that(getDriver().getTitle().contains("Dashboard"), "Title should contain Dashboard");
}
}
Step 4 — Create a TestNG suite
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="testfly-suite" verbose="1">
<test name="MyTests">
<classes>
<class name="com.example.LoginTest"/>
</classes>
</test>
</suite>
Step 5 — Run
- Maven
- Gradle
mvn test
./gradlew test
What happens
- Framework loads
testfly.yml - Chrome launches automatically
- Your test runs
- Screenshot captured on any failure
- Browser closes
- HTML report generated at
target/testfly-report.html(Maven) orbuild/testfly-report/(Gradle) - Metrics JSON at
target/testfly-metrics.json
Project structure
- Maven
- Gradle
your-project/
├── pom.xml
├── testfly.yml
├── testng.xml
└── src/test/java/com/example/
├── pages/LoginPage.java
└── tests/LoginTest.java
your-project/
├── build.gradle (or build.gradle.kts)
├── testfly.yml
├── testng.xml
└── src/test/java/com/example/
├── pages/LoginPage.java
└── tests/LoginTest.java
Working example project
Every framework has a runnable reference project in the repository's examples/ directory. Each one is a standalone Maven project on TestFly 1.1.0 that runs offline with mvn -B test:
| Project | Shows |
|---|---|
testng-web | TestNG web UI: locators, self-healing, waits, assertions, recipes, accessibility, visual, network mocking |
junit5-web | JUnit 5 web UI: BaseJUnit5Test, @EnableTestFly, parameterized tests, @Nested |
cucumber | Cucumber BDD for web and API in one suite |
api-testng | REST API on TestNG: auth, schema/OpenAPI, mocks, polling, data-driven tests |
api-junit5 | REST API on JUnit 5 |
loadtest | Load testing on the jdk and Gatling engines |
mobile | Native Android and iOS page objects and tests |
advanced | DB, e-mail/OTP, SPI extensions, quality gates, AI, remote execution |
A complete working project is available at: https://github.com/hakanngul/testfly-test
Clone it, run mvn test (or ./gradlew test), and you'll have a full working suite with page objects, step logging, and retry configured.
Next steps
- TestFly Guide — how the pieces fit together, in one page
- Configuration Reference — all available config options
- BasePage — write clean page objects
- Step Logging — add named steps to your tests