Performance Assertions (Core Web Vitals)
TestFly lets you assert Google's Core Web Vitals (LCP, CLS) and Navigation Timing metrics (FCP, FP, TTFB, DOMContentLoaded, full page load) directly in your Selenium tests — no extra tool, no proxy, no external service. Call assertPerformance() after open() and set thresholds for each metric. If a metric is not available in the current browser (for example LCP or CLS outside Chrome/Edge), that assertion is skipped with a logged warning instead of failing the test.
Quick example
public class HomepagePerformanceTest extends BaseTest {
@Test
public void homepage_meetsWebVitalThresholds() {
open("/");
assertPerformance()
.lcp().isBelow(2500) // Largest Contentful Paint < 2.5 s (Good)
.fcp().isBelow(1800) // First Contentful Paint < 1.8 s (Good)
.ttfb().isBelow(600) // Time To First Byte < 600 ms (Good)
.cls().isBelow(0.1); // Cumulative Layout Shift < 0.1 (Good)
}
}
Google Web Vitals thresholds
| Metric | Good | Needs Improvement | Poor |
|---|---|---|---|
| LCP — Largest Contentful Paint | < 2500 ms | < 4000 ms | ≥ 4000 ms |
| FCP — First Contentful Paint | < 1800 ms | < 3000 ms | ≥ 3000 ms |
| CLS — Cumulative Layout Shift | < 0.1 | < 0.25 | ≥ 0.25 |
| TTFB — Time To First Byte | < 800 ms | < 1800 ms | ≥ 1800 ms |
API reference
assertPerformance()
Available in BaseTest and BaseJUnit5Test. Collects metrics from the current page and returns a fluent PerformanceAssert builder.
assertPerformance()
.lcp().isBelow(2500)
.fcp().isBelow(1800)
.ttfb().isBelow(600)
.cls().isBelow(0.1)
.domLoad().isBelow(3000) // DOMContentLoaded
.pageLoad().isBelow(5000); // window.load (full page)
isBelow(double threshold)
Asserts the metric is strictly below the threshold. Throws AssertionError on failure with a message like:
[Performance] LCP exceeded threshold: LCP = 3420ms (threshold: < 2500ms)
isBelow(double threshold, String message)
Same as above with a custom failure message:
assertPerformance()
.lcp().isBelow(2500, "Homepage LCP regression after hero image update");
isAbove(double threshold)
For asserting a lower bound — useful to verify real server latency is measurable:
assertPerformance()
.ttfb().isAbove(0); // confirms a real HTTP round-trip occurred
collectPerformance()
Returns raw PerformanceMetrics for custom assertions or logging:
PerformanceMetrics perf = collectPerformance();
System.out.println("LCP: " + perf.lcp() + "ms");
System.out.println("CLS: " + perf.cls());
assertPerformance().lcp().isBelow(3000);
Chaining
Each isBelow() / isAbove() call returns the parent PerformanceAssert, enabling full chaining:
assertPerformance()
.lcp().isBelow(2500)
.fcp().isBelow(1800)
.ttfb().isBelow(600)
.cls().isBelow(0.1);
Metric availability by browser
| Metric | Chrome | Edge | Firefox | Safari |
|---|---|---|---|---|
| LCP | ✅ | ✅ | ❌ | ❌ |
| FCP | ✅ | ✅ | ✅ | ✅ (14.5+) |
| TTFB | ✅ | ✅ | ✅ | ✅ |
| CLS | ✅ | ✅ | ❌ |