Contact Us
QA Madness Blog   API-First Test Automation: What to Automate First and What to Keep in the UI

API-First Test Automation: What to Automate First and What to Keep in the UI

Reading Time: 9 minutes

Originally Published: 27 November 2026 Last updated: 27 November 2026

Most slow, flaky suites are UI-heavy because the UI was the only place anyone could test from when someone wrote them. API-first moves every check that does not need a browser down to the service layer, leaving the UI tests to cover what only a browser can see. You get a faster suite, fewer false failures, and a small set of UI tests people trust.

This guide covers which checks belong where and how to rebalance an existing suite. For the theory behind the layers, see our article on the testing pyramid. Here, the focus is on the practical decision and a review of our test automation services that we bring to it.

It is written for QA leads, engineering managers and CTOs fixing a suite that takes too long or fails too often. The worked example is a SaaS product with sign-up, billing and a dashboard. QA Madness provides independent software testing services for SaaS and product teams across the UK, Europe and North America.

What does API-first test automation mean?

API-first test automation means choosing the API layer by default. A check moves up to the UI only when the browser does something the API cannot. It is a rule about where a check lives rather than a rule about writing fewer tests.

The reason is cost per check. A peer-reviewed study presented at the International Conference on Software Engineering in 2023 derived API test suites automatically from the UI tests of 7 open-source applications. The UI suites took 7 minutes on average; the API suites took 0.6 minutes, at 0.2% lower coverage.

Treat that as a direction rather than a constant. The spread across those 7 applications ran from 3 times faster to 150 times faster, on small and medium open-source apps. It remains the most recent published measurement of the 2 layers against the same flows.

The practice is current even where the measurement is not. A 2026 industrial paper from ByteDance and Fudan University reports a 9-month production deployment that carved API tests from network traffic, generating 3,196 test cases with an 85.4% code adoption rate.

What API-first is not. It does not mean “stop writing UI tests”. A suite with no UI tests cannot tell you the sign-up button renders, and the layer you drop is the one your users touch.

Where it is harder. API-first assumes you have an API worth testing against. If the UI talks to endpoints built for 1 screen, with state carried in the session, the API layer will not express your business rules cleanly. That is an architecture problem rather than a testing one, and it changes the size of the job.

Which checks belong at the API level?

Anything that is a rule, a calculation or a state change belongs at the API level. If you can describe the check without mentioning a screen, it does not need a browser.

For the SaaS example, that covers most of what the product does. Billing proration, plan limits, permission boundaries, validation rules, and error codes are all logic. Logic is cheaper and steadier to check through a request than through a form.

CheckAPI or UIWhy
Validation rules — rejected email formats, password policy, required fieldsAPI, mostlyServer-side enforcement is the real rule and belongs here. Keep 1 UI check per form for client-side messages, which the API never sees
Permissions — can a viewer edit billing, can one tenant read another’s dataAPI for enforcementNeeds many role and resource combinations, and each is a request rather than a login. Whether the UI hides the control is a separate UI check
Calculations — proration on a mid-cycle upgrade, tax, usage overageAPIThe arithmetic is the risk. A browser adds nothing except time
Error codes and messages — a declined card, 409 on a duplicate sign-upAPIThe UI usually collapses several distinct codes into 1 message, so the specific failure is only visible in the response
Data setup for other tests — create an account on a paid plan with 3 months of historyAPISetting this up by clicking is slow, breaks when the flow changes, and fails before the real check starts
Integration contracts — the billing provider’s webhook payloadAPIOur guide on API contract testing for microservices covers this layer specifically
Layout and responsive behaviour — the dashboard on a narrow viewportUIOnly a browser renders
Visual checks — a chart that draws, a modal that is not cut offUINothing below the browser can see this
Critical user journeys — sign up, add a card, land on the dashboardUIThe journey is the product. The user does not experience it as 6 requests
Browser-specific behaviour — file upload, clipboard, date pickersUIThe behaviour belongs to the browser rather than your service

Note the data setup row, because it changes a suite more than any other single move. A UI test that creates its account through 4 screens before testing 1 thing has 4 chances to fail for reasons unrelated to what it checks.

It also makes the failures readable. When setup happens through requests, a red test means the thing under test broke, rather than a form 3 steps earlier.

At QA Madness, that separation is the first change we make on a UI-heavy suite. It improves triage before it improves runtime.

Both major frameworks document this. Playwright’s authentication guide has a section called “Authenticate with API request”, and recommends reusing that state rather than rebuilding it per test. Cypress documents seeding through cy.request and caching the session with cy.session().

Which companies offer API test automation services? Most QA providers do, so the useful question is what they put around the tests. Ask which strategies they apply — contract testing, schema validation, data-driven checks — and whether the suite runs in your pipeline rather than on someone’s machine.

Ask how they handle test data too, since the setup is usually what makes an API suite slow or unreliable. Our API testing services cover contract testing, schema validation, and data-driven checks across environments, integrated into your CI.

What still needs a UI test?

3 things: what the browser renders, what the browser itself does, and the handful of journeys that lose money when they break. Everything else is a candidate for the layer below.

Keep the journeys small and few. For the SaaS example, that means 3: sign up through to a working dashboard, add a payment method, and 1 pass through the main dashboard view.

The test to apply is whether a failure would stop a customer paying you or leave them unable to work. If not, the check probably belongs a layer down.

Contract testing’s own documentation draws the boundary. Pact’s FAQ states that contract tests “replace a certain class of system integration test”. They “don’t replace the tests that ensure that the core business logic of your services is working”.

Pact frames the gain as a trade rather than a saving. The point is to “shift effort from high-maintenance, slow-feedback tests to low-maintenance, fast-feedback tests”, which is the same trade-off API-first makes across a whole suite.

Why the count matters more than the coverage. UI tests carry a maintenance cost that the layers below do not. A 2026 study of 359 open-source repositories identified 449 reproducible locator breaks, where a structural change to the application stopped a locator from finding its element “even when the underlying functionality remains unchanged”.

That is the defining UI failure: a red test and a working product. API tests have no locators to break.

Flakiness is also expensive at any level, and the current numbers are large. A 2026 study in IEEE Transactions on Software Engineering, covering 8.8 billion test executions across 4 industry-scale projects, found that undetected flaky failures accounted for 9.8% to 16.3% of failed pipeline runs.

1 caveat on the usual framing. A 2026 workshop paper at the International Conference on Software Engineering, studying flaky test reports in SAP HANA, found that test levels fail for different reasons rather than at different rates: system tests skewed towards timeouts and brittle oracles, unit tests towards isolation and platform issues. So the argument for fewer UI tests is maintenance cost and feedback time, not a claim that they are inherently more flaky.

How do you move an existing UI-heavy suite to API-first?

Do it by subtraction, in order, with the suite green at every step. The common failure is rewriting everything at once, then spending a month unable to tell whether a failure is a real bug or a migration artifact.

5 steps, each with 1 thing that can go wrong.

StepWhat changesRisk
1. InventoryList every UI test with its runtime and its failure rate over the last 60 daysNothing yet. Resist fixing things while counting
2. Move data setup to the APITests still run through the UI, but reach their starting state through requestsSetup drifts from the real flow. Keep 1 UI test that creates an account the way a user does
3. Rewrite rule and calculation checks as API testsValidation, permissions, pricing and error codes leave the browserCoverage looks like it dropped, because the API test reports differently. Compare what is checked, not test counts
4. Delete the UI tests you replacedSuite shrinks. This is the step teams skipDeleting a UI test that checked something extra nobody documented. Read each one before it goes
5. Re-tier what remainsAPI tests and the critical journeys run on every build. Cross-browser, responsive and visual passes move to nightlyMoving a journey to nightly, so a checkout defect waits 12 hours for anyone to see it

Step 4 is the one that makes the difference. A suite that gained API tests and lost no UI tests runs slower than when you started. Teams in that position often conclude API-first does not work, when what failed was step 4.

Expect the inventory in step 1 to be uncomfortable. In most UI-heavy suites, a small number of tests account for most of the runtime, and another small number account for most of the failures.

Those 2 lists rarely overlap. Between them they decide the first month of work.

How you run what remains counts too. Playwright’s command line documentation covers sharding across machines and –workers for parallelism. It also documents –last-failed, which re-runs just the failures, and –only-changed, which runs only test files changed against a ref and works with Git only.

1 caution on retries. –retries hides flakiness rather than fixing it, and a test that passes on attempt 3 is still telling you something. For the framework foundations underneath all this, see our guide on setting up a test automation framework.

Self-healing comes up often as the fix for a flaky UI layer. It repairs broken locators and cannot tell a moved element from a changed one. Our article on self-healing tests and AI test generation covers that in detail.

Put plainly: self-healing does not reduce the number of UI tests, and the number is the problem.

How do logs and monitoring help you decide what to test?

They tell you which paths users take in practice and which ones break, so coverage follows evidence rather than memory. Production data answers 2 questions a backlog cannot: what is used, and what fails.

3 sources are worth mining before you write another test.

➛ Request logs. Which endpoints carry real volume, and which combinations of parameters appear that nobody wrote a test for. Rare inputs are where untested behaviour hides.

➛ Error rates and status codes. A 500 appearing a few times a day on 1 endpoint is a test case with evidence behind it. So is a 409 nobody expected.

➛ Incident history. Anything that caused an incident deserves a test, because it has already demonstrated it can break.

A harder version of this exists, and it is worth separating from the 3 sources above. Those tell you what to write a test for. Replay goes further and uses the traffic itself as the test.

Uber published a worked example in November 2026. Rebuilding its query engine, the team mirrored real production traffic into 2 identically sized clusters running the old and new engines, and compared the results: the new engine completed 22,374 queries at a 99.12% success rate against 92.43% for the old one.

Meta described the same pattern at a different scale in a November 2026 paper, running “billions of replayed requests per day using under 1% of the corresponding serving capacity”.

Both teams put a hard limit on replay, as vendor material tends to drop. Meta’s paper is blunt about why: at scale, “experimental traffic can fan out across shared services, trigger latent defects, or send malformed input to systems serving user requests”.

That limit matters for a SaaS product. Replaying a sign-up or a payment against a live system creates real accounts and real charges. Anything that writes needs its own environment before it goes near production data.

The practical version for most teams needs none of that infrastructure and stays on the evidence side rather than the replay side. Export a month of endpoint usage and error counts. Sort by volume and by failure rate, then compare the top of each list against what your suite covers.

The gaps are your next tests, in order of priority, with evidence attached.

What to take away

If you can describe a check without mentioning a screen, it does not need a browser. Move data setup to the API before anything else, because it makes every test downstream faster and steadier. And delete the UI tests you replace, or the suite gets slower rather than faster.

Your next step is the inventory: every UI test, its runtime, and its failure rate over 60 days. That list usually makes the first 20 decisions for you.

Slow, flaky suite? Let’s rebalance it with our test automation services

FAQ

What should be automated first in a test automation strategy?

Start with the checks that are pure logic and run on every build: validation rules, permissions, pricing calculations and error codes, all at the API level. Add data setup through the API next, because it speeds up everything downstream. Leave UI automation for the few journeys that lose money when they break.

API testing vs UI testing: which should you automate?

Both, in different proportions. Automate at the API level by default, and reserve UI tests for rendering, browser behaviour and critical journeys. The most recent published measurement found API suites running more than 10 times faster than UI suites covering the same flows, at near-identical coverage.

How do you reduce flaky UI tests?

Reduce the number of them first, by moving logic checks to the API and setting up test data through requests rather than screens. Then stabilise what remains: deterministic data, no shared state between tests, and no fixed sleeps, since modern frameworks wait on state. Retries mask flakiness rather than fixing it, so track retry rates.

What is observability-driven testing?

It describes using production signals (logs, traces, error rates) to decide what to test, though the phrase is not established terminology. The documented terms are “testing in production” and OpenTelemetry’s “trace-based testing”. The practice is sound regardless of the label: let real usage data choose your next test.

Get your API test automation

Contact us

Ready to speed up the testing process?

QA Madness
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.