Automation Testing Interview Questions and Answers
Last updated 2026-11-19
Automation testing interviews test judgement more than tool trivia. Which tests should be automated, at which layer, and how do you keep a suite fast and trustworthy as it grows? This page works through 15 questions on the test pyramid, framework architecture, data handling, flaky tests, CI integration and BDD, with pytest and Java examples you can run.
Tool-specific detail lives on the Selenium questions and API testing with Postman questions pages. If you are earlier in your career, start with the manual testing questions. For interview strategy see how to crack a QA testing interview.
| Core ideas | Test pyramid, maintainable frameworks, test data, CI feedback speed, flaky-test control |
|---|---|
| Typical stack | Selenium or Playwright, pytest or TestNG, REST-assured or requests, Docker, Jenkins or GitHub Actions |
| Interview style | Framework design discussion, a coding or debugging task, and scenario questions |
A compact pytest example worth knowing
Interviewers often ask for a parametrised test with a fixture. This test checks a discount function across several cases, shares set-up through a fixture and marks slow tests so CI can select a subset. Be ready to explain what each decorator does.
import pytest
def discount(total, code):
if code == 'SAVE10' and total >= 500:
return round(total * 0.10, 2)
return 0.0
@pytest.fixture
def cart_total():
return 1000
@pytest.mark.parametrize('total, code, expected', [
(1000, 'SAVE10', 100.0),
(500, 'SAVE10', 50.0),
(499, 'SAVE10', 0.0),
(1000, 'BAD', 0.0),
(1000, '', 0.0),
])
def test_discount_rules(total, code, expected):
assert discount(total, code) == expected
@pytest.mark.slow
def test_discount_on_fixture(cart_total):
assert discount(cart_total, 'SAVE10') == 100.0Automation Testing Interview Questions and Answers: questions with worked answers
1 What should be automated, and what should not?
easyAutomate tests that are repetitive, stable, deterministic, high value and run often: regression suites, smoke tests, data-driven checks with many input combinations, API contract checks and cross-browser checks. Do not automate exploratory testing, usability judgement, one-off tests, features still changing daily, or tests whose setup cost exceeds the value of repeating them. A useful filter is frequency times cost of manual execution compared with the cost to write and maintain the script. Start with the critical business paths and the checks that block releases, then expand deliberately.
2 Explain the test automation pyramid and why an inverted pyramid is a problem.
easyThe pyramid says to have many fast unit tests at the base, fewer integration and API tests in the middle, and very few slow end-to-end UI tests at the top. Lower-level tests are cheaper, faster and more stable, and they localise failures. An inverted pyramid, the so-called ice-cream cone, relies mostly on UI tests, giving long feedback times, flaky results and expensive maintenance. A practical target is to cover business rules with unit and API tests and keep the UI layer for a handful of critical journeys and rendering behaviour. Contract tests between services fill a gap between API and UI tests in microservice systems.
3 How would you design an automation framework from scratch?
mediumChoose by team skills and the product: language, runner, driver library and reporting. Structure it in layers: a core layer for driver or HTTP client creation, configuration per environment and logging; a page or API-client layer that hides locators and endpoints; a test layer that reads like business steps; and utilities for data, waits and assertions. Add data-driven support, parallel execution with isolated state, retry only for known infrastructure noise, rich failure artefacts (screenshots, logs, HAR files), and CI integration with tagged suites for smoke, regression and nightly. Keep secrets out of the repo, version the framework, and document how to add a test.
4 What is data-driven, keyword-driven and hybrid testing?
mediumData-driven testing separates test logic from test data, running one script over many rows from a CSV, JSON, database or a parametrised annotation, which is how you cover boundary values economically. Keyword-driven testing expresses tests as sequences of keywords such as login or addToCart mapped to code, so non-programmers can compose tests, as in Robot Framework. A hybrid framework combines both, along with a page object layer. The danger of keyword approaches is a second layer of indirection to maintain, so use them only when non-coders will write tests.
5 How do you manage test data reliably?
mediumMake each test create the data it needs through an API or database seeding, rather than depending on rows left by earlier tests, and clean up afterwards or use disposable environments. Use unique values, such as a timestamp or UUID in an email address, to avoid collisions in parallel runs. Keep static reference data versioned with the code, mask any production-derived data, and never use real customer information. Containers with a seeded database image give a clean state per run. Avoid hard-coded IDs that exist only in one environment.
pythonimport uuid, pytest, requests @pytest.fixture def new_user(api_base): email = f'qa+{uuid.uuid4().hex[:8]}@example.test' r = requests.post(f'{api_base}/users', json={'email': email, 'password': 'Passw0rd!x'}, timeout=10) r.raise_for_status() user = r.json() yield user requests.delete(f"{api_base}/users/{user['id']}", timeout=10)6 What are flaky tests, and what is your policy for them?
mediumA flaky test passes and fails without code changes. Root causes are timing and race conditions, shared state or test order dependence, unstable data, environment problems and unreliable third parties. Policy: measure flakiness per test from CI history, quarantine a flaky test quickly so it stops blocking the pipeline but track it with an owner and deadline, then fix the cause (explicit waits, isolation, mocks) or delete the test if it is not worth its cost. Automatic retries can be used to reduce noise but should be reported, not hidden, since a pass on retry still signals a problem.
7 How do you integrate automated tests into a CI/CD pipeline?
mediumRun fast unit and API tests on every commit or pull request, a small smoke UI suite after deployment to a test environment, and the full regression suite on merge or nightly. Tag tests so the pipeline picks subsets, run in parallel across containers, and publish JUnit XML plus HTML reports and artefacts to the build. Fail the build on test failure, and gate promotion to the next environment on results. Keep the PR feedback under about ten minutes. The workflow below runs pytest in parallel with xdist and uploads reports.
yamlname: tests on: [pull_request] jobs: api-and-smoke: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: '3.12' cache: pip - run: pip install -r requirements.txt - run: pytest -m 'not slow' -n auto --junitxml=report.xml - uses: actions/upload-artifact@v4 if: always() with: name: test-report path: report.xml8 What is BDD, and what are the trade-offs of Cucumber?
mediumBehaviour-driven development describes behaviour in a shared, plain-language format, Gherkin's Given, When, Then, that business people, developers and testers write together; step definitions then bind the sentences to code. Its main value is the conversation and shared understanding, with living documentation as a side effect. The cost is an extra layer to maintain, brittle step reuse and scenarios that become long UI scripts. It works when the business actually reads the scenarios and they stay declarative, such as When the customer pays by UPI, not a list of clicks. If only testers use it, plain test code is often simpler.
textFeature: Coupon Scenario: Valid coupon reduces the total Given a cart totalling Rs 1000 When the customer applies coupon "SAVE10" Then the order total is Rs 9009 What is the difference between a mock, a stub, a fake and a spy?
mediumA stub returns canned answers to calls, so the code under test runs without a real dependency. A mock is pre-programmed with expectations and verifies that specific calls were made, failing otherwise. A fake is a working lightweight implementation, such as an in-memory database. A spy wraps a real object and records calls while keeping the real behaviour. Use fakes and stubs for state-based tests and mocks to verify interactions, but avoid over-mocking, which couples tests to implementation and lets them pass while real integration is broken.
10 What is the difference between a test framework, a test runner and an assertion library?
easyA test runner discovers and executes tests and reports results; examples are pytest, TestNG and JUnit's engine. A test framework is the broader structure around it: conventions, fixtures, configuration, reporting, utilities and sometimes drivers, such as a custom framework built on Selenium and pytest. An assertion library provides expressive checks and clear failure messages, such as AssertJ, Hamcrest or pytest's rewritten assert. Interviewers want you to separate the roles and explain why you chose each, not to equate Selenium with a framework.
11 How do you measure the value of automation?
mediumTrack outcomes, not script counts: defects caught by automation before release, regression cycle time reduced, pipeline feedback time, flaky rate, maintenance effort per sprint and the share of escaped defects that automation could have caught. Return on investment compares manual execution hours saved with the cost to build and maintain. Be wary of vanity metrics such as number of automated test cases or the automation percentage, which can be inflated by low-value tests. Review the suite regularly and delete tests that never fail or duplicate coverage at another layer.
12 How would you automate an application that is under active development with changing UI?
mediumAutomate at stable layers first: API and service tests are far less affected by UI churn. For the UI, use semantic, test-specific locators (data-testid agreed with developers), wrap them in page objects so a change is fixed once, keep UI tests few and journey-focused, and avoid asserting on cosmetic details. Involve testers early in design review, so testability is built in. Run a small smoke suite on each build and delay automating screens whose design is still moving. Visual regression tools can detect layout changes, but need approval workflows to avoid noise.
13 Write a Java TestNG test with a data provider.
mediumA data provider returns a two-dimensional array or iterator of parameters, and TestNG calls the test once for each row, reporting each as a separate result. This gives data-driven coverage without duplicating code. For larger data sets read rows from a CSV or JSON file inside the provider. Use parallel = true on the provider only if the tests are independent and thread-safe.
javaimport org.testng.annotations.*; import static org.testng.Assert.assertEquals; public class DiscountTest { @DataProvider(name = "cases") public Object[][] cases() { return new Object[][] { {1000, "SAVE10", 100.0}, {499, "SAVE10", 0.0}, {1000, "BAD", 0.0} }; } @Test(dataProvider = "cases") public void discountRules(int total, String code, double expected) { assertEquals(Discount.of(total, code), expected, 0.001); } }14 What is visual regression testing and when is it worth it?
mediumVisual regression testing captures screenshots and compares them with approved baselines, flagging pixel or perceptual differences, using tools such as Playwright's screenshot comparison, Percy or Applitools. It catches layout, styling and rendering problems that functional assertions miss. It is worth using on design-system components and key pages, with fixed viewports, disabled animations, masked dynamic regions such as dates and ads, and a clear baseline approval process. Without that discipline it produces noisy diffs and gets ignored.
15 Which metrics and reports would you give stakeholders after a regression run?
easyShow pass, fail and skipped counts with trend over recent runs, failures grouped by cause (product defect, test defect, environment), the list of blocked or flaky tests, coverage of critical requirements, execution time, and open defects by severity. A one-line verdict, such as ready to release with two known medium defects, is more useful than a table alone. Link every failure to logs and screenshots, and distinguish a real regression from a test problem before reporting, because crying wolf destroys trust in automation.
Frequently asked questions
Do I need to know programming for automation testing?
Yes. You need solid fundamentals in one language: collections, strings, exceptions, OOP and reading and writing files, plus a test framework. Hard algorithms are less common than in developer interviews.
Should I learn Selenium, Playwright or Cypress?
Learn the concepts that transfer, such as locators, waiting and page objects, using Selenium for wide market coverage, and add Playwright to stay current. Pick based on the job descriptions you are targeting.
What is the difference between an automation tester and an SDET?
An automation tester mainly writes and maintains automated checks for the product. An SDET also builds frameworks, tooling and pipelines, reviews code for testability and often works closer to development. See the SDET questions.
How do I practise automation without a work project?
Automate public practice sites, an open-source application you run locally, or your own small app. Put the framework on GitHub with a README, CI workflow and reports, which interviewers can inspect.
Related guides
More in Role-wise Interview Questions by Job and Tech Stack
- AWS Interview Questions and Answers
- Azure Interview Questions and Answers
- Backend Developer Interview Questions and Answers
- Business Analyst Interview Questions and Answers
- Cloud Engineer Interview Questions and Answers
- Computer Vision Interview Questions and Answers
- Cybersecurity Interview Questions and Answers
- Data Analyst Interview Questions and Answers
- Data Engineer Interview Questions and Answers
- Data Scientist Interview Questions and Answers
- Deep Learning Interview Questions and Answers
- DevOps Interview Questions and Answers