DEV Community

Cover image for TestFly Part 1: The Spring Boot of Selenium for zero-boilerplate Java test automation
Hakan GÜL
Hakan GÜL

Posted on Edited on Originally published at hakangul.lovable.app AI-assisted

TestFly Part 1: The Spring Boot of Selenium for zero-boilerplate Java test automation

TestFly is an opinionated test automation framework for Java 17+. This post shows how BaseTest, testfly.yml and ThreadLocal driver management get a test passing in under 60 seconds.

The idea behind TestFly

TestFly calls itself "the Spring Boot of Selenium". Building an enterprise-grade Selenium framework in Java has usually meant writing hundreds of lines of repetitive infrastructure code: configuring WebDriverManager, synchronizing thread-local instances, managing wait strategies and setting up screenshot listeners.

TestFly follows convention over configuration. BaseTest creates the driver and tears it down. Environment, timeouts and execution parameters live in testfly.yml. Each thread gets its own driver, so tests run in parallel without race conditions and without extra setup. After a run, a self-contained HTML report is written to target/testfly-report.html.

Quickstart in 60 seconds

1. Add the dependency to pom.xml

<dependencies>
    <dependency>
        <groupId>io.testfly</groupId>
        <artifactId>testfly</artifactId>
        <version>1.0.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

2. Create testfly.yml in the project root

execution:
  mode: local
  baseUrl: https://example.com

browser:
  name: chrome
  headless: false

timeouts:
  explicit: 10
  pageLoad: 30
Enter fullscreen mode Exit fullscreen mode

3. Write a test class

package io.testfly.examples;

import io.testfly.test.BaseTest;
import org.testng.annotations.Test;
import static org.testng.Assert.assertTrue;

public class SmokeTest extends BaseTest {

    @Test
    public void opensThePage() {
        open(); // navigates to execution.baseUrl from testfly.yml
        assertTrue(getDriver().getTitle().contains("Example Domain"));
    }

    @Test
    public void navigatesToSubpath() {
        open("/login"); // navigates to baseUrl + "/login"
    }
}
Enter fullscreen mode Exit fullscreen mode

Run it with Maven:

mvn test
Enter fullscreen mode Exit fullscreen mode

You don't write driver.quit() or new ChromeDriver() anywhere. TestFly manages the driver for you.

Top comments (0)