QA MadnessBlog 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: 9minutes
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.
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.
Layout and responsive behaviour — the dashboard on a narrow viewport
UI
Only a browser renders
Visual checks — a chart that draws, a modal that is not cut off
UI
Nothing below the browser can see this
Critical user journeys — sign up, add a card, land on the dashboard
UI
The journey is the product. The user does not experience it as 6 requests
Browser-specific behaviour — file upload, clipboard, date pickers
UI
The 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.
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.
Step
What changes
Risk
1. Inventory
List every UI test with its runtime and its failure rate over the last 60 days
Nothing yet. Resist fixing things while counting
2. Move data setup to the API
Tests still run through the UI, but reach their starting state through requests
Setup 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 tests
Validation, permissions, pricing and error codes leave the browser
Coverage looks like it dropped, because the API test reports differently. Compare what is checked, not test counts
4. Delete the UI tests you replaced
Suite shrinks. This is the step teams skip
Deleting a UI test that checked something extra nobody documented. Read each one before it goes
5. Re-tier what remains
API tests and the critical journeys run on every build. Cross-browser, responsive and visual passes move to nightly
Moving 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.
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.
Last updated: August 27, 2026 Most engineering teams don't have a testing problem. They have a time problem. Writing test cases takes hours. Regression suites grow until they block every release. Automation scripts break the moment a UI element shifts. And the QA team spends its best hours on work that a well-configured system could handle instead. AI in software testing changes that equation, not by replacing QA engineers, but by absorbing the mechanical, repetitive layer of their work so engineers can focus on what actually requires human judgment. By 2027, Gartner projects that 80% of software engineering organizations will use AI-augmented testing tools, up from fewer than 20% in 2023. Teams that have already made the shift report up to 70% reductions in manual effort on repetitive QA tasks, according to Capgemini's World Quality Report. This article explains what AI in software testing actually means, which tasks it handles best, how it expands test coverage, and where...
Last updated: August 6, 2026 Most teams that struggle with QA automation do not have a tooling problem. They have a vendor problem. They hired a provider that can produce test scripts, but cannot explain what those tests protect, cannot connect coverage to business risk, and cannot keep the system maintainable as the product evolves. The market has moved. According to the 2025-2026 State of Testing report by PractiTest, AI adoption is now common in QA workflows. That raises the baseline. If a provider still treats automation as a collection of scripts instead of an engineering system, they are behind the market. This article focuses specifically on web automation for teams building automation from scratch or near-scratch. Mobile automation is a related track but requires a separate tooling discussion. And if your project already has an existing automation suite you want to hand off to an outsourced team, that scenario deserves its own evaluation framework, since the priorities...
The best software testing tools in 2026 span five categories: performance testing (Apache JMeter, k6), test automation (Playwright, Selenium, Cypress), unit testing (Vitest, Jest), test management (TestRail, Qase), and bug tracking (Jira, Linear). This guide covers 12 essential tools QA teams rely on daily – updated to reflect the shift toward AI-assisted testing and modern JavaScript-first frameworks that have replaced many legacy tools from previous years. Originally published: February 11, 2016 | Updated: June 5, 2026 What Are the Best QA Testing Tools in 2026? Modern QA teams need tools that integrate tightly with CI/CD pipelines, support AI-assisted testing, and work natively with JavaScript-first stacks. Below are 12 tools that cover the five core categories every QA organization needs. Performance Testing Tools Here are the most important tools to test the performance, load, and stress of your website or application. Apache JMeter is a 100% pure Java desktop application d...
SaaS companies ship fast. That's the whole point. Weekly sprints, continuous deployments, feature flags, multi-tenant architecture, third-party integrations stacked on top of integrations. The velocity is the product. But velocity without quality is just a faster way to lose customers. The numbers are unambiguous: 68% of users will abandon an application after encountering just two software bugs or glitches, and 88% are less likely to return after a bad experience. For SaaS, where the average B2B company already churns 3.5% of customers every single month, a quality problem is not a technical problem. It is a revenue problem. The solution most growing SaaS teams reach for is dedicated QA. This means testing is handled by people whose only job is quality — whether that is one specialist or a full team. Not developers context-switching into tester mode. Not a PM clicking through screens before a release. Dedicated QA specialists who know the product, own the quality process, a...