Skills101

Software Testing & Automation · Lesson 11 of 11 · Updated ·

Selenium, TestNG and API Testing Interview Questions — With Short Answers

Revise these before QA automation interviews. Answer briefly, then add an example from your framework — the one you built in this track.

The automation pyramid: few UI tests, more API tests, many unit tests

Testing basics

  1. Verification vs validation? Built right (reviews, spec) vs right product (running it against user needs).
  2. Smoke vs sanity vs regression? Smoke: is the build usable at all. Sanity: does this fix work. Regression: did anything else break.
  3. Severity vs priority? Severity = impact of the bug; priority = how soon to fix it. (A spelling mistake in the company name: low severity, high priority.)
  4. What do you automate first? Stable, repeated, high-risk flows — login, payments — and the smoke suite.

Selenium

  1. Selenium WebDriver architecture? Java client → W3C WebDriver protocol (HTTP/JSON) → browser driver → browser.
  2. findElement vs findElements? First match or exception vs a list (empty if none).
  3. Best locators? id, name, data-testid, then CSS; XPath for text or parents; never absolute XPath.
  4. Implicit vs explicit wait? Global retry for every findElement vs waiting for a specific condition; prefer explicit, don't mix.
  5. Why not Thread.sleep? Always waits the full time and still fails when the app is slower.
  6. StaleElementReferenceException? The element was re-rendered; find it again.
  7. close() vs quit()? Current window vs all windows and the session.
  8. Handling alerts, frames, windows? switchTo().alert()/frame()/window(); back with defaultContent().
  9. Dropdowns? Select for <select>; click custom dropdowns like normal elements.
  10. Hover or drag-drop? The Actions class with perform().
  11. Screenshots on failure? TakesScreenshot in @AfterMethod when the result failed (our BaseUiTest).
  12. Headless? Browser without a window — used on CI servers.
  13. Selenium Manager? Built-in since 4.6: finds or downloads the right driver automatically.

TestNG and frameworks

  1. TestNG annotation order? BeforeSuite → BeforeTest → BeforeClass → BeforeMethod → Test → AfterMethod → AfterClass → AfterTest → AfterSuite.
  2. DataProvider? Feeds rows of data to one test method; each row is a separate test.
  3. Hard vs soft assert? Stop at the first failure vs collect failures and report with assertAll().
  4. Groups? Tags such as smoke and regression to run subsets.
  5. Parallel execution? parallel="methods" in testng.xml, with one WebDriver per test (never a shared static driver).
  6. Listeners? React to results — logging, screenshots, reporting (ITestListener).
  7. What is POM? One class per page with private locators and user-action methods; tests hold the assertions.
  8. Explain your framework. Maven + TestNG + Selenium + REST Assured; driver factory, base test, page objects, config via system properties, listeners and reports, CI with GitHub Actions/Jenkins.

API testing

  1. What do you check in an API test? Status code, headers, body fields, error messages, response time, and negative cases.
  2. 401 vs 403? Not authenticated vs authenticated but not allowed.
  3. PUT vs PATCH? Replace the whole resource vs change some fields.
  4. How do you test authenticated APIs? Log in in the test, extract the token, send it as a Bearer header.
  5. Postman vs REST Assured? Exploring and sharing without code vs code-based suites in the same repo as UI tests; Newman runs Postman in CI.

CI and maintenance

  1. How do you run tests in CI? Start the app, wait for health, run headless with Maven, publish reports and screenshots.
  2. How do you handle flaky tests? Find the root cause (waits, shared data, parallel state), quarantine meanwhile, don't hide them with retries.

How to answer well

  • Use your project: "In my framework, LoginPage.loginAs() returns a DashboardPage, so tests can't act on the wrong page."
  • Mention trade-offs: "We check most business rules through the API because UI tests are slower."
  • Put the framework on GitHub with a README showing how to run it.

Common mistakes

  • Defining terms without an example.
  • Claiming 100% automation is the goal.
  • Mixing up implicit/explicit waits or severity/priority.

Quick recap

  • Basics: smoke/sanity/regression, severity vs priority, what to automate.
  • Selenium: architecture, locators, explicit waits, stale elements, alerts/frames/windows, Actions.
  • TestNG + POM: lifecycle, DataProvider, groups, parallel, listeners, framework layers.
  • API + CI: status/body/negative checks, tokens, Postman/Newman, pipelines, flaky tests.

Practice what you learned

📝 Quiz: Automation Interview Questions5 questions · instant answers & explanations · +10 XP · counts towards your free certificateTake the quiz →