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.
Testing basics
- Verification vs validation? Built right (reviews, spec) vs right product (running it against user needs).
- Smoke vs sanity vs regression? Smoke: is the build usable at all. Sanity: does this fix work. Regression: did anything else break.
- 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.)
- What do you automate first? Stable, repeated, high-risk flows — login, payments — and the smoke suite.
Selenium
- Selenium WebDriver architecture? Java client → W3C WebDriver protocol (HTTP/JSON) → browser driver → browser.
- findElement vs findElements? First match or exception vs a list (empty if none).
- Best locators? id, name,
data-testid, then CSS; XPath for text or parents; never absolute XPath. - Implicit vs explicit wait? Global retry for every findElement vs waiting for a specific condition; prefer explicit, don't mix.
- Why not Thread.sleep? Always waits the full time and still fails when the app is slower.
- StaleElementReferenceException? The element was re-rendered; find it again.
- close() vs quit()? Current window vs all windows and the session.
- Handling alerts, frames, windows?
switchTo().alert()/frame()/window(); back withdefaultContent(). - Dropdowns?
Selectfor<select>; click custom dropdowns like normal elements. - Hover or drag-drop? The
Actionsclass withperform(). - Screenshots on failure?
TakesScreenshotin@AfterMethodwhen the result failed (ourBaseUiTest). - Headless? Browser without a window — used on CI servers.
- Selenium Manager? Built-in since 4.6: finds or downloads the right driver automatically.
TestNG and frameworks
- TestNG annotation order? BeforeSuite → BeforeTest → BeforeClass → BeforeMethod → Test → AfterMethod → AfterClass → AfterTest → AfterSuite.
- DataProvider? Feeds rows of data to one test method; each row is a separate test.
- Hard vs soft assert? Stop at the first failure vs collect failures and report with
assertAll(). - Groups? Tags such as smoke and regression to run subsets.
- Parallel execution?
parallel="methods"in testng.xml, with one WebDriver per test (never a shared static driver). - Listeners? React to results — logging, screenshots, reporting (
ITestListener). - What is POM? One class per page with private locators and user-action methods; tests hold the assertions.
- 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
- What do you check in an API test? Status code, headers, body fields, error messages, response time, and negative cases.
- 401 vs 403? Not authenticated vs authenticated but not allowed.
- PUT vs PATCH? Replace the whole resource vs change some fields.
- How do you test authenticated APIs? Log in in the test, extract the token, send it as a Bearer header.
- 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
- How do you run tests in CI? Start the app, wait for health, run headless with Maven, publish reports and screenshots.
- 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.