Skip to content

Top 50 Most Asked Automation Testing Interview Questions

The questions that appear most often across company-wise sets — master these first.

Why start here

We count how often each question appears across the 155 company-wise Automation Testing practice sets on this site and show the 50 most common. They are the safest questions to master first.

Solved — top 50Start practicing
3 QUESTIONS FREESign up to unlock the full question bank and track your progress.Unlock every question and answer, then continue practising company-wise and package-wise.
3 questions free Unlock the rest in seconds
01

How do you run Selenium tests in Docker containers in CI?

API Testing and CI/CDIn 39 company setsMedium
Save to ▾
Show answer
Use official Selenium images, either standalone-chrome for simple runs or a Grid with hub and node containers via Docker Compose. The test container or Jenkins agent points RemoteWebDriver to http://selenium-hub:4444. Containers give the same browser version everywhere and are cleaned after each run. Add shm_size for Chrome stability and record videos for failed tests if needed.
02

Write Selenium code to verify that all links on a page are not broken.

Selenium WebDriverIn 33 company setsMedium
Save to ▾
Show answer
List<WebElement> links = driver.findElements(By.tagName("a")); for (WebElement link : links) { String url = link.getAttribute("href"); if (url == null || !url.startsWith("http")) continue; HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod("HEAD"); int code = con.getResponseCode(); if (code >= 400) System.out.println("Broken: " + url + " " + code); }
03

How do you pass thread count and duration to a JMeter test from the command line?

Performance Testing with JMeterIn 33 company setsMedium
Save to ▾
Show answer
// In the Thread Group fields use property functions with defaults Number of Threads: ${__P(users,10)} Ramp-up period: ${__P(rampup,30)} Duration (seconds): ${__P(duration,300)} // Then override them when running jmeter -n -t load.jmx -l out.jtl -Jusers=200 -Jrampup=120 -Jduration=1800
04

How do you record videos of tests running on a Docker Selenium Grid?

Selenium Grid & DockerIn 32 company setsMedium
Save to ▾
Show answer
Add the selenium/video image as a sidecar container next to each node, sharing the node's display through DISPLAY_CONTAINER_NAME, and mount a folder for the mp4 files. Newer Grid versions also support recording per session by setting the se:recordVideo capability with Dynamic Grid. Name videos with se:name so they match test names. Keep videos only for failed tests or for a few days, because they use a lot of disk space.
05

How do you handle a test that is flaky only in headless mode?

Selenium WebDriverIn 31 company setsMedium
Save to ▾
Show answer
Set window size explicitly, use proper waits, check animations and viewport differences, and capture screenshots and logs to find timing issues.
06

How do you group tests?

TestNG FrameworkIn 31 company setsMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
07

How do you handle dynamic elements whose ids change?

Selenium WebDriverIn 31 company setsMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
08

How do you handle test data cleanup in Cucumber scenarios?

Cucumber and BDDIn 31 company setsMedium
Save to ▾
Show answer
Create data in Given steps through APIs, record the created IDs in the scenario context, and delete them in an @After hook, which runs even when the scenario fails. Use unique names with a timestamp or UUID to avoid clashes in parallel runs. For shared environments, add a nightly cleanup job for leftover data tagged with a test prefix.
09

Your code review shows a test class with 30 copy-pasted lines in every method. How do you refactor it with Java features?

Core Java for TestersIn 31 company setsMedium
Save to ▾
Show answer
Extract repeated steps into private helper methods or a page object, move common setup into @BeforeMethod, and use a DataProvider when only data differs. If the repeated code differs only in a small action, pass that action as a lambda, such as a Consumer<WebDriver>. Rerun the tests after each small refactor to confirm behaviour is unchanged.
10

How do you handle environment-specific configuration?

Page Object ModelIn 30 company setsMedium
Save to ▾
Show answer
Keep URLs and credentials in per-environment config files or variables, choose with a command-line parameter and never hard-code secrets.
11

How do you make WebDriver thread-safe for parallel runs?

Page Object ModelIn 30 company setsMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
12

How do you retry failed tests in TestNG?

TestNG FrameworkIn 29 company setsMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
13

What is a DataProvider in TestNG?

TestNG FrameworkIn 29 company setsMedium
Save to ▾
Show answer
@DataProvider returns Object[][]; a @Test(dataProvider = "name") method runs once per row — the basis of data-driven tests, often reading Excel or JSON.
14

How do you attach a screenshot to the Cucumber report when a scenario fails?

Cucumber and BDDIn 29 company setsMedium
Save to ▾
Show answer
@After public void afterScenario(Scenario scenario) { if (scenario.isFailed()) { byte[] shot = ((TakesScreenshot) driver) .getScreenshotAs(OutputType.BYTES); scenario.attach(shot, "image/png", scenario.getName()); } driver.quit(); }
15

How do you verify response time and headers in REST Assured?

REST AssuredIn 28 company setsMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
16

How do you upload a file with REST Assured?

REST AssuredIn 28 company setsMedium
Save to ▾
Show answer
Use multipart: given().multiPart("file", new File("src/test/resources/report.pdf"), "application/pdf").formParam("type", "invoice").when().post("/upload").then().statusCode(200). REST Assured sets the multipart/form-data content type automatically. Verify both the status and the response, such as the returned file id or size, and test edge cases like empty, oversized and wrong-type files.
17

Your API tests started failing with SSL handshake errors on a new test server. What do you do?

REST AssuredIn 28 company setsMedium
Save to ▾
Show answer
First confirm the server uses a self-signed or internal certificate. The proper fix is to import the company CA certificate into a truststore and configure REST Assured with trustStore(path, password). As a temporary measure in a test environment only, relaxedHTTPSValidation() skips checks. Never use relaxed validation against production, and raise the certificate issue with the infra team.
18

A click works locally but throws ElementClickInterceptedException in CI. How do you fix it?

Selenium WebDriverIn 28 company setsMedium
Save to ▾
Show answer
Another element, such as a cookie banner, loader overlay or sticky header, covers the target. In CI the window is often smaller, so the layout differs. Set a fixed window size, wait for the overlay to disappear with invisibilityOfElementLocated, close banners in setup and scroll the element into view. Use a JavaScript click only as a last resort, since it bypasses real user behaviour.
19

How do you pass parameters from testng.xml?

TestNG FrameworkIn 27 company setsMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
20

How do you handle a web table in Selenium?

Selenium WebDriverIn 27 company setsMedium
Save to ▾
Show answer
Locate rows and columns with XPath such as //table//tr and //td, loop through them to read or click cells, or build the XPath dynamically from the row text.
21

A test configuration value has to be the same for the whole run and accessed from many classes. How do you implement it?

Core Java for TestersIn 27 company setsMedium
Save to ▾
Show answer
Create a ConfigReader that loads properties once, using a singleton or a static holder initialised lazily in a thread-safe way, and exposes typed getters like getInt("timeout"). Let system properties and environment variables override file values so CI can change them. Keep it read-only after loading so parallel threads cannot change settings mid-run.
22

Write a docker-compose.yml that runs a Selenium hub with Chrome and Firefox nodes.

Selenium Grid & DockerIn 27 company setsMedium
Save to ▾
Show answer
services: selenium-hub: image: selenium/hub:4.25.0 ports: - "4442:4442" - "4443:4443" - "4444:4444" chrome: image: selenium/node-chrome:4.25.0 shm_size: 2gb depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 firefox: image: selenium/node-firefox:4.25.0 shm_size: 2gb depends_on: - selenium-hub environment: - SE_EVENT_BUS_HOST=selenium-hub - SE_EVENT_BUS_PUBLISH_PORT=4442 - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
23

Tests running inside Docker cannot reach the application running on the host's localhost. Why, and how do you fix it?

Selenium Grid & DockerIn 27 company setsMedium
Save to ▾
Show answer
Inside a container, localhost means the container itself, not the host machine. On Docker Desktop use host.docker.internal as the host name. On Linux add extra_hosts with host.docker.internal:host-gateway, or use the host's IP. A cleaner option is running the application in the same Compose network and calling it by its service name, such as http://web:8080. Make sure the app listens on 0.0.0.0, not only 127.0.0.1.
24

How do you validate an XML response in REST Assured?

REST AssuredIn 27 company setsMedium
Save to ▾
Show answer
// REST Assured uses GPath for XML as well as JSON given() .accept(ContentType.XML) .when() .get("/orders/42") .then() .statusCode(200) .contentType(ContentType.XML) .body("order.@id", equalTo("42")) .body("order.items.item.size()", equalTo(3)) .body("order.status", equalTo("SHIPPED"));
25

What is the LoadableComponent pattern in Selenium?

Page Object ModelIn 27 company setsMedium
Save to ▾
Show answer
LoadableComponent is a Selenium support class that standardises how a page object ensures it is loaded. You extend it and implement load(), which navigates to the page, and isLoaded(), which throws an Error if the page is not ready. Calling get() checks isLoaded and calls load only if needed, then checks again. It gives a consistent, self-verifying way to open pages and fails fast with a clear message.
26

A login action can lead either to the dashboard or to an error message. How should the page object method return?

Page Object ModelIn 27 company setsMedium
Save to ▾
Show answer
Make the outcome explicit with separate methods instead of one method guessing. For example loginAs(user) returns DashboardPage for valid credentials, while loginExpectingError(user) returns the same LoginPage so the test can check the error. Each method waits for its expected page and fails clearly if it does not appear. This keeps tests readable and avoids returning a generic Object or checking types in tests.
27

How do you verify that an element is displayed, enabled or selected?

Selenium WebDriverIn 26 company setsMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
28

How do you handle dropdowns in Selenium?

Selenium WebDriverIn 26 company setsMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
29

How do you validate a response against a JSON schema in REST Assured?

REST AssuredIn 26 company setsMedium
Save to ▾
Show answer
Add the json-schema-validator dependency, place the schema file in src/test/resources, and assert with then().body(matchesJsonSchemaInClasspath("user-schema.json")). Schema validation checks field types, required fields and structure, so it catches contract changes that value checks might miss. It complements, not replaces, assertions on business values like status or totals.
30

How do you mock an external API in automation tests?

API Testing and CI/CDIn 26 company setsMedium
Save to ▾
Show answer
Use a tool such as WireMock or MockServer to run a stub server that returns predefined responses for given requests. Point the application or tests to the stub with configuration. This lets you test error codes, timeouts and edge cases that are hard to trigger on the real service, and keeps tests stable when the third party is down. Still keep a few tests against the real integration.
31

An element is visible in Appium Inspector but your test throws NoSuchElementException on the device. What do you check?

Appium Mobile AutomationIn 26 company setsMedium
Save to ▾
Show answer
First check timing: the screen may still be loading, so add an explicit wait for presence. Then check context: in a hybrid app the element may be in a webview while you are in NATIVE_APP. Confirm the locator matches exactly, including package prefix in resource-id. The element may be off screen in a list, so scroll first. Also check that the Inspector session used the same app build, language and device size as the test.
32

How do you read data from Excel or properties files in Java?

Core Java for TestersIn 25 company setsMedium
Save to ▾
Show answer
Use Apache POI for Excel and the Properties class for config files, loaded in a utility class so tests read data instead of hard-coding it.
33

How do you switch between windows and tabs?

Selenium WebDriverIn 25 company setsMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
34

Which reporting tools do you use?

TestNG FrameworkIn 25 company setsMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
35

How do you rerun only failed Cucumber scenarios?

Cucumber and BDDIn 25 company setsMedium
Save to ▾
Show answer
Add the rerun plugin, for example rerun:target/failed.txt, to the main runner. It writes the location of each failed scenario. Create a second runner whose features point to @target/failed.txt and run it after the main run in Maven or Jenkins. Use reruns to separate real failures from flaky ones, but track flaky scenarios and fix them instead of hiding them.
36

How do you publish Allure or Extent reports from Jenkins?

Git, Maven and JenkinsIn 25 company setsMedium
Save to ▾
Show answer
For Allure, install the Allure Jenkins plugin, configure the commandline tool, and add allure results: [[path: 'target/allure-results']] in the post always block. For Extent, archive the HTML file and use the HTML Publisher plugin to show it as a build link. Keep report history per build and share the link in failure notifications.
37

How would you test an API with rate limiting?

API Testing and CI/CDIn 25 company setsMedium
Save to ▾
Show answer
Read the documented limit, then send requests quickly until you exceed it and assert a 429 Too Many Requests response with headers like Retry-After or remaining quota. Wait for the window to reset and confirm requests succeed again. Also check limits are per user or key as designed. Run these tests in isolation so they do not throttle the rest of the suite.
38

Why is XPath slow in Appium and what should you use instead?

Appium Mobile AutomationIn 25 company setsMedium
Save to ▾
Show answer
For every XPath query Appium must fetch the full page source of the app, convert it into an XML document and then evaluate the expression, which can take seconds on large screens and is even slower on iOS. Index-based XPath also breaks when layouts change. Use accessibility id first, then resource-id, Android UiAutomator selectors or iOS predicate strings and class chains, which are evaluated natively on the device and are much faster.
39

Mobile tests pass on the emulator but fail on a low-end real device. How do you investigate?

Appium Mobile AutomationIn 25 company setsMedium
Save to ▾
Show answer
Low-end devices are slower, so fixed waits and short timeouts expire before screens render. Replace sleeps with explicit waits and increase timeouts sensibly. Check for vendor-specific pop-ups, battery optimisation dialogs or different keyboards on that brand. Compare screen size and resolution, since coordinate-based taps break. Collect device logs with adb logcat and screen recordings to see what the app was doing. Also check whether the app crashed due to low memory.
40

Tests on the Grid fail with SessionNotCreatedException saying the new session request timed out. What do you check?

Selenium Grid & DockerIn 25 company setsMedium
Save to ▾
Show answer
It means no matching free slot appeared in time. Check the Grid UI to see whether nodes are registered and whether their capabilities match the request, such as browser name, version or platform. Compare the test thread count with total slots, since extra threads just wait in the queue. Look for stuck sessions holding slots after aborted builds. Then increase capacity, reduce threads, or raise the session request timeout.
41

Your recorded JMeter script fails with 403 on every request after login. What is the likely cause?

Performance Testing with JMeterIn 25 company setsMedium
Save to ▾
Show answer
The script is probably replaying hard-coded dynamic values, such as a CSRF token, session cookie or auth header captured during recording. The server rejects them because they belong to the old session. Add an HTTP Cookie Manager so cookies are handled per thread, extract the CSRF or bearer token from the login response with an extractor, and replace the recorded value with the variable. Verify with View Results Tree on one thread.
42

How do you handle StaleElementReferenceException?

Selenium WebDriverIn 24 company setsMedium
Save to ▾
Show answer
Re-locate the element after the DOM refreshes, use explicit waits for the refreshed element, don't keep element references for long, or wrap the action in retry logic.
43

What is CI/CD and why does automation need it?

API Testing and CI/CDIn 24 company setsMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
44

How do you upload a file with Selenium?

Selenium WebDriverIn 24 company setsMedium
Save to ▾
Show answer
If the element is <input type="file">, use element.sendKeys("C:/path/file.pdf"). Use the Robot class or AutoIt only as a last resort for OS dialogs.
45

Where do you use OOP concepts in your framework?

Core Java for TestersIn 24 company setsMedium
Save to ▾
Show answer
Encapsulation: private locators with public page methods. Inheritance: pages extend a BasePage. Polymorphism: the WebDriver interface for different browsers. Abstraction: utility layers hiding Selenium details.
46

How do you manage test data in a framework?

Page Object ModelIn 24 company setsMedium
Save to ▾
Show answer
Use external files or APIs and database setup scripts, generate unique data per run, and clean up afterwards so tests stay independent.
47

Write a declarative Jenkinsfile that runs Maven tests and publishes results.

Git, Maven and JenkinsIn 24 company setsMedium
Save to ▾
Show answer
pipeline { agent any parameters { choice(name: 'SUITE', choices: ['smoke', 'regression']) } stages { stage('Checkout') { steps { checkout scm } } stage('Test') { steps { sh "mvn clean test -DsuiteXml=${params.SUITE}.xml" } } } post { always { junit 'target/surefire-reports/*.xml' archiveArtifacts artifacts: 'target/screenshots/**', allowEmptyArchive: true } } }
48

Write a Java stream that extracts and sorts product prices from a list of WebElements.

Core Java for TestersIn 24 company setsMedium
Save to ▾
Show answer
List<Double> prices = driver.findElements(By.cssSelector(".price")) .stream() .map(WebElement::getText) .map(t -> t.replaceAll("[^0-9.]", "")) .map(Double::parseDouble) .sorted() .collect(Collectors.toList()); System.out.println(prices);
49

How do you handle an element inside a shadow DOM in Selenium 4?

Selenium WebDriverIn 24 company setsMedium
Save to ▾
Show answer
Find the shadow host element, then call getShadowRoot() to get a SearchContext, and search inside it with CSS selectors: driver.findElement(By.cssSelector("my-app")).getShadowRoot().findElement(By.cssSelector("#submit")). XPath does not work inside shadow roots. For nested shadow roots, repeat the step for each host. Closed shadow roots cannot be accessed this way.
50

How do you validate a JSON response in REST Assured?

REST AssuredIn 23 company setsMedium
Save to ▾
Show answer
Use then().statusCode(200).body("data.id", equalTo(5)), or extract() the response and assert fields with JsonPath.

Frequently asked questions

How is this list made?

We count how often each question appears across the 155 company-wise Automation Testing practice sets on this site and show the 50 most common. They are the safest questions to master first.

Is this enough to clear an interview?

It is the best starting point, not the finish line. After these, practise the company pages for your target employers and the sheets for your weaker topics.