Skip to content

Automation Testing Interview Questions & Answers (2026)

Practice interview questions and answers organized by company, salary package, topic and difficulty. Mark questions as solved to keep track of your preparation.

Questions solvedStart practicing
3 QUESTIONS FREESign up or log in 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

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
02

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
03

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
04

How do you validate a JSON response in REST Assured?

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

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
06

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
07

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
08

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
09

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
10

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

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.
11

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
12

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
13

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
14

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
15

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
16

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
17

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
18

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
19

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
20

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
21

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
22

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
23

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
24

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
25

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
26

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
27

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
28

How do you handle StaleElementReferenceException?

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.
29

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
30

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
31

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
32

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
33

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
34

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
35

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
36

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
37

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
38

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
39

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
40

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
41

How do you handle environment-specific configuration?

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.
42

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
43

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
44

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
45

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
46

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
47

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
48

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
49

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
50

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
51

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
52

How do you validate a JSON response in REST Assured?

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

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
54

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
55

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
56

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
57

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
58

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
59

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
60

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

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.
61

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
62

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
63

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
64

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
65

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
66

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
67

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
68

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
69

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
70

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
71

How do you group tests?

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

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
73

How do you upload a file with Selenium?

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.
74

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
75

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
76

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
77

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
78

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
79

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
80

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
81

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
82

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
83

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
84

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
85

Where do you use OOP concepts in your framework?

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.
86

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
87

How do you handle environment-specific configuration?

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.
88

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
89

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
90

How do you handle StaleElementReferenceException?

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.
91

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
92

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
93

How do you handle a web table in Selenium?

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.
94

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
95

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
96

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
97

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
98

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
99

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
100

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
101

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
102

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
103

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
104

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
105

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
106

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
107

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
108

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
109

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
110

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
111

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
112

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
113

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
114

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
115

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
116

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
117

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
118

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
119

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
120

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
121

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
122

Where do you use OOP concepts in your framework?

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.
123

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
124

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
125

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
126

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
127

How do you manage test data in a framework?

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.
128

How do you validate a JSON response in REST Assured?

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

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
130

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
131

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
132

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
133

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
134

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
135

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
136

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
137

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
138

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
139

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
140

How do you handle environment-specific configuration?

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.
141

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
142

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
143

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
144

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
145

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
146

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
147

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
148

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
149

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
150

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
151

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
152

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
153

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
154

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
155

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
156

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
157

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

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.
158

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
159

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
160

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
161

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
162

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
163

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
164

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
165

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
166

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
167

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
168

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
169

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
170

What is a DataProvider in TestNG?

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.
171

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
172

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
173

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
174

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
175

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
176

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
177

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
178

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
179

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
180

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
181

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
182

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
183

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
184

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
185

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
186

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
187

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
188

What is a DataProvider in TestNG?

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.
189

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
190

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
191

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
192

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
193

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
194

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
195

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
196

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
197

How do you handle a web table in Selenium?

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.
198

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
199

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
200

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
201

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
202

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
203

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
204

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
205

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

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.
206

How do you handle StaleElementReferenceException?

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.
207

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
208

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

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.
209

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
210

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
211

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
212

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
213

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
214

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
215

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
216

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
217

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
218

How do you handle StaleElementReferenceException?

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.
219

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
220

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
221

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
222

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
223

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
224

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
225

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
226

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
227

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
228

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
229

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
230

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
231

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
232

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
233

How do you group tests?

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

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
235

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
236

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
237

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
238

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
239

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
240

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
241

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
242

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
243

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
244

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
245

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
246

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
247

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
248

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
249

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
250

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
251

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
252

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
253

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
254

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
255

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
256

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
257

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
258

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
259

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
260

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
261

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
262

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
263

How do you handle a web table in Selenium?

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.
264

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
265

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
266

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
267

What is a DataProvider in TestNG?

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.
268

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
269

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
270

How do you handle StaleElementReferenceException?

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.
271

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
272

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
273

How do you handle environment-specific configuration?

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.
274

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
275

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
276

Where do you use OOP concepts in your framework?

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.
277

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
278

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
279

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
280

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
281

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
282

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
283

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
284

How do you handle environment-specific configuration?

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.
285

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
286

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
287

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
288

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
289

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
290

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
291

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

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.
292

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
293

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
294

How do you upload a file with Selenium?

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.
295

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
296

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
297

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
298

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
299

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
300

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
301

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
302

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
303

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
304

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
305

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
306

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
307

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
308

How do you handle StaleElementReferenceException?

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.
309

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
310

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
311

What is a DataProvider in TestNG?

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.
312

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
313

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
314

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
315

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
316

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
317

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
318

How do you manage test data in a framework?

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.
319

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
320

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
321

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
322

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
323

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
324

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
325

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
326

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
327

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
328

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
329

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
330

How do you upload a file with Selenium?

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.
331

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
332

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
333

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
334

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
335

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
336

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
337

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
338

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
339

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
340

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
341

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
342

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
343

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
344

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
345

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
346

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
347

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
348

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
349

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
350

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
351

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
352

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
353

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

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.
354

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
355

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
356

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
357

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
358

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
359

How do you validate a JSON response in REST Assured?

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

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
361

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
362

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
363

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
364

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
365

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
366

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
367

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
368

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
369

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
370

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
371

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
372

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
373

How do you handle a web table in Selenium?

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.
374

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
375

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
376

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
377

How do you handle StaleElementReferenceException?

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.
378

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
379

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
380

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
381

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
382

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
383

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
384

How do you handle environment-specific configuration?

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.
385

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

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.
386

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
387

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
388

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
389

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
390

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
391

How do you manage test data in a framework?

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.
392

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
393

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
394

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
395

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
396

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
397

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
398

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
399

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
400

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
401

What is a DataProvider in TestNG?

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.
402

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
403

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
404

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
405

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

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.
406

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
407

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
408

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
409

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
410

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
411

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
412

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
413

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
414

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
415

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
416

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
417

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
418

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
419

Where do you use OOP concepts in your framework?

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.
420

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
421

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
422

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
423

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
424

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
425

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
426

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
427

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
428

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
429

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
430

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
431

How do you handle StaleElementReferenceException?

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.
432

How do you validate a JSON response in REST Assured?

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

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
434

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
435

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
436

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
437

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
438

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
439

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
440

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

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.
441

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
442

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
443

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
444

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
445

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
446

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
447

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
448

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
449

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
450

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
451

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
452

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
453

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
454

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
455

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
456

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
457

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
458

What is a DataProvider in TestNG?

TCSMedium
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.
459

What is OAuth 2.0 in API testing?

TCSMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
460

What is the execution order of TestNG annotations?

TCSEasy
Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
461

What is the Hybrid framework?

TCSMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
462

How do you handle dropdowns in Selenium?

TCSMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
463

What is an API and what are common HTTP methods?

TCSEasy
Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
464

How does the DataProvider annotation work?

TCSMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
465

Explain your CI/CD pipeline for tests.

TCSHard
Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
466

What is the difference between hard and soft assertions?

TCSMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
467

What is the difference between an array and an ArrayList?

InfosysMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
468

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
469

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
470

Where do you use OOP concepts in your framework?

InfosysMedium
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.
471

What are relative locators in Selenium 4?

InfosysMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
472

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
473

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
474

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
475

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
476

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
477

What is the use of the this and super keywords?

InfosysMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
478

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
479

Difference between absolute and relative XPath?

InfosysMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
480

How do you handle iframes?

InfosysMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
481

How do you run tests in parallel?

InfosysMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
482

How do you handle alerts and pop-ups?

InfosysMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
483

How do you validate a JSON response in REST Assured?

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

How do you handle StaleElementReferenceException?

InfosysMedium
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.
485

How do you pass authentication in an API test?

InfosysMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
486

What is the difference between @BeforeTest and @BeforeMethod?

InfosysMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
487

What is the difference between driver.close() and driver.quit()?

InfosysMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
488

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
489

How do you scroll a page in Selenium?

InfosysMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
490

What is REST Assured?

InfosysMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
491

How do you pass parameters from testng.xml?

InfosysMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
492

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
493

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
494

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
495

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

InfosysMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
496

What is polymorphism and how does it show up in Selenium?

InfosysMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
497

What is the difference between driver.close() and driver.quit()?

WiproMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
498

How do you handle a website that uses CAPTCHA?

WiproHard
Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
499

How do you pass parameters from testng.xml?

WiproMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
500

List common TestNG annotations and their order.

WiproEasy
Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
501

How do you run tests in parallel?

WiproMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
502

What is the purpose of testng.xml?

WiproEasy
Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
503

What is OAuth 2.0 in API testing?

WiproMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
504

What is the difference between throw and throws?

WiproMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
505

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

WiproMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
506

How do you switch between windows and tabs?

WiproMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
507

What is the difference between an array and an ArrayList?

WiproMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
508

What is the difference between @BeforeTest and @BeforeMethod?

WiproMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
509

What is the difference between == and equals() in Java?

WiproEasy
Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
510

What is Postman and how do you automate with it?

WiproMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
511

What is contract testing?

WiproMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
512

What is the difference between Comparable and Comparator in Java?

WiproMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
513

How do you test an API that depends on another service that is down?

WiproMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
514

What is the use of the this and super keywords?

MetaMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
515

How do you decide what to automate?

MetaHard
Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
516

How would you automate a login flow with multiple user roles?

MetaHard
Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
517

What new features came with Selenium 4?

MetaMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
518

What is the difference between driver.close() and driver.quit()?

MetaMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
519

How do you run tests in parallel?

MetaMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
520

How do you handle dynamic elements whose ids change?

MetaMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
521

How do you handle a website that uses CAPTCHA?

MetaHard
Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
522

What is a constructor and can it be overloaded?

MetaMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
523

What is TestNG and why is it used with Selenium?

MetaEasy
Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
524

POST vs PUT vs PATCH?

MetaMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
525

What is the Page Object Model?

MetaEasy
Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
526

What is the execution order of TestNG annotations?

MetaEasy
Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
527

How do you pass authentication in an API test?

MetaMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
528

What is the use of Maven in automation projects?

MetaMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
529

Common HTTP status codes?

MetaEasy
Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
530

How do you handle alerts and pop-ups?

MetaMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
531

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

MetaMedium
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.
532

How do you take a screenshot on failure in TestNG?

MetaMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
533

How do you run JavaScript in Selenium?

MetaMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
534

What are exceptions and how do you handle them?

MetaEasy
Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
535

Reverse a string in Java.

MetaEasy
Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
536

What are relative locators in Selenium 4?

MetaMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
537

What is contract testing?

MetaMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
538

What is the difference between static and non-static members?

MetaMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
539

What are the main OOP concepts in Java?

MetaEasy
Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
540

What is the difference between hard and soft assertions?

MetaMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
541

How do you pass parameters from testng.xml?

MetaMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
542

How do you calculate automation ROI?

MetaHard
Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
543

How do you integrate Selenium tests with Jenkins?

MetaMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
544

What are listeners in TestNG?

MetaMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
545

What does dependsOnMethods do?

MetaMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
546

What is the difference between SOAP and REST?

MetaMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
547

How do you retry failed tests in TestNG?

MetaMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
548

How would you design a CI pipeline for nightly regression?

MetaHard
Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
549

Difference between final, finally and finalize?

MetaEasy
Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
550

What is OAuth 2.0 in API testing?

MetaMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
551

List common TestNG annotations and their order.

MetaEasy
Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
552

How would you design an automation framework from scratch?

MetaHard
Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
553

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
554

How do you handle environment-specific configuration?

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.
555

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
556

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
557

How do you upload a file with Selenium?

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.
558

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
559

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

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.
560

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
561

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
562

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
563

What is a DataProvider in TestNG?

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.
564

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
565

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
566

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
567

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
568

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
569

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
570

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
571

How do you validate a JSON response in REST Assured?

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

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
573

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
574

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
575

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
576

How do you manage test data in a framework?

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.
577

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
578

How do you handle StaleElementReferenceException?

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.
579

Reverse a string in Java.

AppleEasy
Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
580

Implicit vs explicit vs fluent wait?

AppleEasy
Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
581

ArrayList vs HashMap — how do you use them in a framework?

AppleEasy
Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
582

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

AppleEasy
Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
583

What is the execution order of TestNG annotations?

AppleEasy
Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
584

Difference between an abstract class and an interface?

AppleEasy
Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
585

How do you handle iframes?

AppleMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
586

How do you handle environment-specific configuration?

AppleMedium
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.
587

How do you manage test data in a framework?

AppleMedium
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.
588

How do you pass parameters from testng.xml?

AppleMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
589

What is the difference between hard and soft assertions?

AppleMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
590

How do you calculate automation ROI?

AppleHard
Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
591

How do you validate a JSON response in REST Assured?

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

How does HashMap work internally?

AppleMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
593

Difference between ArrayList and LinkedList?

AppleMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
594

What are wrapper classes in Java?

AppleEasy
Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
595

What is the difference between static and non-static members?

AppleMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
596

How would you design a CI pipeline for nightly regression?

AppleHard
Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
597

How do you handle alerts and pop-ups?

AppleMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
598

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

AppleMedium
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.
599

What are the Actions class use cases?

AppleMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
600

What is the use of the this and super keywords?

AppleMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
601

What is the difference between throw and throws?

AppleMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
602

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

AppleMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
603

What is the Hybrid framework?

AppleMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
604

What are the different types of waits in Selenium?

AppleMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
605

Method overloading vs overriding?

AppleEasy
Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
606

What are the main OOP concepts in Java?

AppleEasy
Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
607

How do you handle a website that uses CAPTCHA?

AppleHard
Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
608

What is PageFactory?

AppleMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
609

What is WebDriver and how does it communicate with the browser?

AppleEasy
Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
610

What is the difference between an array and an ArrayList?

AppleMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
611

How do you group tests?

AppleMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
612

Where do you use OOP concepts in your framework?

AppleMedium
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.
613

How do you handle a web table in Selenium?

AppleMedium
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.
614

What is method overriding and where is it useful in frameworks?

AppleMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
615

What is the use of Maven in automation projects?

AppleMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
616

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

AppleMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
617

How do you retry failed tests in TestNG?

AppleMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
618

What are listeners in TestNG?

AppleMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
619

String vs StringBuilder?

AppleEasy
Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
620

What is the difference between == and equals() in Java?

AppleEasy
Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
621

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

AppleMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
622

How do you handle a dropdown that is not a <select> tag?

AppleMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
623

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
624

How do you upload a file with Selenium?

LinkedInMedium
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.
625

What is the difference between an array and an ArrayList?

LinkedInMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
626

What are the different types of waits in Selenium?

LinkedInMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
627

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
628

How do you handle StaleElementReferenceException?

LinkedInMedium
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.
629

What is Selenium Grid and why use it?

LinkedInMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
630

What is OAuth 2.0 in API testing?

LinkedInMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
631

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
632

What is the difference between throw and throws?

LinkedInMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
633

What new features came with Selenium 4?

LinkedInMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
634

What are the Actions class use cases?

LinkedInMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
635

What is BDD and how does Cucumber work?

LinkedInMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
636

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
637

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
638

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
639

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
640

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
641

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

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.
642

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
643

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
644

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
645

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
646

What is a DataProvider in TestNG?

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.
647

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
648

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
649

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
650

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
651

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
652

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
653

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
654

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
655

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
656

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
657

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
658

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
659

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
660

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
661

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
662

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
663

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
664

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
665

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
666

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
667

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
668

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
669

How do you handle StaleElementReferenceException?

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.
670

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
671

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
672

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
673

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
674

How do you handle a web table in Selenium?

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.
675

What is a Jenkins pipeline?

PhonePeMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
676

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
677

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
678

How do you upload a file with Selenium?

PhonePeMedium
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.
679

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
680

Difference between absolute and relative XPath?

PhonePeMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
681

What is contract testing?

PhonePeMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
682

How do you validate a JSON response in REST Assured?

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

How do you handle a dropdown that is not a <select> tag?

PhonePeMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
684

What is Selenium Grid and why use it?

PhonePeMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
685

How do you take a screenshot on failure in TestNG?

PhonePeMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
686

What is the difference between getText() and getAttribute()?

PhonePeMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
687

How do you pass parameters from testng.xml?

PhonePeMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
688

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
689

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
690

How does HashMap work internally?

PhonePeMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
691

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
692

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
693

What is the difference between @BeforeTest and @BeforeMethod?

PhonePeMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
694

How do you handle StaleElementReferenceException?

PhonePeMedium
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.
695

What is OAuth 2.0 in API testing?

PhonePeMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
696

What is Postman and how do you automate with it?

PhonePeMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
697

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
698

What are relative locators in Selenium 4?

PhonePeMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
699

How do you pass authentication in an API test?

MeeshoMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
700

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
701

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
702

How do you test an API that depends on another service that is down?

MeeshoMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
703

What is the difference between an array and an ArrayList?

MeeshoMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
704

How do you pass parameters from testng.xml?

MeeshoMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
705

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
706

What is REST Assured?

MeeshoMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
707

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
708

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
709

What is contract testing?

MeeshoMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
710

How do you handle dynamic elements whose ids change?

MeeshoMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
711

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
712

What is the difference between @BeforeTest and @BeforeMethod?

MeeshoMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
713

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

MeeshoMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
714

How do you switch between windows and tabs?

MeeshoMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
715

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
716

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
717

What are the Actions class use cases?

MeeshoMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
718

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
719

What is the difference between Comparable and Comparator in Java?

MeeshoMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
720

What is a Jenkins pipeline?

MeeshoMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
721

What are listeners in TestNG?

MeeshoMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
722

How do you run tests in parallel?

MeeshoMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
723

What is Selenium Grid and why use it?

MeeshoMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
724

POST vs PUT vs PATCH?

MeeshoMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
725

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
726

How do you validate a JSON response in REST Assured?

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

How do you handle multiple windows?

MeeshoMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
728

How do you handle iframes?

MeeshoMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
729

What are try-with-resources and why use them?

MeeshoMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
730

What is the use of the this and super keywords?

MeeshoMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
731

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
732

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
733

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
734

What are Java collections and which ones do testers use most?

MeeshoMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
735

What is the difference between driver.close() and driver.quit()?

MeeshoMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
736

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
737

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
738

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
739

What are access modifiers in Java?

MeeshoMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
740

What is the Hybrid framework?

MeeshoMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
741

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
742

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
743

What are relative locators in Selenium 4?

MeeshoMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
744

What is Docker and how does it help tests?

MeeshoMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
745

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
746

How do you retry failed tests in TestNG?

MeeshoMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
747

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
748

How do you handle environment-specific configuration?

MeeshoMedium
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.
749

What is the use of the this and super keywords?

CREDMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
750

What is TestNG and why is it used with Selenium?

CREDEasy
Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
751

How do you handle dynamic elements whose ids change?

CREDMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
752

What is JSON and how is it used in API testing?

CREDEasy
Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
753

What is a webhook and how do you test it?

CREDMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
754

How do you validate a JSON response in REST Assured?

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

Write an XPath for a button with the text "Login".

CREDEasy
Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
756

What is a DataProvider in TestNG?

CREDMedium
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.
757

What is the Hybrid framework?

CREDMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
758

What are try-with-resources and why use them?

CREDMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
759

What does dependsOnMethods do?

CREDMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
760

What is polymorphism and how does it show up in Selenium?

CREDMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
761

What are relative locators in Selenium 4?

CREDMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
762

Common HTTP status codes?

CREDEasy
Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
763

What is method overriding and where is it useful in frameworks?

CREDMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
764

How do you manage test data in a framework?

CREDMedium
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.
765

What is the difference between driver.close() and driver.quit()?

CREDMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
766

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

CREDMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
767

List common TestNG annotations and their order.

CREDEasy
Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
768

What is the use of the this and super keywords?

RazorpayMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
769

How do you handle dropdowns in Selenium?

RazorpayMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
770

What is the difference between getText() and getAttribute()?

RazorpayMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
771

How do you run tests in parallel?

RazorpayMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
772

What is a constructor and can it be overloaded?

RazorpayMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
773

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

RazorpayMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
774

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
775

What is Selenium Grid and why use it?

RazorpayMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
776

How do you integrate Selenium tests with Jenkins?

RazorpayMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
777

POST vs PUT vs PATCH?

RazorpayMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
778

How do you upload a file with Selenium?

RazorpayMedium
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.
779

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
780

What is the difference between throw and throws?

RazorpayMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
781

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
782

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
783

What is BDD and how does Cucumber work?

RazorpayMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
784

How do you retry failed tests in TestNG?

RazorpayMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
785

How do you handle a dropdown that is not a <select> tag?

RazorpayMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
786

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
787

How do you handle multiple windows?

RazorpayMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
788

What are Java 8 streams and lambdas?

RazorpayMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
789

What are Java 8 streams and lambdas?

ZomatoMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
790

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
791

What is data-driven testing?

ZomatoMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
792

Difference between absolute and relative XPath?

ZomatoMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
793

What is method overriding and where is it useful in frameworks?

ZomatoMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
794

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
795

How do you test an API that depends on another service that is down?

ZomatoMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
796

What is the difference between getText() and getAttribute()?

ZomatoMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
797

What is Selenium Grid and why use it?

ZomatoMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
798

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
799

How do you upload a file with Selenium?

ZomatoMedium
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.
800

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
801

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
802

What are listeners in TestNG?

ZomatoMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
803

How do you pass authentication in an API test?

ZomatoMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
804

How does the DataProvider annotation work?

ZomatoMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
805

How do you handle StaleElementReferenceException?

ZomatoMedium
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.
806

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
807

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
808

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
809

How do you handle environment-specific configuration?

ZomatoMedium
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.
810

What is BDD and how does Cucumber work?

ZomatoMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
811

What is the difference between SOAP and REST?

ZomatoMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
812

What does dependsOnMethods do?

ZomatoMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
813

What are the advantages of version control for test code?

ZomatoMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
814

How do you retry failed tests in TestNG?

ZomatoMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
815

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
816

What is PageFactory?

ZomatoMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
817

What is the difference between driver.close() and driver.quit()?

ZomatoMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
818

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
819

Write a GET test in REST Assured.

ZomatoMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
820

Which reporting tools do you use?

ZomatoMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
821

How do you handle environment-specific configuration?

SwiggyMedium
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.
822

What are the different types of waits in Selenium?

SwiggyMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
823

How do you handle dropdowns in Selenium?

SwiggyMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
824

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
825

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
826

Where do you use OOP concepts in your framework?

SwiggyMedium
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.
827

What are the advantages of version control for test code?

SwiggyMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
828

What is the difference between getText() and getAttribute()?

SwiggyMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
829

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

SwiggyMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
830

What is data-driven testing?

SwiggyMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
831

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

SwiggyMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
832

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
833

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
834

How do you handle dynamic elements whose ids change?

SwiggyMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
835

What is the difference between driver.close() and driver.quit()?

SwiggyMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
836

What is Docker and how does it help tests?

SwiggyMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
837

What are Java collections and which ones do testers use most?

SwiggyMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
838

How do you run tests in parallel?

SwiggyMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
839

How do you scroll a page in Selenium?

ZeptoMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
840

Where do you use OOP concepts in your framework?

ZeptoMedium
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.
841

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
842

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
843

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
844

How do you handle a web table in Selenium?

IntuitMedium
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.
845

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
846

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

IntuitMedium
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.
847

Difference between ArrayList and LinkedList?

IntuitMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
848

How do you handle iframes?

IntuitMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
849

How do you run JavaScript in Selenium?

IntuitMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
850

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
851

What is contract testing?

IntuitMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
852

What is data-driven testing?

IntuitMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
853

What is the difference between getText() and getAttribute()?

IntuitMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
854

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
855

What are listeners in TestNG?

IntuitMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
856

What is the use of Maven in automation projects?

IntuitMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
857

What is the difference between hard and soft assertions?

IntuitMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
858

What is a Jenkins pipeline?

IntuitMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
859

What are access modifiers in Java?

IntuitMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
860

What is a DataProvider in TestNG?

IntuitMedium
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.
861

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
862

What is the difference between getText() and getAttribute()?

WalmartMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
863

What are try-with-resources and why use them?

WalmartMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
864

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

WalmartMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
865

What is the use of Maven in automation projects?

WalmartMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
866

What is a DataProvider in TestNG?

WalmartMedium
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.
867

How do you upload a file with Selenium?

WalmartMedium
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.
868

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
869

How do you handle a web table in Selenium?

WalmartMedium
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.
870

How do you integrate Selenium tests with Jenkins?

WalmartMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
871

How does the DataProvider annotation work?

WalmartMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
872

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
873

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
874

What is the difference between static and non-static members?

WalmartMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
875

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
876

How do you handle multiple windows?

WalmartMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
877

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
878

What is polymorphism and how does it show up in Selenium?

WalmartMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
879

Which reporting tools do you use?

WalmartMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
880

What are relative locators in Selenium 4?

WalmartMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
881

How do you take a screenshot on failure in TestNG?

WalmartMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
882

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

WalmartMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
883

How do you scroll a page in Selenium?

WalmartMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
884

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
885

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
886

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
887

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
888

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
889

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

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.
890

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
891

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

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.
892

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
893

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
894

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
895

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
896

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
897

How do you handle StaleElementReferenceException?

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.
898

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
899

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
900

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
901

How do you group tests?

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

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
903

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
904

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
905

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
906

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
907

How do you manage test data in a framework?

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.
908

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
909

What is a webhook and how do you test it?

BarclaysMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
910

What are the different types of waits in Selenium?

BarclaysMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
911

What is polymorphism and how does it show up in Selenium?

BarclaysMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
912

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
913

How do you integrate Selenium tests with Jenkins?

BarclaysMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
914

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
915

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
916

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
917

What is the Hybrid framework?

BarclaysMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
918

What are try-with-resources and why use them?

BarclaysMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
919

How do you pass authentication in an API test?

BarclaysMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
920

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
921

What is Docker and how does it help tests?

BarclaysMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
922

How do you group tests?

BarclaysMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
923

How do you handle a dropdown that is not a <select> tag?

BarclaysMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
924

How do you scroll a page in Selenium?

BarclaysMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
925

What is Postman and how do you automate with it?

BarclaysMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
926

What is Selenium Grid and why use it?

BarclaysMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
927

What is data-driven testing?

BarclaysMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
928

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
929

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
930

How does HashMap work internally?

BarclaysMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
931

What is PageFactory?

BarclaysMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
932

What is the difference between Comparable and Comparator in Java?

BarclaysMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
933

How do you handle dropdowns in Selenium?

BarclaysMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
934

What is a constructor and can it be overloaded?

BarclaysMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
935

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
936

What is a Jenkins pipeline?

BarclaysMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
937

What is the difference between SOAP and REST?

BarclaysMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
938

How do you take a screenshot on failure in TestNG?

HSBCMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
939

What is the Page Object Model?

HSBCEasy
Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
940

What is an API and what are common HTTP methods?

HSBCEasy
Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
941

String vs StringBuilder?

HSBCEasy
Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
942

How do you manage test data in a framework?

HSBCMedium
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.
943

What are exceptions and how do you handle them?

HSBCEasy
Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
944

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

HSBCMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
945

What is Postman and how do you automate with it?

HSBCMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
946

What is the difference between getText() and getAttribute()?

HSBCMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
947

How do you run tests in parallel?

HSBCMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
948

POST vs PUT vs PATCH?

HSBCMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
949

What is the execution order of TestNG annotations?

HSBCEasy
Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
950

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

HSBCMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
951

What is a DataProvider in TestNG?

HSBCMedium
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.
952

Difference between absolute and relative XPath?

HSBCMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
953

What are the different types of waits in Selenium?

HSBCMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
954

How would you automate a login flow with multiple user roles?

HSBCHard
Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
955

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

HSBCEasy
Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
956

How do you calculate automation ROI?

HSBCHard
Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
957

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
958

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
959

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

HCLTechMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
960

What is Docker and how does it help tests?

HCLTechMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
961

What is the difference between an array and an ArrayList?

HCLTechMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
962

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
963

How do you handle dynamic elements whose ids change?

HCLTechMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
964

What is method overriding and where is it useful in frameworks?

HCLTechMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
965

What is the difference between driver.close() and driver.quit()?

HCLTechMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
966

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
967

POST vs PUT vs PATCH?

HCLTechMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
968

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
969

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

HCLTechMedium
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.
970

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
971

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
972

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
973

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
974

Where do you use OOP concepts in your framework?

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.
975

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
976

How do you upload a file with Selenium?

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.
977

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
978

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
979

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
980

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
981

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
982

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
983

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
984

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
985

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
986

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
987

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
988

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
989

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
990

How do you manage test data in a framework?

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.
991

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
992

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
993

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
994

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
995

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

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.
996

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
997

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
998

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
999

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
1000

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
1001

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
1002

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
1003

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1004

How do you handle a web table in Selenium?

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.
1005

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
1006

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1007

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
1008

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1009

What is a DataProvider in TestNG?

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.
1010

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
1011

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1012

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
1013

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1014

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1015

How do you handle a web table in Selenium?

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.
1016

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1017

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
1018

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
1019

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
1020

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
1021

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1022

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1023

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
1024

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
1025

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
1026

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
1027

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1028

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1029

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

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.
1030

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
1031

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
1032

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1033

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
1034

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
1035

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
1036

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
1037

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1038

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
1039

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1040

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
1041

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
1042

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
1043

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
1044

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1045

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
1046

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1047

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
1048

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1049

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1050

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1051

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
1052

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
1053

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
1054

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1055

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
1056

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
1057

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
1058

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
1059

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
1060

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
1061

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
1062

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1063

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1064

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1065

How do you handle environment-specific configuration?

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.
1066

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1067

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
1068

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1069

How do you handle StaleElementReferenceException?

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.
1070

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1071

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
1072

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1073

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1074

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
1075

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1076

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
1077

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
1078

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1079

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
1080

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1081

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
1082

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
1083

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
1084

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
1085

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1086

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
1087

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1088

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
1089

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1090

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1091

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
1092

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1093

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
1094

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1095

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
1096

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
1097

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1098

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
1099

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1100

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1101

Where do you use OOP concepts in your framework?

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.
1102

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1103

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1104

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
1105

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
1106

How do you group tests?

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

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
1108

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1109

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1110

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1111

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
1112

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
1113

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
1114

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
1115

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
1116

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1117

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1118

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1119

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
1120

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
1121

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
1122

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
1123

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
1124

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1125

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1126

How do you handle a web table in Selenium?

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.
1127

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
1128

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
1129

How do you validate a JSON response in REST Assured?

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

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1131

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1132

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1133

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
1134

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
1135

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1136

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
1137

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1138

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
1139

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
1140

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1141

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
1142

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
1143

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
1144

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
1145

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
1146

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
1147

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
1148

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
1149

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1150

How do you upload a file with Selenium?

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.
1151

How do you manage test data in a framework?

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.
1152

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
1153

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
1154

How do you handle environment-specific configuration?

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.
1155

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
1156

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
1157

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
1158

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
1159

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1160

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
1161

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
1162

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1163

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1164

How do you validate a JSON response in REST Assured?

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

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
1166

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
1167

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
1168

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
1169

Where do you use OOP concepts in your framework?

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.
1170

How do you manage test data in a framework?

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.
1171

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1172

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
1173

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
1174

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
1175

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1176

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
1177

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1178

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
1179

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1180

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
1181

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
1182

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
1183

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
1184

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1185

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
1186

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
1187

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
1188

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
1189

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

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.
1190

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
1191

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
1192

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1193

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1194

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

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.
1195

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
1196

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
1197

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
1198

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
1199

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
1200

How do you upload a file with Selenium?

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.
1201

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1202

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
1203

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1204

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
1205

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
1206

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
1207

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1208

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
1209

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1210

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
1211

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
1212

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
1213

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
1214

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1215

Where do you use OOP concepts in your framework?

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.
1216

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1217

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
1218

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1219

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1220

How do you group tests?

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

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
1222

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1223

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1224

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
1225

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
1226

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
1227

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1228

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
1229

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1230

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
1231

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1232

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1233

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
1234

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
1235

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
1236

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
1237

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
1238

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
1239

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
1240

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
1241

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1242

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
1243

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
1244

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1245

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
1246

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1247

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1248

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1249

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
1250

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
1251

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1252

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
1253

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1254

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
1255

How do you validate a JSON response in REST Assured?

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

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1257

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1258

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
1259

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
1260

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1261

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
1262

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1263

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
1264

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1265

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
1266

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
1267

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1268

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
1269

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
1270

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
1271

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
1272

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
1273

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
1274

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
1275

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1276

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1277

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1278

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
1279

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1280

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1281

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
1282

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
1283

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
1284

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
1285

How do you manage test data in a framework?

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.
1286

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1287

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
1288

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
1289

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1290

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1291

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1292

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
1293

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1294

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1295

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
1296

Where do you use OOP concepts in your framework?

TCSMedium
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.
1297

What locators does Selenium support?

TCSEasy
Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1298

List common TestNG annotations and their order.

TCSEasy
Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
1299

What is the difference between SOAP and REST?

TCSMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
1300

What is the difference between Comparable and Comparator in Java?

TCSMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
1301

How do you handle StaleElementReferenceException?

TCSMedium
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.
1302

What is BDD and how does Cucumber work?

TCSMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
1303

What is a Jenkins pipeline?

TCSMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1304

What is the difference between an array and an ArrayList?

TCSMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
1305

How would you design a CI pipeline for nightly regression?

TCSHard
Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1306

What is WebDriver and how does it communicate with the browser?

TCSEasy
Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
1307

How do you handle a dropdown that is not a <select> tag?

TCSMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
1308

What are Java collections and which ones do testers use most?

TCSMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
1309

What are Java 8 streams and lambdas?

TCSMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1310

How do you calculate automation ROI?

TCSHard
Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1311

String vs StringBuilder?

TCSEasy
Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
1312

How do you integrate Selenium tests with Jenkins?

TCSMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
1313

Implicit vs explicit vs fluent wait?

TCSEasy
Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
1314

What is TestNG and why is it used with Selenium?

TCSEasy
Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
1315

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

TCSMedium
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.
1316

What are exceptions and how do you handle them?

TCSEasy
Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
1317

Difference between ArrayList and LinkedList?

TCSMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1318

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

TCSMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1319

How would you design an automation framework from scratch?

TCSHard
Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
1320

What are the advantages of version control for test code?

TCSMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1321

How do you scroll a page in Selenium?

TCSMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
1322

What is the difference between @BeforeTest and @BeforeMethod?

TCSMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1323

How do you pass parameters from testng.xml?

TCSMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
1324

How do you manage test data in a framework?

TCSMedium
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.
1325

What is the difference between throw and throws?

TCSMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
1326

What new features came with Selenium 4?

TCSMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
1327

What is the difference between static and non-static members?

TCSMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
1328

What is polymorphism and how does it show up in Selenium?

TCSMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1329

What is the use of the this and super keywords?

TCSMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1330

How do you handle multiple windows?

TCSMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1331

How do you handle dynamic elements whose ids change?

TCSMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
1332

How do you validate a JSON response in REST Assured?

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

What is the difference between == and equals() in Java?

TCSEasy
Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
1334

How do you run tests in parallel?

TCSMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1335

What is the Page Object Model?

TCSEasy
Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
1336

What is Postman and how do you automate with it?

TCSMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
1337

How do you handle alerts and pop-ups?

TCSMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
1338

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

TCSMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
1339

What is a webhook and how do you test it?

TCSMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
1340

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

TCSMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1341

What is Docker and how does it help tests?

TCSMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1342

What is Selenium Grid and why use it?

TCSMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
1343

How do you retry failed tests in TestNG?

TCSMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
1344

Difference between final, finally and finalize?

TCSEasy
Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
1345

What is the use of Maven in automation projects?

TCSMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
1346

What is the purpose of testng.xml?

TCSEasy
Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
1347

Method overloading vs overriding?

TCSEasy
Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
1348

How do you upload a file with Selenium?

TCSMedium
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.
1349

What are relative locators in Selenium 4?

TCSMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1350

How do you handle environment-specific configuration?

TCSMedium
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.
1351

What are try-with-resources and why use them?

TCSMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1352

How does HashMap work internally?

TCSMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
1353

What is data-driven testing?

TCSMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1354

What is REST Assured?

TCSMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
1355

How do you test an API that depends on another service that is down?

TCSMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
1356

Reverse a string in Java.

TCSEasy
Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
1357

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

TCSMedium
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.
1358

ArrayList vs HashMap — how do you use them in a framework?

TCSEasy
Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
1359

What are Java 8 streams and lambdas?

InfosysMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1360

What is the difference between SOAP and REST?

InfosysMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
1361

Which reporting tools do you use?

InfosysMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
1362

What is the difference between hard and soft assertions?

InfosysMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1363

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
1364

How do you handle multiple windows?

InfosysMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1365

What is the Hybrid framework?

InfosysMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
1366

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
1367

What is the difference between static and non-static members?

InfosysMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
1368

Write a GET test in REST Assured.

InfosysMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1369

What are access modifiers in Java?

InfosysMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1370

What are the different types of waits in Selenium?

InfosysMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
1371

What is Selenium Grid and why use it?

InfosysMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
1372

How do you handle dropdowns in Selenium?

InfosysMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1373

Difference between ArrayList and LinkedList?

InfosysMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1374

How do you upload a file with Selenium?

InfosysMedium
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.
1375

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
1376

What is a webhook and how do you test it?

InfosysMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
1377

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
1378

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1379

How do you group tests?

InfosysMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
1380

What is a Jenkins pipeline?

InfosysMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1381

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1382

What are the advantages of version control for test code?

InfosysMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1383

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
1384

How do you run JavaScript in Selenium?

InfosysMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
1385

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

InfosysMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
1386

What new features came with Selenium 4?

InfosysMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
1387

How does the DataProvider annotation work?

InfosysMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
1388

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
1389

What is Docker and how does it help tests?

InfosysMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1390

How do you switch between windows and tabs?

InfosysMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
1391

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

InfosysMedium
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.
1392

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1393

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

InfosysMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1394

What is the difference between Comparable and Comparator in Java?

InfosysMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
1395

What is OAuth 2.0 in API testing?

InfosysMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
1396

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
1397

What is Postman and how do you automate with it?

InfosysMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
1398

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

InfosysMedium
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.
1399

What is the difference between getText() and getAttribute()?

WiproMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
1400

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

WiproMedium
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.
1401

How do you validate a JSON response in REST Assured?

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

How do you handle StaleElementReferenceException?

WiproMedium
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.
1403

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

WiproMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1404

Implicit vs explicit vs fluent wait?

WiproEasy
Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
1405

What are the Actions class use cases?

WiproMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1406

Method overloading vs overriding?

WiproEasy
Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
1407

What is Docker and how does it help tests?

WiproMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1408

Write an XPath for a button with the text "Login".

WiproEasy
Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
1409

Tests pass locally but fail on Jenkins. Why?

WiproHard
Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
1410

How do you calculate automation ROI?

WiproHard
Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1411

Explain your CI/CD pipeline for tests.

WiproHard
Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
1412

Common HTTP status codes?

WiproEasy
Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1413

Where do you use OOP concepts in your framework?

WiproMedium
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.
1414

What is the difference between hard and soft assertions?

WiproMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1415

What are the different types of waits in Selenium?

WiproMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
1416

What is BDD and how does Cucumber work?

WiproMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
1417

How do you handle a web table in Selenium?

WiproMedium
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.
1418

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

WiproEasy
Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
1419

findElement vs findElements?

WiproEasy
Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1420

Difference between absolute and relative XPath?

WiproMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
1421

How do you handle environment-specific configuration?

WiproMedium
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.
1422

Write a GET test in REST Assured.

WiproMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1423

What is an API and what are common HTTP methods?

WiproEasy
Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1424

What are access modifiers in Java?

WiproMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1425

What are relative locators in Selenium 4?

WiproMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1426

What is a constructor and can it be overloaded?

WiproMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
1427

What locators does Selenium support?

WiproEasy
Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1428

How do you handle alerts and pop-ups?

WiproMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
1429

How would you design an automation framework from scratch?

WiproHard
Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
1430

How do you scroll a page in Selenium?

WiproMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
1431

What is a Jenkins pipeline?

WiproMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1432

Reverse a string in Java.

WiproEasy
Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
1433

What are the advantages of version control for test code?

WiproMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1434

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

WiproMedium
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.
1435

How would you design a CI pipeline for nightly regression?

WiproHard
Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1436

How do you group tests?

WiproMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
1437

What is REST Assured?

WiproMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
1438

What is Selenium and what are its components?

WiproEasy
Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
1439

What is WebDriver and how does it communicate with the browser?

WiproEasy
Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
1440

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
1441

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1442

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
1443

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
1444

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
1445

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
1446

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
1447

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1448

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
1449

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
1450

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
1451

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
1452

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1453

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
1454

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
1455

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1456

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1457

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1458

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
1459

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
1460

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1461

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
1462

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
1463

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
1464

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1465

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1466

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1467

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
1468

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
1469

How do you handle a web table in Selenium?

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.
1470

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1471

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

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.
1472

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
1473

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1474

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1475

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1476

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1477

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
1478

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
1479

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1480

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
1481

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1482

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
1483

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
1484

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
1485

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
1486

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
1487

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
1488

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
1489

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
1490

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
1491

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

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.
1492

What is a DataProvider in TestNG?

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.
1493

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
1494

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
1495

How do you manage test data in a framework?

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.
1496

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
1497

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1498

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1499

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
1500

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1501

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
1502

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
1503

How do you handle environment-specific configuration?

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.
1504

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1505

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
1506

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
1507

Where do you use OOP concepts in your framework?

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.
1508

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
1509

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
1510

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
1511

How do you handle StaleElementReferenceException?

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.
1512

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
1513

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
1514

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
1515

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
1516

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1517

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
1518

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
1519

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

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.
1520

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1521

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
1522

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1523

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1524

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1525

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1526

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
1527

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
1528

Where do you use OOP concepts in your framework?

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.
1529

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
1530

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
1531

How do you manage test data in a framework?

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.
1532

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1533

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1534

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
1535

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1536

How do you handle StaleElementReferenceException?

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.
1537

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
1538

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
1539

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

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.
1540

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1541

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
1542

How do you handle environment-specific configuration?

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.
1543

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1544

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
1545

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
1546

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1547

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
1548

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
1549

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
1550

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
1551

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1552

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
1553

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1554

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
1555

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
1556

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
1557

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
1558

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
1559

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
1560

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
1561

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1562

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
1563

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1564

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1565

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
1566

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1567

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
1568

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
1569

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
1570

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1571

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
1572

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1573

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
1574

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
1575

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
1576

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
1577

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1578

How do you group tests?

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

How do you handle a web table in Selenium?

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.
1580

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
1581

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
1582

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
1583

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1584

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
1585

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
1586

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
1587

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
1588

How do you group tests?

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

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
1590

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
1591

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
1592

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
1593

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
1594

What is a DataProvider in TestNG?

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.
1595

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1596

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1597

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
1598

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
1599

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
1600

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
1601

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1602

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
1603

How do you validate a JSON response in REST Assured?

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

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
1605

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1606

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
1607

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1608

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1609

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
1610

How do you upload a file with Selenium?

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.
1611

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
1612

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1613

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
1614

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
1615

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1616

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
1617

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
1618

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
1619

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
1620

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1621

How do you handle environment-specific configuration?

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.
1622

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
1623

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
1624

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

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.
1625

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1626

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
1627

Where do you use OOP concepts in your framework?

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.
1628

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
1629

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
1630

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
1631

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1632

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
1633

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
1634

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1635

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1636

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
1637

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
1638

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1639

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
1640

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
1641

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1642

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
1643

What is Selenium Grid and why use it?

DeloitteMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
1644

What is the difference between Comparable and Comparator in Java?

DeloitteMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
1645

What is PageFactory?

DeloitteMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
1646

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
1647

Where do you use OOP concepts in your framework?

DeloitteMedium
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.
1648

What is the difference between hard and soft assertions?

DeloitteMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1649

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
1650

How do you switch between windows and tabs?

DeloitteMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
1651

What are try-with-resources and why use them?

DeloitteMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1652

How do you handle a dropdown that is not a <select> tag?

DeloitteMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
1653

What is contract testing?

DeloitteMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
1654

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
1655

Write a GET test in REST Assured.

DeloitteMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1656

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1657

How do you handle alerts and pop-ups?

DeloitteMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
1658

What are listeners in TestNG?

DeloitteMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
1659

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1660

What is the use of the this and super keywords?

DeloitteMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1661

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
1662

POST vs PUT vs PATCH?

DeloitteMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
1663

How do you validate a JSON response in REST Assured?

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

What is the difference between @BeforeTest and @BeforeMethod?

DeloitteMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1665

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
1666

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
1667

What are Java collections and which ones do testers use most?

DeloitteMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
1668

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1669

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

DeloitteMedium
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.
1670

What new features came with Selenium 4?

DeloitteMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
1671

What is a Jenkins pipeline?

DeloitteMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1672

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
1673

What is BDD and how does Cucumber work?

DeloitteMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
1674

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
1675

What is the difference between SOAP and REST?

DeloitteMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
1676

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
1677

What is method overriding and where is it useful in frameworks?

DeloitteMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
1678

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
1679

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1680

How do you test an API that depends on another service that is down?

DeloitteMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
1681

What is polymorphism and how does it show up in Selenium?

DeloitteMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1682

How do you handle multiple windows?

DeloitteMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1683

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

DeloitteMedium
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.
1684

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

DeloitteMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1685

How do you run JavaScript in Selenium?

DeloitteMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
1686

What are the Actions class use cases?

DeloitteMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1687

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
1688

What is data-driven testing?

DeloitteMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1689

What are relative locators in Selenium 4?

DeloitteMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1690

What is the difference between getText() and getAttribute()?

DeloitteMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
1691

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
1692

How do you handle StaleElementReferenceException?

DeloitteMedium
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.
1693

How do you run tests in parallel?

DeloitteMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1694

How do you pass authentication in an API test?

DeloitteMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
1695

What is Docker and how does it help tests?

DeloitteMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1696

How do you upload a file with Selenium?

DeloitteMedium
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.
1697

How do you handle dropdowns in Selenium?

DeloitteMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1698

How do you take a screenshot on failure in TestNG?

DeloitteMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
1699

How do you handle iframes?

DeloitteMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
1700

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
1701

Difference between ArrayList and LinkedList?

DeloitteMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1702

How do you handle a web table in Selenium?

DeloitteMedium
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.
1703

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
1704

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
1705

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1706

What are access modifiers in Java?

DeloitteMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1707

What is the difference between throw and throws?

DeloitteMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
1708

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
1709

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

DeloitteMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1710

What is the use of Maven in automation projects?

DeloitteMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
1711

How do you handle iframes?

AmazonMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
1712

What are the Actions class use cases?

AmazonMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1713

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
1714

How do you retry failed tests in TestNG?

AmazonMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
1715

What is Docker and how does it help tests?

AmazonMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1716

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

AmazonMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
1717

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

AmazonMedium
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.
1718

What are the advantages of version control for test code?

AmazonMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1719

How do you integrate Selenium tests with Jenkins?

AmazonMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
1720

How do you pass authentication in an API test?

AmazonMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
1721

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
1722

What are Java 8 streams and lambdas?

AmazonMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1723

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
1724

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
1725

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
1726

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
1727

How do you switch between windows and tabs?

AmazonMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
1728

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
1729

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
1730

What are access modifiers in Java?

AmazonMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1731

What is the use of Maven in automation projects?

AmazonMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
1732

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1733

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

AmazonMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1734

What is a constructor and can it be overloaded?

AmazonMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
1735

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

AmazonMedium
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.
1736

What is a Jenkins pipeline?

AmazonMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1737

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
1738

Difference between ArrayList and LinkedList?

AmazonMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1739

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
1740

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

AmazonMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
1741

What is REST Assured?

AmazonMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
1742

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
1743

What does dependsOnMethods do?

AmazonMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
1744

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1745

How does the DataProvider annotation work?

AmazonMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
1746

How do you validate a JSON response in REST Assured?

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

How do you upload a file with Selenium?

AmazonMedium
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.
1748

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
1749

What are try-with-resources and why use them?

AmazonMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1750

What is a DataProvider in TestNG?

AmazonMedium
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.
1751

What is the Hybrid framework?

AmazonMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
1752

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1753

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1754

What are the different types of waits in Selenium?

AmazonMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
1755

What is the difference between Comparable and Comparator in Java?

AmazonMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
1756

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1757

How do you group tests?

AmazonMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
1758

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
1759

What is the difference between driver.close() and driver.quit()?

AmazonMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
1760

What is Selenium Grid and why use it?

AmazonMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
1761

What is the difference between an array and an ArrayList?

AmazonMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
1762

What is data-driven testing?

AmazonMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1763

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
1764

How do you handle alerts and pop-ups?

AmazonMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
1765

How do you run JavaScript in Selenium?

AmazonMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
1766

How do you manage test data in a framework?

AmazonMedium
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.
1767

Where do you use OOP concepts in your framework?

AmazonMedium
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.
1768

How do you handle dropdowns in Selenium?

AmazonMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1769

POST vs PUT vs PATCH?

AmazonMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
1770

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1771

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1772

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
1773

Write a GET test in REST Assured.

AmazonMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1774

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
1775

What is PageFactory?

AmazonMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
1776

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
1777

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
1778

What is the difference between throw and throws?

AmazonMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
1779

Which reporting tools do you use?

AmazonMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
1780

What is the difference between @BeforeTest and @BeforeMethod?

AmazonMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1781

What are Java collections and which ones do testers use most?

AmazonMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
1782

What is Postman and how do you automate with it?

AmazonMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
1783

What is polymorphism and how does it show up in Selenium?

AmazonMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1784

How do you run tests in parallel?

AmazonMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1785

What is OAuth 2.0 in API testing?

AmazonMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
1786

What are try-with-resources and why use them?

GoogleMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
1787

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
1788

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
1789

Where do you use OOP concepts in your framework?

GoogleMedium
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.
1790

What does dependsOnMethods do?

GoogleMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
1791

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
1792

What is the Hybrid framework?

GoogleMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
1793

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
1794

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
1795

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1796

How do you test an API that depends on another service that is down?

GoogleMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
1797

What is the difference between Comparable and Comparator in Java?

GoogleMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
1798

What is the difference between driver.close() and driver.quit()?

GoogleMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
1799

What is the difference between SOAP and REST?

GoogleMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
1800

What is the difference between hard and soft assertions?

GoogleMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1801

Difference between ArrayList and LinkedList?

GoogleMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1802

How do you handle alerts and pop-ups?

GoogleMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
1803

How do you retry failed tests in TestNG?

GoogleMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
1804

How do you run JavaScript in Selenium?

GoogleMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
1805

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
1806

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1807

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
1808

How do you manage test data in a framework?

GoogleMedium
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.
1809

What are relative locators in Selenium 4?

GoogleMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1810

How does HashMap work internally?

GoogleMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
1811

What is the difference between throw and throws?

GoogleMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
1812

What is the use of the this and super keywords?

GoogleMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1813

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
1814

What is data-driven testing?

GoogleMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1815

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
1816

What are the advantages of version control for test code?

GoogleMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1817

What are access modifiers in Java?

GoogleMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1818

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1819

What is REST Assured?

GoogleMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
1820

How do you integrate Selenium tests with Jenkins?

GoogleMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
1821

How do you pass parameters from testng.xml?

GoogleMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
1822

How do you handle a web table in Selenium?

GoogleMedium
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.
1823

How do you handle multiple windows?

GoogleMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1824

What is the difference between @BeforeTest and @BeforeMethod?

GoogleMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1825

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

GoogleMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
1826

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1827

POST vs PUT vs PATCH?

GoogleMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
1828

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

GoogleMedium
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.
1829

What is BDD and how does Cucumber work?

GoogleMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
1830

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
1831

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
1832

How do you upload a file with Selenium?

GoogleMedium
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.
1833

What is a constructor and can it be overloaded?

GoogleMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
1834

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
1835

What is OAuth 2.0 in API testing?

GoogleMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
1836

What is a Jenkins pipeline?

GoogleMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1837

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1838

What are Java 8 streams and lambdas?

GoogleMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1839

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1840

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
1841

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
1842

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

GoogleMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1843

What is method overriding and where is it useful in frameworks?

GoogleMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
1844

What new features came with Selenium 4?

GoogleMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
1845

What is a DataProvider in TestNG?

GoogleMedium
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.
1846

How do you scroll a page in Selenium?

GoogleMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
1847

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
1848

How do you handle dynamic elements whose ids change?

GoogleMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
1849

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
1850

What is polymorphism and how does it show up in Selenium?

GoogleMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1851

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

GoogleMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
1852

Difference between absolute and relative XPath?

GoogleMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
1853

findElement vs findElements?

MetaEasy
Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1854

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

MetaMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1855

What is a DataProvider in TestNG?

MetaMedium
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.
1856

Write an XPath for a button with the text "Login".

MetaEasy
Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
1857

How do you group tests?

MetaMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
1858

What is an API and what are common HTTP methods?

MetaEasy
Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1859

What is data-driven testing?

MetaMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1860

How do you handle a web table in Selenium?

MetaMedium
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.
1861

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

MetaEasy
Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
1862

How do you reduce flakiness in a CI pipeline?

MetaHard
Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
1863

How does HashMap work internally?

MetaMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
1864

Write a GET test in REST Assured.

MetaMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1865

What is a Jenkins pipeline?

MetaMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1866

What is BDD and how does Cucumber work?

MetaMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
1867

Which reporting tools do you use?

MetaMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
1868

What is the difference between an array and an ArrayList?

MetaMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
1869

What locators does Selenium support?

MetaEasy
Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1870

What is a webhook and how do you test it?

MetaMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
1871

What is Selenium and what are its components?

MetaEasy
Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
1872

What are Java 8 streams and lambdas?

MetaMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1873

How do you handle dropdowns in Selenium?

MetaMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1874

ArrayList vs HashMap — how do you use them in a framework?

MetaEasy
Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
1875

What is JSON and how is it used in API testing?

MetaEasy
Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
1876

What is the difference between == and equals() in Java?

MetaEasy
Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
1877

What is PageFactory?

MetaMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
1878

What is Docker and how does it help tests?

MetaMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1879

How do you manage test data in a framework?

MetaMedium
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.
1880

What are the Actions class use cases?

MetaMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1881

How do you handle multiple windows?

MetaMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1882

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

MetaMedium
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.
1883

Difference between ArrayList and LinkedList?

MetaMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1884

Explain your CI/CD pipeline for tests.

MetaHard
Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
1885

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

MetaMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1886

What are Java collections and which ones do testers use most?

MetaMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
1887

What is polymorphism and how does it show up in Selenium?

MetaMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1888

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
1889

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
1890

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1891

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
1892

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
1893

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
1894

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
1895

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
1896

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
1897

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
1898

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
1899

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
1900

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
1901

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
1902

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
1903

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
1904

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1905

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
1906

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
1907

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
1908

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
1909

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1910

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
1911

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1912

How do you group tests?

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

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
1914

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1915

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
1916

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
1917

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
1918

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
1919

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
1920

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
1921

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1922

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
1923

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
1924

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
1925

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1926

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
1927

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
1928

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1929

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1930

How would you automate a login flow with multiple user roles?

AppleHard
Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
1931

How do you reduce flakiness in a CI pipeline?

AppleHard
Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
1932

What is OAuth 2.0 in API testing?

AppleMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
1933

How does the DataProvider annotation work?

AppleMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
1934

What is contract testing?

AppleMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
1935

What is the difference between @BeforeTest and @BeforeMethod?

AppleMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1936

What is data-driven testing?

AppleMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
1937

What is the difference between getText() and getAttribute()?

AppleMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
1938

How do you run JavaScript in Selenium?

AppleMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
1939

Difference between final, finally and finalize?

AppleEasy
Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
1940

What is TestNG and why is it used with Selenium?

AppleEasy
Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
1941

What are Java 8 streams and lambdas?

AppleMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
1942

Common HTTP status codes?

AppleEasy
Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
1943

What are relative locators in Selenium 4?

AppleMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
1944

What is a DataProvider in TestNG?

AppleMedium
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.
1945

What is polymorphism and how does it show up in Selenium?

AppleMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1946

findElement vs findElements?

AppleEasy
Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
1947

Which reporting tools do you use?

AppleMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
1948

What is Docker and how does it help tests?

AppleMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1949

POST vs PUT vs PATCH?

AppleMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
1950

What is Postman and how do you automate with it?

AppleMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
1951

How do you handle multiple windows?

AppleMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1952

How do you take a screenshot on failure in TestNG?

AppleMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
1953

List common TestNG annotations and their order.

AppleEasy
Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
1954

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

LinkedInMedium
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.
1955

What is Docker and how does it help tests?

LinkedInMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
1956

Difference between absolute and relative XPath?

LinkedInMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
1957

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
1958

How do you switch between windows and tabs?

LinkedInMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
1959

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
1960

How do you take a screenshot on failure in TestNG?

LinkedInMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
1961

How do you handle a dropdown that is not a <select> tag?

LinkedInMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
1962

What is the use of the this and super keywords?

LinkedInMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1963

What is the Hybrid framework?

LinkedInMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
1964

How do you run tests in parallel?

LinkedInMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1965

How do you handle a web table in Selenium?

LinkedInMedium
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.
1966

What is a webhook and how do you test it?

LinkedInMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
1967

What is polymorphism and how does it show up in Selenium?

LinkedInMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
1968

What is the difference between driver.close() and driver.quit()?

LinkedInMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
1969

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
1970

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
1971

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

LinkedInMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
1972

What is the difference between @BeforeTest and @BeforeMethod?

LinkedInMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
1973

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
1974

Write a GET test in REST Assured.

LinkedInMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
1975

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
1976

What are access modifiers in Java?

LinkedInMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
1977

What is the difference between hard and soft assertions?

LinkedInMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
1978

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
1979

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
1980

How do you handle dropdowns in Selenium?

LinkedInMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
1981

How do you validate a JSON response in REST Assured?

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

What is a Jenkins pipeline?

LinkedInMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
1983

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
1984

How do you test an API that depends on another service that is down?

LinkedInMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
1985

What is the use of Maven in automation projects?

LinkedInMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
1986

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
1987

Difference between ArrayList and LinkedList?

LinkedInMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
1988

What is REST Assured?

LinkedInMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
1989

How do you handle multiple windows?

LinkedInMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1990

How does the DataProvider annotation work?

LinkedInMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
1991

How do you group tests?

LinkedInMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
1992

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

LinkedInMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
1993

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
1994

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
1995

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
1996

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
1997

How do you handle StaleElementReferenceException?

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.
1998

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
1999

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
2000

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
2001

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2002

Where do you use OOP concepts in your framework?

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.
2003

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
2004

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2005

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2006

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2007

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
2008

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
2009

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

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.
2010

How do you handle environment-specific configuration?

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.
2011

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
2012

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2013

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2014

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
2015

How do you manage test data in a framework?

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.
2016

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
2017

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
2018

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2019

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2020

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
2021

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
2022

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
2023

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2024

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2025

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
2026

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
2027

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
2028

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2029

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
2030

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
2031

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
2032

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2033

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2034

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
2035

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
2036

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
2037

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
2038

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
2039

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2040

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
2041

Which reporting tools do you use?

UberMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2042

How do you validate a JSON response in REST Assured?

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

String vs StringBuilder?

UberEasy
Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2044

What are the main OOP concepts in Java?

UberEasy
Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2045

What is contract testing?

UberMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
2046

How do you retry failed tests in TestNG?

UberMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
2047

What are the different types of waits in Selenium?

UberMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2048

How do you handle StaleElementReferenceException?

UberMedium
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.
2049

How would you design a CI pipeline for nightly regression?

UberHard
Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2050

What is an API and what are common HTTP methods?

UberEasy
Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
2051

Where do you use OOP concepts in your framework?

UberMedium
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.
2052

Reverse a string in Java.

UberEasy
Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
2053

How do you handle iframes?

UberMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
2054

How do you handle dropdowns in Selenium?

UberMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
2055

What does dependsOnMethods do?

UberMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
2056

What is a DataProvider in TestNG?

UberMedium
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.
2057

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

UberMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
2058

What are wrapper classes in Java?

UberEasy
Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2059

What are the advantages of version control for test code?

UberMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
2060

Explain your CI/CD pipeline for tests.

UberHard
Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
2061

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

UberMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
2062

Write a GET test in REST Assured.

UberMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
2063

What is OAuth 2.0 in API testing?

UberMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2064

What is data-driven testing?

UberMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2065

What are access modifiers in Java?

UberMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
2066

What is the purpose of testng.xml?

UberEasy
Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2067

Common HTTP status codes?

UberEasy
Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
2068

What are try-with-resources and why use them?

UberMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
2069

How do you handle environment-specific configuration?

UberMedium
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.
2070

findElement vs findElements?

UberEasy
Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
2071

What is Docker and how does it help tests?

UberMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
2072

What is the difference between throw and throws?

UberMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
2073

How would you automate a login flow with multiple user roles?

UberHard
Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2074

What is the difference between @BeforeTest and @BeforeMethod?

UberMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
2075

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

UberMedium
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.
2076

Difference between ArrayList and LinkedList?

UberMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
2077

Difference between an abstract class and an interface?

UberEasy
Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
2078

What are exceptions and how do you handle them?

UberEasy
Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2079

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

UberMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2080

How do you pass authentication in an API test?

UberMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2081

What is a Jenkins pipeline?

UberMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2082

What is the difference between driver.close() and driver.quit()?

UberMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2083

How would you design an automation framework from scratch?

UberHard
Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2084

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

UberEasy
Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
2085

What are relative locators in Selenium 4?

UberMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
2086

Write an XPath for a button with the text "Login".

UberEasy
Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2087

What is the difference between == and equals() in Java?

UberEasy
Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
2088

What is the difference between SOAP and REST?

UberMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
2089

What is JSON and how is it used in API testing?

UberEasy
Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
2090

What are Java collections and which ones do testers use most?

UberMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
2091

What is the difference between hard and soft assertions?

UberMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2092

What is method overriding and where is it useful in frameworks?

UberMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
2093

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

UberMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
2094

Tests pass locally but fail on Jenkins. Why?

UberHard
Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
2095

How do you manage test data in a framework?

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.
2096

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
2097

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
2098

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

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.
2099

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
2100

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
2101

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
2102

How do you upload a file with Selenium?

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.
2103

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
2104

How do you handle a web table in Selenium?

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.
2105

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2106

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
2107

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
2108

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2109

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
2110

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
2111

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2112

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2113

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2114

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
2115

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
2116

How do you group tests?

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

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
2118

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2119

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
2120

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2121

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2122

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2123

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
2124

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
2125

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
2126

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
2127

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
2128

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2129

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
2130

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2131

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
2132

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2133

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2134

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
2135

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
2136

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
2137

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2138

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
2139

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
2140

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
2141

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2142

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

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.
2143

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
2144

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
2145

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
2146

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
2147

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2148

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2149

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
2150

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
2151

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
2152

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
2153

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
2154

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
2155

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
2156

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
2157

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
2158

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2159

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2160

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
2161

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
2162

How do you group tests?

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

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2164

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
2165

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
2166

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2167

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
2168

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
2169

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
2170

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
2171

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

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.
2172

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
2173

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
2174

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2175

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
2176

How do you validate a JSON response in REST Assured?

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

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
2178

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
2179

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
2180

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2181

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
2182

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
2183

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
2184

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
2185

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2186

How do you upload a file with Selenium?

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.
2187

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
2188

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2189

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2190

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
2191

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
2192

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2193

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
2194

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
2195

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2196

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
2197

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
2198

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2199

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
2200

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
2201

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
2202

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
2203

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
2204

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
2205

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2206

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2207

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
2208

What is a DataProvider in TestNG?

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.
2209

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
2210

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2211

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
2212

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2213

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
2214

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2215

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
2216

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
2217

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
2218

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2219

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2220

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
2221

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
2222

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
2223

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2224

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
2225

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2226

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
2227

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2228

How do you handle environment-specific configuration?

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.
2229

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
2230

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
2231

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
2232

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
2233

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
2234

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2235

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
2236

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
2237

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
2238

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
2239

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
2240

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
2241

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
2242

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2243

How do you handle StaleElementReferenceException?

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.
2244

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
2245

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
2246

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
2247

How do you group tests?

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

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
2249

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2250

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2251

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
2252

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
2253

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
2254

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
2255

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
2256

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2257

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
2258

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2259

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
2260

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2261

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
2262

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
2263

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
2264

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2265

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
2266

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2267

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
2268

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
2269

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2270

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
2271

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
2272

What is contract testing?

StripeMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
2273

What is a Jenkins pipeline?

StripeMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2274

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
2275

What is the difference between driver.close() and driver.quit()?

StripeMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2276

Difference between ArrayList and LinkedList?

StripeMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
2277

What is Selenium Grid and why use it?

StripeMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
2278

What are Java collections and which ones do testers use most?

StripeMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
2279

What does dependsOnMethods do?

StripeMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
2280

How do you scroll a page in Selenium?

StripeMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
2281

How do you switch between windows and tabs?

StripeMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2282

How do you validate a JSON response in REST Assured?

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

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
2284

How do you handle StaleElementReferenceException?

StripeMedium
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.
2285

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2286

How do you pass authentication in an API test?

StripeMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2287

What is data-driven testing?

StripeMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2288

How do you group tests?

StripeMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
2289

What are relative locators in Selenium 4?

StripeMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
2290

How do you run tests in parallel?

StripeMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
2291

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2292

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2293

How do you handle a web table in Selenium?

StripeMedium
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.
2294

What is a webhook and how do you test it?

StripeMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
2295

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
2296

What are the Actions class use cases?

StripeMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2297

How does HashMap work internally?

StripeMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
2298

What are the different types of waits in Selenium?

StripeMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2299

What is OAuth 2.0 in API testing?

StripeMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2300

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2301

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
2302

How do you handle dropdowns in Selenium?

StripeMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
2303

What is the Hybrid framework?

StripeMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
2304

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2305

What new features came with Selenium 4?

StripeMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2306

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
2307

Where do you use OOP concepts in your framework?

StripeMedium
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.
2308

What is Docker and how does it help tests?

StripeMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
2309

How do you run JavaScript in Selenium?

StripeMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
2310

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
2311

How do you retry failed tests in TestNG?

StripeMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
2312

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

StripeMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2313

What is the difference between Comparable and Comparator in Java?

StripeMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
2314

What is the difference between SOAP and REST?

StripeMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
2315

Which reporting tools do you use?

StripeMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2316

What is the use of Maven in automation projects?

StripeMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
2317

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

StripeMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
2318

What is BDD and how does Cucumber work?

StripeMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
2319

What is the difference between @BeforeTest and @BeforeMethod?

StripeMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
2320

How do you pass parameters from testng.xml?

StripeMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2321

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2322

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
2323

How do you handle environment-specific configuration?

StripeMedium
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.
2324

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
2325

How do you handle multiple windows?

StripeMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
2326

What is the difference between throw and throws?

StripeMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
2327

What is the difference between getText() and getAttribute()?

StripeMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
2328

What is the difference between hard and soft assertions?

StripeMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2329

What is polymorphism and how does it show up in Selenium?

StripeMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
2330

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2331

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
2332

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
2333

Difference between absolute and relative XPath?

StripeMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
2334

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
2335

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
2336

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

StripeMedium
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.
2337

How do you integrate Selenium tests with Jenkins?

StripeMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
2338

What is the use of the this and super keywords?

StripeMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
2339

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
2340

How does the DataProvider annotation work?

StripeMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
2341

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2342

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
2343

How do you handle a dropdown that is not a <select> tag?

StripeMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
2344

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
2345

How do you handle multiple windows?

PayPalMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
2346

How do you run tests in parallel?

PayPalMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
2347

How do you pass parameters from testng.xml?

PayPalMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2348

What is the use of the this and super keywords?

PayPalMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
2349

What is Postman and how do you automate with it?

PayPalMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
2350

What is the difference between an array and an ArrayList?

PayPalMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
2351

How do you handle StaleElementReferenceException?

PayPalMedium
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.
2352

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
2353

What are the different types of waits in Selenium?

PayPalMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2354

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
2355

How do you handle environment-specific configuration?

PayPalMedium
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.
2356

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
2357

What is method overriding and where is it useful in frameworks?

PayPalMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
2358

How do you handle iframes?

PayPalMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
2359

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

PayPalMedium
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.
2360

What is the difference between hard and soft assertions?

PayPalMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2361

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2362

How does HashMap work internally?

PayPalMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
2363

What is a Jenkins pipeline?

PayPalMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2364

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
2365

How do you handle dynamic elements whose ids change?

PayPalMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
2366

How do you pass authentication in an API test?

PayPalMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2367

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
2368

What is the difference between Comparable and Comparator in Java?

PayPalMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
2369

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2370

What is data-driven testing?

PayPalMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2371

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
2372

How do you test an API that depends on another service that is down?

PayPalMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
2373

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2374

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

PayPalMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
2375

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
2376

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2377

How do you upload a file with Selenium?

PayPalMedium
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.
2378

What are the Actions class use cases?

PayPalMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2379

How do you integrate Selenium tests with Jenkins?

PayPalMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
2380

What does dependsOnMethods do?

PayPalMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
2381

How do you handle a dropdown that is not a <select> tag?

PayPalMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
2382

What is Docker and how does it help tests?

PayPalMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
2383

How do you take a screenshot on failure in TestNG?

PayPalMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
2384

How do you retry failed tests in TestNG?

PayPalMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
2385

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2386

How do you handle alerts and pop-ups?

PayPalMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
2387

What is Selenium Grid and why use it?

PayPalMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
2388

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
2389

What are access modifiers in Java?

PayPalMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
2390

What is the use of Maven in automation projects?

PayPalMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
2391

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
2392

How do you handle dropdowns in Selenium?

PayPalMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
2393

Write a GET test in REST Assured.

PayPalMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
2394

How do you validate a JSON response in REST Assured?

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

What are Java collections and which ones do testers use most?

PayPalMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
2396

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

PayPalMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2397

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
2398

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
2399

What are listeners in TestNG?

PayPalMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
2400

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
2401

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

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.
2402

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2403

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
2404

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
2405

How do you validate a JSON response in REST Assured?

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

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
2407

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2408

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
2409

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
2410

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
2411

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

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.
2412

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
2413

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
2414

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
2415

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2416

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2417

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
2418

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
2419

Where do you use OOP concepts in your framework?

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.
2420

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2421

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
2422

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2423

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
2424

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
2425

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
2426

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
2427

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2428

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
2429

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
2430

How do you handle a web table in Selenium?

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.
2431

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
2432

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
2433

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
2434

How do you manage test data in a framework?

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.
2435

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2436

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
2437

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
2438

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
2439

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2440

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2441

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2442

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
2443

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
2444

What is a DataProvider in TestNG?

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.
2445

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
2446

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
2447

How do you handle environment-specific configuration?

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.
2448

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
2449

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
2450

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2451

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
2452

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
2453

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
2454

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
2455

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
2456

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
2457

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
2458

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
2459

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2460

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
2461

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2462

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
2463

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2464

How do you upload a file with Selenium?

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.
2465

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
2466

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
2467

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2468

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2469

What is BDD and how does Cucumber work?

AdobeMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
2470

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

AdobeMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
2471

How would you design a CI pipeline for nightly regression?

AdobeHard
Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2472

What is OAuth 2.0 in API testing?

AdobeMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2473

What is the difference between static and non-static members?

AdobeMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
2474

What is the Page Object Model?

AdobeEasy
Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2475

How do you take a screenshot on failure in TestNG?

AdobeMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
2476

How do you validate a JSON response in REST Assured?

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

What are wrapper classes in Java?

AdobeEasy
Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2478

Difference between ArrayList and LinkedList?

AdobeMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
2479

What is Docker and how does it help tests?

AdobeMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
2480

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

AdobeMedium
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.
2481

Difference between absolute and relative XPath?

AdobeMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
2482

How do you handle iframes?

AdobeMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
2483

What are listeners in TestNG?

AdobeMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
2484

How would you design an automation framework from scratch?

AdobeHard
Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2485

What are exceptions and how do you handle them?

AdobeEasy
Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2486

What are the different types of waits in Selenium?

AdobeMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2487

Tests pass locally but fail on Jenkins. Why?

AdobeHard
Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
2488

How do you handle a website that uses CAPTCHA?

AdobeHard
Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
2489

What is the difference between driver.close() and driver.quit()?

AdobeMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2490

What is the difference between @BeforeTest and @BeforeMethod?

AdobeMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
2491

How do you upload a file with Selenium?

AdobeMedium
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.
2492

What are the Actions class use cases?

AdobeMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2493

What is TestNG and why is it used with Selenium?

AdobeEasy
Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
2494

What are Java 8 streams and lambdas?

AdobeMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
2495

Where do you use OOP concepts in your framework?

AdobeMedium
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.
2496

Common HTTP status codes?

AdobeEasy
Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
2497

What are Java collections and which ones do testers use most?

AdobeMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
2498

How do you handle dropdowns in Selenium?

AdobeMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
2499

What are the main OOP concepts in Java?

AdobeEasy
Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2500

What is a Jenkins pipeline?

AdobeMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2501

What is a webhook and how do you test it?

AdobeMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
2502

How do you switch between windows and tabs?

AdobeMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2503

How do you scroll a page in Selenium?

AdobeMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
2504

What are the advantages of version control for test code?

AdobeMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
2505

Method overloading vs overriding?

AdobeEasy
Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
2506

What is REST Assured?

AdobeMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
2507

What is the use of the this and super keywords?

AdobeMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
2508

What is an API and what are common HTTP methods?

AdobeEasy
Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
2509

What is the use of Maven in automation projects?

AdobeMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
2510

Write an XPath for a button with the text "Login".

AdobeEasy
Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2511

How do you calculate automation ROI?

AdobeHard
Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2512

What is the difference between getText() and getAttribute()?

AdobeMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
2513

How do you pass authentication in an API test?

AdobeMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2514

What is WebDriver and how does it communicate with the browser?

AdobeEasy
Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
2515

What is a constructor and can it be overloaded?

AdobeMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
2516

What is the Hybrid framework?

AdobeMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
2517

How do you pass parameters from testng.xml?

AdobeMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2518

What new features came with Selenium 4?

AdobeMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2519

Difference between an abstract class and an interface?

AdobeEasy
Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
2520

How do you handle alerts and pop-ups?

AdobeMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
2521

How do you handle multiple windows?

AdobeMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
2522

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

AdobeMedium
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.
2523

What is the difference between == and equals() in Java?

AdobeEasy
Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
2524

What is the purpose of testng.xml?

AdobeEasy
Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2525

How do you run JavaScript in Selenium?

AdobeMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
2526

How do you test an API that depends on another service that is down?

AdobeMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
2527

What is Postman and how do you automate with it?

AdobeMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
2528

How do you reduce flakiness in a CI pipeline?

AdobeHard
Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
2529

What is the difference between an array and an ArrayList?

AdobeMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
2530

What is polymorphism and how does it show up in Selenium?

FlipkartMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
2531

What new features came with Selenium 4?

FlipkartMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2532

How do you handle multiple windows?

FlipkartMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
2533

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2534

What are the different types of waits in Selenium?

FlipkartMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2535

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
2536

What is a webhook and how do you test it?

FlipkartMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
2537

Which reporting tools do you use?

FlipkartMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2538

POST vs PUT vs PATCH?

FlipkartMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
2539

What is the difference between throw and throws?

FlipkartMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
2540

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2541

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

FlipkartMedium
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.
2542

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2543

What is method overriding and where is it useful in frameworks?

FlipkartMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
2544

How do you switch between windows and tabs?

FlipkartMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2545

What are Java 8 streams and lambdas?

FlipkartMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
2546

How do you handle environment-specific configuration?

FlipkartMedium
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.
2547

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

FlipkartMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
2548

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
2549

How do you group tests?

FlipkartMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
2550

What is OAuth 2.0 in API testing?

FlipkartMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2551

What are the advantages of version control for test code?

FlipkartMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
2552

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
2553

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2554

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

FlipkartMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
2555

How do you retry failed tests in TestNG?

FlipkartMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
2556

How do you upload a file with Selenium?

FlipkartMedium
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.
2557

Where do you use OOP concepts in your framework?

FlipkartMedium
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.
2558

What are relative locators in Selenium 4?

FlipkartMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
2559

How do you pass parameters from testng.xml?

FlipkartMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2560

How do you test an API that depends on another service that is down?

FlipkartMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
2561

How do you handle dynamic elements whose ids change?

FlipkartMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
2562

Difference between ArrayList and LinkedList?

FlipkartMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
2563

What is the difference between driver.close() and driver.quit()?

FlipkartMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2564

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2565

How does the DataProvider annotation work?

FlipkartMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
2566

What is REST Assured?

FlipkartMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
2567

How do you integrate Selenium tests with Jenkins?

FlipkartMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
2568

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2569

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
2570

What is Selenium Grid and why use it?

FlipkartMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
2571

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
2572

What is the difference between getText() and getAttribute()?

FlipkartMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
2573

What are listeners in TestNG?

FlipkartMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
2574

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
2575

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2576

What is a Jenkins pipeline?

FlipkartMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2577

What is the difference between an array and an ArrayList?

FlipkartMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
2578

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2579

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
2580

What are Java collections and which ones do testers use most?

FlipkartMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
2581

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
2582

What is the difference between Comparable and Comparator in Java?

FlipkartMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
2583

How do you take a screenshot on failure in TestNG?

FlipkartMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
2584

What is the Hybrid framework?

FlipkartMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
2585

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

FlipkartMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2586

What is a constructor and can it be overloaded?

FlipkartMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
2587

How do you run tests in parallel?

FlipkartMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
2588

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
2589

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
2590

What is data-driven testing?

FlipkartMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2591

How do you pass authentication in an API test?

FlipkartMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2592

How do you handle iframes?

FlipkartMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
2593

What is a DataProvider in TestNG?

FlipkartMedium
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.
2594

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

FlipkartMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
2595

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
2596

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

FlipkartMedium
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.
2597

How do you manage test data in a framework?

FlipkartMedium
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.
2598

What is the use of Maven in automation projects?

FlipkartMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
2599

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
2600

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2601

How do you handle StaleElementReferenceException?

FlipkartMedium
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.
2602

What is Postman and how do you automate with it?

FlipkartMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
2603

What is the difference between hard and soft assertions?

FlipkartMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2604

How do you run JavaScript in Selenium?

FlipkartMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
2605

What are the Actions class use cases?

PhonePeMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2606

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

PhonePeMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2607

How do you scroll a page in Selenium?

PhonePeMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
2608

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
2609

How do you handle alerts and pop-ups?

PhonePeMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
2610

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2611

What are try-with-resources and why use them?

PhonePeMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
2612

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2613

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2614

How do you integrate Selenium tests with Jenkins?

PhonePeMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
2615

What are access modifiers in Java?

PhonePeMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
2616

What is method overriding and where is it useful in frameworks?

PhonePeMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
2617

What does dependsOnMethods do?

PhonePeMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
2618

What new features came with Selenium 4?

PhonePeMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2619

How do you switch between windows and tabs?

PhonePeMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2620

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
2621

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2622

What is the difference between Comparable and Comparator in Java?

PhonePeMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
2623

What is a DataProvider in TestNG?

PhonePeMedium
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.
2624

How do you handle dynamic elements whose ids change?

PhonePeMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
2625

How does the DataProvider annotation work?

PhonePeMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
2626

How do you group tests?

PhonePeMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
2627

What are listeners in TestNG?

PhonePeMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
2628

How do you pass authentication in an API test?

PhonePeMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2629

Where do you use OOP concepts in your framework?

PhonePeMedium
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.
2630

How do you test an API that depends on another service that is down?

PhonePeMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
2631

How do you handle multiple windows?

PhonePeMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
2632

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2633

How do you manage test data in a framework?

PhonePeMedium
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.
2634

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
2635

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
2636

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
2637

What are the different types of waits in Selenium?

PhonePeMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2638

Which reporting tools do you use?

PhonePeMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2639

Difference between ArrayList and LinkedList?

PhonePeMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
2640

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
2641

How do you run JavaScript in Selenium?

PhonePeMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
2642

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
2643

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2644

What are the advantages of version control for test code?

PhonePeMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
2645

What is the difference between throw and throws?

PhonePeMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
2646

What is the difference between SOAP and REST?

PhonePeMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
2647

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
2648

How do you scroll a page in Selenium?

MeeshoMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
2649

What new features came with Selenium 4?

MeeshoMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2650

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

MeeshoMedium
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.
2651

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
2652

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
2653

What is the difference between hard and soft assertions?

MeeshoMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2654

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2655

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
2656

What is PageFactory?

MeeshoMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
2657

What is data-driven testing?

MeeshoMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2658

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
2659

How do you group tests?

MeeshoMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
2660

What is a DataProvider in TestNG?

MeeshoMedium
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.
2661

What is BDD and how does Cucumber work?

MeeshoMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
2662

What is method overriding and where is it useful in frameworks?

MeeshoMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
2663

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
2664

Write a GET test in REST Assured.

MeeshoMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
2665

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

MeeshoMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
2666

How do you handle a web table in Selenium?

MeeshoMedium
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.
2667

What are the advantages of version control for test code?

CREDMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
2668

What are listeners in TestNG?

CREDMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
2669

What is PageFactory?

CREDMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
2670

What is the Page Object Model?

CREDEasy
Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2671

How do you handle a website that uses CAPTCHA?

CREDHard
Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
2672

How do you handle iframes?

CREDMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
2673

Difference between an abstract class and an interface?

CREDEasy
Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
2674

How do you calculate automation ROI?

CREDHard
Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2675

Method overloading vs overriding?

CREDEasy
Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
2676

What is the use of Maven in automation projects?

CREDMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
2677

What is the difference between throw and throws?

CREDMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
2678

How do you handle a dropdown that is not a <select> tag?

CREDMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
2679

How would you automate a login flow with multiple user roles?

CREDHard
Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2680

What is the difference between static and non-static members?

CREDMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
2681

What is a Jenkins pipeline?

CREDMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2682

What is a constructor and can it be overloaded?

CREDMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
2683

What are Java 8 streams and lambdas?

CREDMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
2684

What are wrapper classes in Java?

CREDEasy
Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2685

findElement vs findElements?

CREDEasy
Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
2686

What is Postman and how do you automate with it?

CREDMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
2687

How do you test an API that depends on another service that is down?

CREDMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
2688

What is the execution order of TestNG annotations?

CREDEasy
Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
2689

What is an API and what are common HTTP methods?

CREDEasy
Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
2690

What are the main OOP concepts in Java?

CREDEasy
Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2691

How does the DataProvider annotation work?

CREDMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
2692

What is the difference between @BeforeTest and @BeforeMethod?

CREDMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
2693

What is Selenium and what are its components?

CREDEasy
Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
2694

What locators does Selenium support?

CREDEasy
Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
2695

What new features came with Selenium 4?

CREDMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2696

How do you handle StaleElementReferenceException?

CREDMedium
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.
2697

How do you handle environment-specific configuration?

CREDMedium
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.
2698

POST vs PUT vs PATCH?

CREDMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
2699

How would you design a CI pipeline for nightly regression?

CREDHard
Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2700

How do you group tests?

CREDMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
2701

How do you run tests in parallel?

CREDMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
2702

How do you pass authentication in an API test?

CREDMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2703

String vs StringBuilder?

CREDEasy
Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2704

What is Selenium Grid and why use it?

CREDMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
2705

What is the purpose of testng.xml?

CREDEasy
Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2706

Implicit vs explicit vs fluent wait?

CREDEasy
Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
2707

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

CREDEasy
Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
2708

How do you take a screenshot on failure in TestNG?

CREDMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
2709

What are the Actions class use cases?

CREDMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2710

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

CREDMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
2711

Tests pass locally but fail on Jenkins. Why?

CREDHard
Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
2712

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

CREDMedium
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.
2713

What is WebDriver and how does it communicate with the browser?

CREDEasy
Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
2714

How would you design an automation framework from scratch?

CREDHard
Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2715

How does HashMap work internally?

CREDMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
2716

How do you pass parameters from testng.xml?

CREDMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2717

What is the difference between Comparable and Comparator in Java?

CREDMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
2718

What is data-driven testing?

CREDMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2719

How do you handle alerts and pop-ups?

CREDMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
2720

What are Java collections and which ones do testers use most?

CREDMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
2721

What are access modifiers in Java?

CREDMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
2722

How do you scroll a page in Selenium?

CREDMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
2723

How do you retry failed tests in TestNG?

CREDMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
2724

How do you switch between windows and tabs?

CREDMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2725

What is contract testing?

CREDMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
2726

What are Java collections and which ones do testers use most?

RazorpayMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
2727

What is a webhook and how do you test it?

RazorpayMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
2728

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2729

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2730

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2731

How do you test an API that depends on another service that is down?

RazorpayMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
2732

How do you pass authentication in an API test?

RazorpayMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2733

What is PageFactory?

RazorpayMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
2734

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
2735

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
2736

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
2737

How do you pass parameters from testng.xml?

RazorpayMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2738

What is the Hybrid framework?

RazorpayMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
2739

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
2740

What is the difference between driver.close() and driver.quit()?

RazorpayMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2741

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2742

What are the advantages of version control for test code?

RazorpayMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
2743

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
2744

How do you manage test data in a framework?

RazorpayMedium
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.
2745

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
2746

What is Docker and how does it help tests?

RazorpayMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
2747

What is the difference between hard and soft assertions?

RazorpayMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2748

What is the difference between static and non-static members?

RazorpayMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
2749

What is OAuth 2.0 in API testing?

RazorpayMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2750

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2751

Difference between ArrayList and LinkedList?

RazorpayMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
2752

How do you handle alerts and pop-ups?

RazorpayMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
2753

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2754

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
2755

Where do you use OOP concepts in your framework?

RazorpayMedium
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.
2756

What new features came with Selenium 4?

RazorpayMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2757

How do you group tests?

RazorpayMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
2758

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

RazorpayMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2759

What are listeners in TestNG?

RazorpayMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
2760

What is the difference between an array and an ArrayList?

RazorpayMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
2761

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

RazorpayMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
2762

How do you scroll a page in Selenium?

RazorpayMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
2763

What is contract testing?

RazorpayMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
2764

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2765

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
2766

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
2767

What is REST Assured?

RazorpayMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
2768

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

RazorpayMedium
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.
2769

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
2770

What is the use of Maven in automation projects?

RazorpayMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
2771

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
2772

How does the DataProvider annotation work?

RazorpayMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
2773

How do you handle a web table in Selenium?

RazorpayMedium
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.
2774

How do you switch between windows and tabs?

RazorpayMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2775

How do you handle iframes?

RazorpayMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
2776

What are the different types of waits in Selenium?

RazorpayMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2777

Write a GET test in REST Assured.

RazorpayMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
2778

How do you handle dynamic elements whose ids change?

RazorpayMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
2779

How do you run JavaScript in Selenium?

RazorpayMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
2780

How do you handle StaleElementReferenceException?

RazorpayMedium
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.
2781

What is method overriding and where is it useful in frameworks?

RazorpayMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
2782

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
2783

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2784

What is Postman and how do you automate with it?

ZomatoMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
2785

What are try-with-resources and why use them?

ZomatoMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
2786

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
2787

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

ZomatoMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
2788

How do you handle dropdowns in Selenium?

ZomatoMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
2789

What are the Actions class use cases?

ZomatoMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2790

POST vs PUT vs PATCH?

ZomatoMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
2791

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
2792

What is the difference between throw and throws?

ZomatoMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
2793

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2794

How do you validate a JSON response in REST Assured?

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

How do you take a screenshot on failure in TestNG?

ZomatoMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
2796

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2797

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2798

How do you integrate Selenium tests with Jenkins?

ZomatoMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
2799

What is polymorphism and how does it show up in Selenium?

ZomatoMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
2800

How do you run JavaScript in Selenium?

ZomatoMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
2801

What is REST Assured?

ZomatoMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
2802

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2803

How do you handle a dropdown that is not a <select> tag?

ZomatoMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
2804

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

ZomatoMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
2805

Where do you use OOP concepts in your framework?

ZomatoMedium
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.
2806

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
2807

What is a Jenkins pipeline?

ZomatoMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2808

How do you handle dynamic elements whose ids change?

ZomatoMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
2809

How do you manage test data in a framework?

ZomatoMedium
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.
2810

What are the different types of waits in Selenium?

ZomatoMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2811

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

ZomatoMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
2812

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
2813

What are relative locators in Selenium 4?

SwiggyMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
2814

What does dependsOnMethods do?

SwiggyMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
2815

How do you validate a JSON response in REST Assured?

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

How do you manage test data in a framework?

SwiggyMedium
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.
2817

What is the difference between hard and soft assertions?

SwiggyMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2818

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2819

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2820

What new features came with Selenium 4?

SwiggyMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2821

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2822

How does HashMap work internally?

SwiggyMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
2823

How do you handle iframes?

SwiggyMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
2824

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
2825

What is a constructor and can it be overloaded?

SwiggyMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
2826

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
2827

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
2828

What is contract testing?

SwiggyMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
2829

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
2830

What is the difference between an array and an ArrayList?

SwiggyMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
2831

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2832

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2833

How do you handle a dropdown that is not a <select> tag?

SwiggyMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
2834

Write a GET test in REST Assured.

SwiggyMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
2835

How do you upload a file with Selenium?

SwiggyMedium
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.
2836

What is a Jenkins pipeline?

SwiggyMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2837

Difference between ArrayList and LinkedList?

SwiggyMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
2838

How do you pass authentication in an API test?

SwiggyMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2839

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

SwiggyMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2840

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

SwiggyMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
2841

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
2842

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
2843

What are Java 8 streams and lambdas?

SwiggyMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
2844

How do you upload a file with Selenium?

ZeptoMedium
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.
2845

What is the difference between SOAP and REST?

ZeptoMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
2846

What is the difference between static and non-static members?

ZeptoMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
2847

How do you retry failed tests in TestNG?

ZeptoMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
2848

What is WebDriver and how does it communicate with the browser?

ZeptoEasy
Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
2849

How do you run tests in parallel?

ZeptoMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
2850

What are exceptions and how do you handle them?

ZeptoEasy
Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2851

Implicit vs explicit vs fluent wait?

ZeptoEasy
Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
2852

How does HashMap work internally?

ZeptoMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
2853

Reverse a string in Java.

ZeptoEasy
Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
2854

What is data-driven testing?

ZeptoMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
2855

Explain your CI/CD pipeline for tests.

ZeptoHard
Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
2856

What are listeners in TestNG?

ZeptoMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
2857

What is Postman and how do you automate with it?

ZeptoMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
2858

What are the different types of waits in Selenium?

ZeptoMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2859

How do you handle environment-specific configuration?

ZeptoMedium
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.
2860

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

ZeptoMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
2861

String vs StringBuilder?

ZeptoEasy
Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2862

What new features came with Selenium 4?

ZeptoMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2863

What is Docker and how does it help tests?

ZeptoMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
2864

How do you test an API that depends on another service that is down?

ZeptoMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
2865

What is contract testing?

ZeptoMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
2866

What is the use of the this and super keywords?

ZeptoMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
2867

How do you pass authentication in an API test?

ZeptoMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
2868

What is the Hybrid framework?

ZeptoMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
2869

What is REST Assured?

ZeptoMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
2870

Write an XPath for a button with the text "Login".

ZeptoEasy
Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2871

How do you take a screenshot on failure in TestNG?

ZeptoMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
2872

How do you reduce flakiness in a CI pipeline?

ZeptoHard
Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
2873

What is the difference between an array and an ArrayList?

ZeptoMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
2874

How would you automate a login flow with multiple user roles?

ZeptoHard
Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2875

What does dependsOnMethods do?

ZeptoMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
2876

How do you group tests?

ZeptoMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
2877

What are access modifiers in Java?

ZeptoMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
2878

What is the purpose of testng.xml?

ZeptoEasy
Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2879

What is the difference between Comparable and Comparator in Java?

ZeptoMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
2880

How do you handle a web table in Selenium?

ZeptoMedium
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.
2881

Method overloading vs overriding?

ZeptoEasy
Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
2882

How would you design an automation framework from scratch?

ZeptoHard
Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2883

What is the difference between driver.close() and driver.quit()?

ZeptoMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2884

What is a webhook and how do you test it?

ZeptoMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
2885

What is OAuth 2.0 in API testing?

ZeptoMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2886

What is BDD and how does Cucumber work?

ZeptoMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
2887

How do you integrate Selenium tests with Jenkins?

ZeptoMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
2888

How do you run JavaScript in Selenium?

ZeptoMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
2889

How would you design a CI pipeline for nightly regression?

ZeptoHard
Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
2890

What are the main OOP concepts in Java?

ZeptoEasy
Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2891

How do you switch between windows and tabs?

ZeptoMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2892

How do you handle dynamic elements whose ids change?

ZeptoMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
2893

What locators does Selenium support?

ZeptoEasy
Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
2894

What is a Jenkins pipeline?

ZeptoMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2895

What is a constructor and can it be overloaded?

ZeptoMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
2896

What is the difference between @BeforeTest and @BeforeMethod?

ZeptoMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
2897

List common TestNG annotations and their order.

ZeptoEasy
Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
2898

How do you manage test data in a framework?

ZeptoMedium
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.
2899

What is a DataProvider in TestNG?

ZeptoMedium
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.
2900

How do you handle a website that uses CAPTCHA?

ZeptoHard
Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
2901

How do you handle alerts and pop-ups?

ZeptoMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
2902

What is TestNG and why is it used with Selenium?

ZeptoEasy
Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
2903

How do you calculate automation ROI?

ZeptoHard
Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2904

What are the advantages of version control for test code?

ZeptoMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
2905

What is the difference between getText() and getAttribute()?

ZeptoMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
2906

What is polymorphism and how does it show up in Selenium?

ZeptoMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
2907

How does the DataProvider annotation work?

ZeptoMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
2908

What are try-with-resources and why use them?

ZeptoMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
2909

Which reporting tools do you use?

ZeptoMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2910

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

ZeptoEasy
Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
2911

What is the Page Object Model?

ZeptoEasy
Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2912

POST vs PUT vs PATCH?

ZeptoMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
2913

What are Java 8 streams and lambdas?

ZeptoMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
2914

How do you handle multiple windows?

ZeptoMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
2915

What are the Actions class use cases?

ZeptoMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2916

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

ZeptoMedium
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.
2917

How do you switch between windows and tabs?

PaytmMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
2918

What is Docker and how does it help tests?

PaytmMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
2919

Which reporting tools do you use?

PaytmMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2920

What is PageFactory?

PaytmMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
2921

How do you test an API that depends on another service that is down?

PaytmMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
2922

findElement vs findElements?

PaytmEasy
Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
2923

How do you pass parameters from testng.xml?

PaytmMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
2924

What is contract testing?

PaytmMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
2925

Where do you use OOP concepts in your framework?

PaytmMedium
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.
2926

What is the purpose of testng.xml?

PaytmEasy
Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
2927

String vs StringBuilder?

PaytmEasy
Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
2928

How do you group tests?

PaytmMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
2929

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

PaytmMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
2930

Difference between an abstract class and an interface?

PaytmEasy
Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
2931

Common HTTP status codes?

PaytmEasy
Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
2932

What new features came with Selenium 4?

PaytmMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
2933

What is BDD and how does Cucumber work?

PaytmMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
2934

What are access modifiers in Java?

PaytmMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
2935

What is polymorphism and how does it show up in Selenium?

PaytmMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
2936

What are relative locators in Selenium 4?

PaytmMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
2937

What is the Page Object Model?

PaytmEasy
Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
2938

How do you integrate Selenium tests with Jenkins?

PaytmMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
2939

What is Selenium and what are its components?

PaytmEasy
Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
2940

How do you calculate automation ROI?

PaytmHard
Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
2941

What is a constructor and can it be overloaded?

PaytmMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
2942

How do you handle dynamic elements whose ids change?

PaytmMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
2943

What are exceptions and how do you handle them?

PaytmEasy
Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
2944

What is the difference between == and equals() in Java?

PaytmEasy
Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
2945

What is a Jenkins pipeline?

PaytmMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
2946

How do you manage test data in a framework?

PaytmMedium
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.
2947

How do you take a screenshot on failure in TestNG?

PaytmMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
2948

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

PaytmMedium
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.
2949

What are the different types of waits in Selenium?

PaytmMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
2950

How do you handle dropdowns in Selenium?

PaytmMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
2951

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

PaytmMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
2952

How do you reduce flakiness in a CI pipeline?

PaytmHard
Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
2953

What is REST Assured?

PaytmMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
2954

What is the difference between throw and throws?

PaytmMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
2955

What are the advantages of version control for test code?

PaytmMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
2956

What is the difference between Comparable and Comparator in Java?

PaytmMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
2957

How do you decide what to automate?

PaytmHard
Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
2958

How do you handle a dropdown that is not a <select> tag?

PaytmMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
2959

What is JSON and how is it used in API testing?

PaytmEasy
Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
2960

What are the Actions class use cases?

PaytmMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
2961

How does HashMap work internally?

PaytmMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
2962

What are wrapper classes in Java?

PaytmEasy
Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
2963

What is the execution order of TestNG annotations?

PaytmEasy
Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
2964

What is the difference between an array and an ArrayList?

PaytmMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
2965

What are try-with-resources and why use them?

PaytmMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
2966

What is TestNG and why is it used with Selenium?

PaytmEasy
Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
2967

What are Java 8 streams and lambdas?

PaytmMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
2968

How would you automate a login flow with multiple user roles?

PaytmHard
Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2969

What is the difference between static and non-static members?

PaytmMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
2970

How do you handle a web table in Selenium?

PaytmMedium
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.
2971

What is OAuth 2.0 in API testing?

PaytmMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
2972

What are the main OOP concepts in Java?

PaytmEasy
Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
2973

Tests pass locally but fail on Jenkins. Why?

PaytmHard
Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
2974

Write an XPath for a button with the text "Login".

PaytmEasy
Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2975

Difference between absolute and relative XPath?

PaytmMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
2976

What are Java collections and which ones do testers use most?

PaytmMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
2977

What is Selenium Grid and why use it?

PaytmMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
2978

How does the DataProvider annotation work?

PaytmMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
2979

What is the difference between hard and soft assertions?

PaytmMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
2980

How do you upload a file with Selenium?

PaytmMedium
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.
2981

What is the difference between driver.close() and driver.quit()?

PaytmMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
2982

Write a GET test in REST Assured.

PaytmMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
2983

How do you handle alerts and pop-ups?

PaytmMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
2984

Difference between ArrayList and LinkedList?

PaytmMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
2985

How do you retry failed tests in TestNG?

PaytmMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
2986

What are listeners in TestNG?

PaytmMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
2987

ArrayList vs HashMap — how do you use them in a framework?

PaytmEasy
Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
2988

How do you handle a website that uses CAPTCHA?

PaytmHard
Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
2989

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
2990

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
2991

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
2992

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
2993

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
2994

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
2995

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
2996

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
2997

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
2998

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
2999

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
3000

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
3001

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
3002

How do you group tests?

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

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
3004

Where do you use OOP concepts in your framework?

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.
3005

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
3006

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
3007

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
3008

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
3009

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
3010

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
3011

What is a DataProvider in TestNG?

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.
3012

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
3013

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
3014

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
3015

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
3016

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
3017

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
3018

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

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.
3019

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
3020

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
3021

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
3022

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
3023

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
3024

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
3025

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
3026

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
3027

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
3028

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
3029

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3030

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
3031

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
3032

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
3033

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
3034

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
3035

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
3036

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
3037

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
3038

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
3039

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
3040

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
3041

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
3042

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
3043

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
3044

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
3045

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
3046

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
3047

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
3048

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
3049

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
3050

How do you handle StaleElementReferenceException?

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.
3051

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
3052

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
3053

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
3054

How do you take a screenshot on failure in TestNG?

IntuitMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
3055

How do you handle a dropdown that is not a <select> tag?

IntuitMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
3056

What is a webhook and how do you test it?

IntuitMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
3057

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
3058

How do you integrate Selenium tests with Jenkins?

IntuitMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
3059

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
3060

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
3061

How do you handle dropdowns in Selenium?

IntuitMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
3062

How does the DataProvider annotation work?

IntuitMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
3063

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
3064

How do you pass parameters from testng.xml?

IntuitMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
3065

How do you handle environment-specific configuration?

IntuitMedium
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.
3066

What is Selenium Grid and why use it?

IntuitMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
3067

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
3068

What are relative locators in Selenium 4?

IntuitMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
3069

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

IntuitMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
3070

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

IntuitMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
3071

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
3072

How do you handle StaleElementReferenceException?

IntuitMedium
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.
3073

How do you pass authentication in an API test?

IntuitMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
3074

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
3075

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
3076

What is the Hybrid framework?

IntuitMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
3077

What new features came with Selenium 4?

IntuitMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
3078

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
3079

What are Java collections and which ones do testers use most?

IntuitMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
3080

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
3081

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

IntuitMedium
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.
3082

How do you switch between windows and tabs?

IntuitMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
3083

How do you run tests in parallel?

IntuitMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
3084

What is the difference between Comparable and Comparator in Java?

IntuitMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
3085

What are Java 8 streams and lambdas?

IntuitMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
3086

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3087

What is the difference between throw and throws?

IntuitMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
3088

What is Postman and how do you automate with it?

IntuitMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
3089

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
3090

What are the Actions class use cases?

IntuitMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
3091

How do you handle dynamic elements whose ids change?

IntuitMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
3092

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
3093

How do you validate a JSON response in REST Assured?

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

What does dependsOnMethods do?

IntuitMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
3095

What is the difference between static and non-static members?

IntuitMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
3096

What are the different types of waits in Selenium?

IntuitMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
3097

What are the advantages of version control for test code?

IntuitMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
3098

What is the difference between @BeforeTest and @BeforeMethod?

IntuitMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
3099

Difference between absolute and relative XPath?

IntuitMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
3100

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

IntuitMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
3101

How do you group tests?

IntuitMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
3102

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
3103

POST vs PUT vs PATCH?

IntuitMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
3104

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
3105

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
3106

What is the difference between an array and an ArrayList?

IntuitMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
3107

What is Docker and how does it help tests?

IntuitMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
3108

How do you manage test data in a framework?

IntuitMedium
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.
3109

How do you handle StaleElementReferenceException?

WalmartMedium
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.
3110

POST vs PUT vs PATCH?

WalmartMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
3111

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

WalmartMedium
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.
3112

Where do you use OOP concepts in your framework?

WalmartMedium
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.
3113

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
3114

What is Selenium Grid and why use it?

WalmartMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
3115

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
3116

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
3117

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

WalmartMedium
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.
3118

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
3119

How do you run JavaScript in Selenium?

WalmartMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
3120

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
3121

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
3122

What is contract testing?

WalmartMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
3123

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
3124

How do you test an API that depends on another service that is down?

WalmartMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
3125

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
3126

What is OAuth 2.0 in API testing?

WalmartMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
3127

What are access modifiers in Java?

WalmartMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
3128

What is the difference between Comparable and Comparator in Java?

WalmartMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
3129

How do you handle environment-specific configuration?

WalmartMedium
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.
3130

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
3131

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
3132

How do you pass authentication in an API test?

WalmartMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
3133

How do you handle alerts and pop-ups?

WalmartMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
3134

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3135

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
3136

What is a constructor and can it be overloaded?

WalmartMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
3137

What is a Jenkins pipeline?

WalmartMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
3138

What is the difference between an array and an ArrayList?

WalmartMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
3139

What is the difference between SOAP and REST?

WalmartMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
3140

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
3141

Difference between ArrayList and LinkedList?

WalmartMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
3142

What are the different types of waits in Selenium?

WalmartMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
3143

What is the difference between throw and throws?

WalmartMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
3144

What is the Hybrid framework?

WalmartMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
3145

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
3146

What is the use of the this and super keywords?

WalmartMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
3147

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
3148

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
3149

What is data-driven testing?

WalmartMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
3150

What are Java 8 streams and lambdas?

WalmartMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
3151

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
3152

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
3153

What is BDD and how does Cucumber work?

WalmartMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
3154

How does HashMap work internally?

WalmartMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
3155

What does dependsOnMethods do?

WalmartMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
3156

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
3157

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

WalmartMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
3158

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
3159

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
3160

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
3161

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
3162

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
3163

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
3164

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
3165

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
3166

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
3167

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
3168

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
3169

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
3170

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
3171

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
3172

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
3173

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
3174

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3175

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
3176

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
3177

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
3178

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
3179

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
3180

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
3181

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
3182

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
3183

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
3184

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
3185

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
3186

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
3187

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
3188

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
3189

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
3190

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
3191

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
3192

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
3193

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
3194

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
3195

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
3196

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
3197

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
3198

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
3199

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
3200

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
3201

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
3202

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
3203

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
3204

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
3205

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
3206

How do you handle a web table in Selenium?

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.
3207

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
3208

Where do you use OOP concepts in your framework?

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.
3209

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
3210

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
3211

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
3212

How do you handle environment-specific configuration?

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.
3213

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
3214

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
3215

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
3216

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
3217

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
3218

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
3219

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
3220

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
3221

Where do you use OOP concepts in your framework?

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.
3222

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
3223

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
3224

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
3225

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
3226

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
3227

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
3228

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
3229

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
3230

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

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.
3231

How do you handle a web table in Selenium?

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.
3232

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
3233

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
3234

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
3235

How do you upload a file with Selenium?

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.
3236

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
3237

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
3238

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
3239

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
3240

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
3241

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
3242

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
3243

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
3244

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
3245

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
3246

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
3247

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
3248

How do you handle alerts and pop-ups?

Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
3249

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
3250

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
3251

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
3252

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
3253

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
3254

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
3255

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
3256

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
3257

How do you group tests?

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

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
3259

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
3260

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
3261

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
3262

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
3263

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
3264

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
3265

How do you handle StaleElementReferenceException?

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.
3266

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
3267

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
3268

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
3269

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
3270

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
3271

What is a DataProvider in TestNG?

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.
3272

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
3273

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
3274

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
3275

What is method overriding and where is it useful in frameworks?

Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
3276

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
3277

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
3278

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
3279

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
3280

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
3281

How do you handle a web table in Selenium?

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.
3282

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
3283

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
3284

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
3285

What is PageFactory?

Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
3286

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
3287

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
3288

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
3289

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
3290

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
3291

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
3292

What is polymorphism and how does it show up in Selenium?

Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
3293

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
3294

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
3295

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
3296

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
3297

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
3298

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
3299

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
3300

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
3301

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
3302

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
3303

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
3304

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
3305

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
3306

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
3307

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
3308

How do you manage test data in a framework?

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.
3309

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
3310

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
3311

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
3312

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
3313

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
3314

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
3315

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
3316

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
3317

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
3318

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
3319

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
3320

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
3321

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
3322

What are access modifiers in Java?

Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
3323

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
3324

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
3325

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
3326

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
3327

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
3328

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
3329

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
3330

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
3331

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
3332

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
3333

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
3334

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
3335

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
3336

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
3337

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
3338

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
3339

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

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.
3340

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
3341

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
3342

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3343

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
3344

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
3345

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
3346

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
3347

Where do you use OOP concepts in your framework?

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.
3348

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
3349

What is the use of the this and super keywords?

Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
3350

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
3351

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
3352

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
3353

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
3354

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
3355

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
3356

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
3357

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
3358

How does the DataProvider annotation work?

Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
3359

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
3360

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
3361

How does HashMap work internally?

OracleMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
3362

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
3363

How do you handle dynamic elements whose ids change?

OracleMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
3364

How do you integrate Selenium tests with Jenkins?

OracleMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
3365

What is Docker and how does it help tests?

OracleMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
3366

What are access modifiers in Java?

OracleMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
3367

Difference between ArrayList and LinkedList?

OracleMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
3368

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

OracleMedium
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.
3369

How do you upload a file with Selenium?

OracleMedium
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.
3370

How do you reduce flakiness in a CI pipeline?

Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
3371

What is a constructor and can it be overloaded?

OracleMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
3372

How do you group tests?

OracleMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
3373

What does dependsOnMethods do?

OracleMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
3374

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
3375

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
3376

What is the difference between hard and soft assertions?

OracleMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
3377

How do you pass authentication in an API test?

OracleMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
3378

POST vs PUT vs PATCH?

OracleMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
3379

What is a Jenkins pipeline?

OracleMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
3380

What is the difference between driver.close() and driver.quit()?

OracleMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
3381

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
3382

What is polymorphism and how does it show up in Selenium?

OracleMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
3383

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
3384

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
3385

What is REST Assured?

OracleMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
3386

What are try-with-resources and why use them?

OracleMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
3387

How does the DataProvider annotation work?

OracleMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
3388

Where do you use OOP concepts in your framework?

OracleMedium
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.
3389

What are Java collections and which ones do testers use most?

OracleMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
3390

How do you validate a JSON response in REST Assured?

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

What are Java 8 streams and lambdas?

OracleMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
3392

What are the Actions class use cases?

OracleMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
3393

What is the difference between an array and an ArrayList?

OracleMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
3394

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
3395

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
3396

What is the use of the this and super keywords?

OracleMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
3397

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
3398

What is data-driven testing?

OracleMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
3399

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

OracleMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
3400

Difference between absolute and relative XPath?

OracleMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
3401

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
3402

What is the difference between throw and throws?

OracleMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
3403

How do you run tests in parallel?

OracleMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
3404

How do you pass parameters from testng.xml?

OracleMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
3405

How do you switch between windows and tabs?

OracleMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
3406

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
3407

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
3408

What is the difference between @BeforeTest and @BeforeMethod?

OracleMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
3409

What is the difference between getText() and getAttribute()?

OracleMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
3410

How do you scroll a page in Selenium?

OracleMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
3411

What are the different types of waits in Selenium?

OracleMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
3412

How do you retry failed tests in TestNG?

OracleMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
3413

What is the use of Maven in automation projects?

OracleMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
3414

What new features came with Selenium 4?

OracleMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
3415

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
3416

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
3417

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3418

What is BDD and how does Cucumber work?

OracleMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
3419

What is the difference between SOAP and REST?

OracleMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
3420

What is Postman and how do you automate with it?

OracleMedium
Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
3421

How do you run JavaScript in Selenium?

OracleMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
3422

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
3423

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

CiscoEasy
Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
3424

What are Java collections and which ones do testers use most?

CiscoMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
3425

What is an API and what are common HTTP methods?

CiscoEasy
Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
3426

What is the difference between == and equals() in Java?

CiscoEasy
Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
3427

How do you pass parameters from testng.xml?

CiscoMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
3428

What is the difference between hard and soft assertions?

CiscoMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
3429

What is the Page Object Model?

CiscoEasy
Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
3430

How do you handle multiple windows?

CiscoMedium
Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
3431

How would you design an automation framework from scratch?

CiscoHard
Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
3432

What is the difference between static and non-static members?

CiscoMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
3433

How do you handle dropdowns in Selenium?

CiscoMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
3434

What are try-with-resources and why use them?

CiscoMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
3435

What is BDD and how does Cucumber work?

CiscoMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
3436

What is TestNG and why is it used with Selenium?

CiscoEasy
Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
3437

Common HTTP status codes?

CiscoEasy
Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
3438

What are the different types of waits in Selenium?

CiscoMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
3439

What is OAuth 2.0 in API testing?

CiscoMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
3440

What is Selenium Grid and why use it?

CiscoMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
3441

What is a DataProvider in TestNG?

CiscoMedium
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.
3442

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

CiscoMedium
Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
3443

How do you run JavaScript in Selenium?

CiscoMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
3444

Method overloading vs overriding?

CiscoEasy
Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
3445

What is a constructor and can it be overloaded?

CiscoMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
3446

What is the difference between @BeforeTest and @BeforeMethod?

CiscoMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
3447

How do you handle alerts and pop-ups?

CiscoMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
3448

What are listeners in TestNG?

CiscoMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
3449

How do you switch between windows and tabs?

CiscoMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
3450

How do you test an API that depends on another service that is down?

CiscoMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
3451

What is polymorphism and how does it show up in Selenium?

CiscoMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
3452

What are Java 8 streams and lambdas?

CiscoMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
3453

Write an XPath for a button with the text "Login".

CiscoEasy
Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
3454

What are the advantages of version control for test code?

CiscoMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
3455

How do you group tests?

CiscoMedium
Save to ▾
Show answer
Tag tests with groups = {"smoke","regression"} and include or exclude them in testng.xml to run chosen sets.
3456

What is the difference between driver.close() and driver.quit()?

CiscoMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
3457

What is the execution order of TestNG annotations?

CiscoEasy
Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
3458

Difference between final, finally and finalize?

CiscoEasy
Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
3459

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

CiscoMedium
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.
3460

What is Docker and how does it help tests?

CiscoMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
3461

What is the difference between SOAP and REST?

CiscoMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
3462

How do you handle a dropdown that is not a <select> tag?

CiscoMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
3463

What is REST Assured?

CiscoMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
3464

What locators does Selenium support?

CiscoEasy
Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
3465

Implicit vs explicit vs fluent wait?

CiscoEasy
Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
3466

ArrayList vs HashMap — how do you use them in a framework?

CiscoEasy
Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
3467

What is the Hybrid framework?

CiscoMedium
Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
3468

What is contract testing?

CiscoMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
3469

What is a webhook and how do you test it?

CiscoMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
3470

How do you handle a web table in Selenium?

CiscoMedium
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.
3471

What is WebDriver and how does it communicate with the browser?

CiscoEasy
Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
3472

How do you run tests in parallel?

CiscoMedium
Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
3473

How would you automate a login flow with multiple user roles?

CiscoHard
Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
3474

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

CiscoMedium
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.
3475

How do you pass authentication in an API test?

CiscoMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
3476

What are the main OOP concepts in Java?

CiscoEasy
Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
3477

What are wrapper classes in Java?

CiscoEasy
Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
3478

How do you upload a file with Selenium?

CiscoMedium
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.
3479

How do you scroll a page in Selenium?

CiscoMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
3480

How do you integrate Selenium tests with Jenkins?

CiscoMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
3481

What is the difference between Comparable and Comparator in Java?

CiscoMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
3482

Tests pass locally but fail on Jenkins. Why?

CiscoHard
Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3483

What are the Actions class use cases?

CiscoMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
3484

What is a Jenkins pipeline?

CiscoMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
3485

Reverse a string in Java.

CiscoEasy
Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
3486

How do you handle StaleElementReferenceException?

CiscoMedium
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.
3487

What is the use of the this and super keywords?

CiscoMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
3488

How do you handle environment-specific configuration?

CiscoMedium
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.
3489

Difference between an abstract class and an interface?

CiscoEasy
Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
3490

findElement vs findElements?

CiscoEasy
Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
3491

How do you take a screenshot on failure in TestNG?

CiscoMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
3492

What is the difference between an array and an ArrayList?

CiscoMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
3493

How do you handle iframes?

CiscoMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
3494

What is the difference between getText() and getAttribute()?

CiscoMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
3495

POST vs PUT vs PATCH?

CiscoMedium
Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
3496

What are exceptions and how do you handle them?

CiscoEasy
Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
3497

How do you scroll a page in Selenium?

VisaMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
3498

What is contract testing?

VisaMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
3499

What are the Actions class use cases?

VisaMedium
Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
3500

How do you run JavaScript in Selenium?

VisaMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
3501

Where do you use OOP concepts in your framework?

VisaMedium
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.
3502

Write a GET test in REST Assured.

VisaMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
3503

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

VisaMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
3504

Difference between absolute and relative XPath?

VisaMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
3505

Implicit vs explicit vs fluent wait?

VisaEasy
Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
3506

Difference between final, finally and finalize?

VisaEasy
Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
3507

What is Docker and how does it help tests?

VisaMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
3508

What is the difference between hard and soft assertions?

VisaMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
3509

How do you integrate Selenium tests with Jenkins?

VisaMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
3510

How do you handle StaleElementReferenceException?

VisaMedium
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.
3511

How do you switch between windows and tabs?

VisaMedium
Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
3512

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

VisaEasy
Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
3513

findElement vs findElements?

VisaEasy
Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
3514

How do you handle iframes?

VisaMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
3515

How do you handle a web table in Selenium?

VisaMedium
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.
3516

What is data-driven testing?

VisaMedium
Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
3517

What is the use of the this and super keywords?

VisaMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
3518

What is the difference between @BeforeTest and @BeforeMethod?

VisaMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
3519

What is the difference between == and equals() in Java?

VisaEasy
Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
3520

What does dependsOnMethods do?

VisaMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
3521

What are Java collections and which ones do testers use most?

VisaMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
3522

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

VisaMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
3523

How do you take a screenshot on failure in TestNG?

VisaMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
3524

What are the different types of waits in Selenium?

VisaMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
3525

How would you automate a login flow with multiple user roles?

VisaHard
Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
3526

How would you design an automation framework from scratch?

VisaHard
Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
3527

What is the execution order of TestNG annotations?

VisaEasy
Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
3528

How do you reduce flakiness in a CI pipeline?

VisaHard
Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
3529

What is the use of Maven in automation projects?

VisaMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
3530

What is a constructor and can it be overloaded?

VisaMedium
Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
3531

What are the advantages of version control for test code?

VisaMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
3532

How do you validate a JSON response in REST Assured?

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

Explain your CI/CD pipeline for tests.

VisaHard
Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
3534

How do you handle alerts and pop-ups?

VisaMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
3535

How does HashMap work internally?

VisaMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
3536

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

VisaMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
3537

What is the Page Object Model?

VisaEasy
Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
3538

What are try-with-resources and why use them?

VisaMedium
Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
3539

String vs StringBuilder?

VisaEasy
Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
3540

Tests pass locally but fail on Jenkins. Why?

VisaHard
Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3541

What are access modifiers in Java?

VisaMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
3542

What is an API and what are common HTTP methods?

VisaEasy
Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
3543

Difference between an abstract class and an interface?

VisaEasy
Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
3544

What are listeners in TestNG?

VisaMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
3545

How do you test an API that depends on another service that is down?

VisaMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
3546

How do you upload a file with Selenium?

VisaMedium
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.
3547

What are relative locators in Selenium 4?

VisaMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
3548

How do you decide what to automate?

VisaHard
Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
3549

What are the main OOP concepts in Java?

VisaEasy
Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
3550

What are exceptions and how do you handle them?

VisaEasy
Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
3551

What is the difference between getText() and getAttribute()?

VisaMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
3552

Method overloading vs overriding?

VisaEasy
Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
3553

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
3554

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
3555

What is the difference between driver.close() and driver.quit()?

Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
3556

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

Save to ▾
Show answer
Use then().time(lessThan(2000L)) and then().header("Content-Type", containsString("json")) along with body assertions.
3557

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
3558

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
3559

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
3560

What is REST Assured?

Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
3561

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
3562

How do you retry failed tests in TestNG?

Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
3563

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
3564

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
3565

What is the difference between getText() and getAttribute()?

Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
3566

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
3567

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
3568

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
3569

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
3570

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
3571

What is OAuth 2.0 in API testing?

Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
3572

What is contract testing?

Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
3573

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
3574

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
3575

How do you group tests?

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

Which reporting tools do you use?

Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
3577

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
3578

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
3579

How do you handle StaleElementReferenceException?

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.
3580

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
3581

What is a webhook and how do you test it?

Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
3582

findElement vs findElements?

Save to ▾
Show answer
findElement returns the first match and throws NoSuchElementException if nothing is found. findElements returns a List (empty if nothing is found) — handy to check whether an element exists.
3583

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
3584

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
3585

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
3586

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
3587

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
3588

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
3589

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
3590

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
3591

How do you pass parameters from testng.xml?

Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
3592

Write a GET test in REST Assured.

Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
3593

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
3594

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
3595

What is BDD and how does Cucumber work?

Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
3596

What is a Jenkins pipeline?

Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
3597

What is a DataProvider in TestNG?

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.
3598

What is the difference between Comparable and Comparator in Java?

Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
3599

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3600

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
3601

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
3602

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

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.
3603

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
3604

What do HTTP status codes 200, 201, 400, 401, 403, 404 and 500 mean?

Save to ▾
Show answer
200 OK, 201 Created, 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found and 500 server error.
3605

ArrayList vs HashMap — how do you use them in a framework?

Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
3606

What are exceptions and how do you handle them?

Save to ▾
Show answer
Runtime events that disrupt flow. Use try-catch-finally, throw, throws, and custom exceptions; checked exceptions must be handled while unchecked ones need not be.
3607

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
3608

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
3609

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
3610

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
3611

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
3612

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
3613

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
3614

How do you handle environment-specific configuration?

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.
3615

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
3616

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
3617

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
3618

How do you upload a file with Selenium?

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.
3619

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
3620

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
3621

What are the advantages of version control for test code?

BarclaysMedium
Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
3622

What is OAuth 2.0 in API testing?

BarclaysMedium
Save to ▾
Show answer
An authorisation framework where a client obtains an access token from an auth server and sends it as a Bearer token; tests fetch and reuse the token in setup.
3623

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
3624

Write a GET test in REST Assured.

BarclaysMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
3625

What are access modifiers in Java?

BarclaysMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
3626

What new features came with Selenium 4?

BarclaysMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
3627

How do you retry failed tests in TestNG?

BarclaysMedium
Save to ▾
Show answer
Implement IRetryAnalyzer with a retry count and attach it through the test annotation or a listener to rerun flaky tests.
3628

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

BarclaysMedium
Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
3629

What is the difference between driver.close() and driver.quit()?

BarclaysMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
3630

How do you take a screenshot on failure in TestNG?

BarclaysMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
3631

Where do you use OOP concepts in your framework?

BarclaysMedium
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.
3632

What is BDD and how does Cucumber work?

BarclaysMedium
Save to ▾
Show answer
Behaviour-driven development writes scenarios in Given-When-Then Gherkin that map to step definitions in code, so business and QA share one language.
3633

How do you handle StaleElementReferenceException?

BarclaysMedium
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.
3634

How do you handle dynamic elements whose ids change?

BarclaysMedium
Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
3635

What is method overriding and where is it useful in frameworks?

BarclaysMedium
Save to ▾
Show answer
A subclass redefines a parent method. Frameworks use it to customise base behaviour, such as overriding a wait or click method in a base page class.
3636

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
3637

Which reporting tools do you use?

BarclaysMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
3638

What is the difference between static and non-static members?

BarclaysMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
3639

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
3640

What is the difference between hard and soft assertions?

BarclaysMedium
Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
3641

How do you pass parameters from testng.xml?

BarclaysMedium
Save to ▾
Show answer
Define parameter name and value in the XML and read them with @Parameters in the test or configuration method.
3642

What are Java 8 streams and lambdas?

BarclaysMedium
Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
3643

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
3644

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
3645

What are relative locators in Selenium 4?

BarclaysMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
3646

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
3647

How would you design a CI pipeline for nightly regression?

Save to ▾
Show answer
Schedule the job, spin up environments or containers, run suites in parallel, store reports and screenshots, notify failures on Slack or email and track trends.
3648

What is the difference between @BeforeTest and @BeforeMethod?

BarclaysMedium
Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
3649

How do you manage test data in a framework?

BarclaysMedium
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.
3650

Reverse a string in Java.

Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
3651

Difference between absolute and relative XPath?

BarclaysMedium
Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].
3652

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

BarclaysMedium
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.
3653

What is REST Assured?

BarclaysMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
3654

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
3655

What is the difference between throw and throws?

BarclaysMedium
Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
3656

What is the difference between an array and an ArrayList?

BarclaysMedium
Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
3657

Common HTTP status codes?

Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
3658

How do you handle a web table in Selenium?

BarclaysMedium
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.
3659

How do you test an API that depends on another service that is down?

BarclaysMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
3660

What is the use of the this and super keywords?

BarclaysMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
3661

What is REST Assured?

HSBCMedium
Save to ▾
Show answer
A Java library that makes API tests readable using given-when-then, with easy request building, response validation and JSON path support.
3662

How do you decide what to automate?

HSBCHard
Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
3663

How do you run JavaScript in Selenium?

HSBCMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
3664

How do you validate a JSON response in REST Assured?

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

Common HTTP status codes?

HSBCEasy
Save to ▾
Show answer
200 OK, 201 Created, 204 No Content, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error.
3666

How do you integrate Selenium tests with Jenkins?

HSBCMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
3667

Which reporting tools do you use?

HSBCMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
3668

What is PageFactory?

HSBCMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
3669

What is the difference between driver.close() and driver.quit()?

HSBCMedium
Save to ▾
Show answer
close() closes the current window; quit() closes all windows and ends the driver session.
3670

How do you handle StaleElementReferenceException?

HSBCMedium
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.
3671

How do you test an API that depends on another service that is down?

HSBCMedium
Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
3672

How do you handle a web table in Selenium?

HSBCMedium
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.
3673

What is contract testing?

HSBCMedium
Save to ▾
Show answer
Verifying that a provider and consumer agree on request and response formats, using tools like Pact, to catch breaking changes early.
3674

ArrayList vs HashMap — how do you use them in a framework?

HSBCEasy
Save to ▾
Show answer
ArrayList stores an ordered list (e.g. all product names on a page). HashMap stores key–value pairs (e.g. test data or config properties).
3675

What is TestNG and why is it used with Selenium?

HSBCEasy
Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
3676

What are relative locators in Selenium 4?

HSBCMedium
Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
3677

Tests pass locally but fail on Jenkins. Why?

HSBCHard
Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3678

How does HashMap work internally?

HSBCMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
3679

What is Docker and how does it help tests?

HSBCMedium
Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
3680

Method overloading vs overriding?

HSBCEasy
Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
3681

What is the difference between SOAP and REST?

HSBCMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
3682

How do you handle dropdowns in Selenium?

HSBCMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
3683

What are access modifiers in Java?

HSBCMedium
Save to ▾
Show answer
public (everywhere), protected (package and subclasses), default (package) and private (same class), used to control visibility of test utilities.
3684

What is the difference between Comparable and Comparator in Java?

HSBCMedium
Save to ▾
Show answer
Comparable defines the natural order inside the class (compareTo); Comparator defines custom orders externally (compare), useful for sorting test data in several ways.
3685

What is a Jenkins pipeline?

HSBCMedium
Save to ▾
Show answer
A scripted or declarative Jenkinsfile that defines stages such as build, test and deploy as code stored with the project.
3686

What does dependsOnMethods do?

HSBCMedium
Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
3687

Write a GET test in REST Assured.

HSBCMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
3688

How do you pass authentication in an API test?

HSBCMedium
Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
3689

Reverse a string in Java.

HSBCEasy
Save to ▾
Show answer
String r = new StringBuilder(s).reverse().toString(); // or loop from the last index and append each character
3690

How do you reduce flakiness in a CI pipeline?

HSBCHard
Save to ▾
Show answer
Stabilise waits and data, isolate tests, use retries cautiously, quarantine unstable tests, run in consistent containers and track flaky rates.
3691

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

HSBCMedium
Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
3692

List common TestNG annotations and their order.

Save to ▾
Show answer
BeforeSuite, BeforeTest, BeforeClass, BeforeMethod, Test, AfterMethod, AfterClass, AfterTest and AfterSuite.
3693

How do you integrate Selenium tests with Jenkins?

HCLTechMedium
Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
3694

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
3695

Where do you use OOP concepts in your framework?

HCLTechMedium
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.
3696

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
3697

How does HashMap work internally?

HCLTechMedium
Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
3698

What is PageFactory?

HCLTechMedium
Save to ▾
Show answer
A helper that initialises @FindBy elements lazily using initElements; some teams skip it in favour of plain By locators.
3699

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
3700

What are the different types of waits in Selenium?

HCLTechMedium
Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
3701

What is polymorphism and how does it show up in Selenium?

HCLTechMedium
Save to ▾
Show answer
One interface, many forms. WebDriver driver = new ChromeDriver() lets the same test code run on any browser class that implements WebDriver.
3702

What is the use of Maven in automation projects?

HCLTechMedium
Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
3703

Explain your CI/CD pipeline for tests.

Save to ▾
Show answer
Code pushed to Git → Jenkins job triggers (webhook or schedule) → mvn clean test with the suite XML → reports and screenshots published → notifications on Slack/email → failures triaged before release.
3704

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
3705

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

HCLTechMedium
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.
3706

How do you run JavaScript in Selenium?

HCLTechMedium
Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
3707

What is Selenium and what are its components?

Save to ▾
Show answer
An open-source suite for browser automation: WebDriver, IDE, Grid and the older RC. WebDriver controls browsers through their native drivers.
3708

How do you handle a dropdown that is not a <select> tag?

HCLTechMedium
Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
3709

How do you take a screenshot on failure in TestNG?

HCLTechMedium
Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
3710

What is a webhook and how do you test it?

HCLTechMedium
Save to ▾
Show answer
A callback where one system sends an HTTP request to another when an event occurs. Test with a mock receiver or tools such as webhook.site and verify the payload.
3711

How do you handle dropdowns in Selenium?

HCLTechMedium
Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
3712

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
3713

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
3714

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
3715

How do you handle iframes?

HCLTechMedium
Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
3716

How do you scroll a page in Selenium?

HCLTechMedium
Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
3717

String vs StringBuilder?

Save to ▾
Show answer
String is immutable — every change creates a new object. StringBuilder is mutable and faster for repeated changes (not thread-safe; StringBuffer is).
3718

What is the difference between getText() and getAttribute()?

HCLTechMedium
Save to ▾
Show answer
getText returns visible inner text; getAttribute returns an HTML attribute or property such as value, href or class.
3719

Which reporting tools do you use?

HCLTechMedium
Save to ▾
Show answer
TestNG reports, ExtentReports and Allure give charts, screenshots and logs that are easy to share with the team.
3720

Tests pass locally but fail on Jenkins. Why?

Save to ▾
Show answer
Headless mode or screen resolution, timing issues, environment data, missing dependencies, browser–driver version mismatch or parallel conflicts. Check logs and failure screenshots and make waits robust.
3721

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

HCLTechMedium
Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
3722

Write a GET test in REST Assured.

HCLTechMedium
Save to ▾
Show answer
given().baseUri(url) .when().get("/users/1") .then().statusCode(200).body("id", equalTo(1));
3723

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
3724

How do you validate a JSON response in REST Assured?

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

How do you handle alerts and pop-ups?

HCLTechMedium
Save to ▾
Show answer
driver.switchTo().alert() lets you accept, dismiss, read text or send keys. Browser windows are handled with window handles.
3726

Difference between ArrayList and LinkedList?

HCLTechMedium
Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
3727

How does the DataProvider annotation work?

HCLTechMedium
Save to ▾
Show answer
A method annotated with @DataProvider returns a 2D object array and the test with dataProvider = "name" runs once per row.
3728

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
3729

What new features came with Selenium 4?

HCLTechMedium
Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
3730

What is the use of the this and super keywords?

HCLTechMedium
Save to ▾
Show answer
this refers to the current object; super refers to the parent class, used to call parent constructors and methods.
3731

What are listeners in TestNG?

HCLTechMedium
Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
3732

What is the difference between static and non-static members?

HCLTechMedium
Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
3733

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
3734

What is Selenium Grid and why use it?

HCLTechMedium
Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
3735

What are Java collections and which ones do testers use most?

HCLTechMedium
Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
3736

What is the difference between SOAP and REST?

HCLTechMedium
Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
3737

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

Save to ▾
Show answer
Continuous Integration builds and tests every commit, and Continuous Delivery ships automatically. Automated tests give fast feedback and gate releases.
3738

What are the main OOP concepts in Java?

Save to ▾
Show answer
Encapsulation, inheritance, polymorphism and abstraction. Testers use them to build reusable page classes, base tests and utility libraries.
3739

What is Docker and how does it help tests?

Save to ▾
Show answer
Docker packages tools in containers so tests run identically everywhere; Selenium Grid and browsers can be started quickly in containers.
3740

How does HashMap work internally?

Save to ▾
Show answer
It uses the key's hashCode to find a bucket and equals to resolve collisions, giving O(1) average lookups; Java 8 converts long buckets into trees.
3741

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

Save to ▾
Show answer
Store each driver in a ThreadLocal so every thread gets its own instance and tests do not interfere.
3742

Difference between final, finally and finalize?

Save to ▾
Show answer
final makes a variable, method or class unchangeable; finally is a block that always runs after try-catch; finalize is a deprecated method called before garbage collection.
3743

What locators does Selenium support?

Save to ▾
Show answer
id, name, className, tagName, linkText, partialLinkText, CSS selector and XPath. Prefer stable ids or CSS, using XPath when needed.
3744

How do you handle a dropdown that is not a <select> tag?

Save to ▾
Show answer
Click to open the dropdown, then locate the option by its text, e.g. //li[text()='India'], and click it. Add an explicit wait for the animation.
3745

What is the difference between static and non-static members?

Save to ▾
Show answer
Static members belong to the class and are shared by all instances; non-static members belong to each object.
3746

What is the use of Maven in automation projects?

Save to ▾
Show answer
It manages dependencies through pom.xml, builds the project, runs tests with Surefire and standardises structure across teams.
3747

How would you automate a login flow with multiple user roles?

Save to ▾
Show answer
Keep credentials in external data, parameterise the test with a data provider, reuse a login method in a page class, and clear sessions between roles.
3748

What is JSON and how is it used in API testing?

Save to ▾
Show answer
A lightweight text format of key-value pairs and arrays used in API requests and responses, validated field by field in tests.
3749

How do you handle StaleElementReferenceException?

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.
3750

How do you handle a website that uses CAPTCHA?

Save to ▾
Show answer
Do not automate it; ask for a test environment where CAPTCHA is disabled or use test keys, or a bypass token agreed with developers.
3751

How do you decide what to automate?

Save to ▾
Show answer
Automate stable, repetitive, high-risk and data-heavy flows (smoke, regression). Skip one-time tests, frequently changing UI and checks needing human judgement. Compare run frequency × manual time with build and maintenance cost.
3752

What is a DataProvider in TestNG?

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.
3753

What is the purpose of testng.xml?

Save to ▾
Show answer
A configuration file to define suites, tests, classes, groups, parameters and parallel execution settings.
3754

What is the Page Object Model?

Save to ▾
Show answer
A design pattern where each page is a class holding its locators and actions, so tests stay readable and a locator change is fixed in one place.
3755

How do you switch between windows and tabs?

Save to ▾
Show answer
Get getWindowHandles(), loop to find the target, and call driver.switchTo().window(handle); switch back using the stored parent handle.
3756

How do you run JavaScript in Selenium?

Save to ▾
Show answer
Cast the driver to JavascriptExecutor and use executeScript, for example to scroll into view or click hidden elements.
3757

What is Selenium Grid and why use it?

Save to ▾
Show answer
It runs tests in parallel across multiple machines and browsers using a hub and nodes, cutting execution time and increasing browser coverage.
3758

What are listeners in TestNG?

Save to ▾
Show answer
Classes like ITestListener that react to events such as test start, success or failure, commonly used for screenshots and reporting.
3759

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

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.
3760

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

Save to ▾
Show answer
Use isDisplayed(), isEnabled() and isSelected() on the WebElement before interacting or asserting.
3761

What does dependsOnMethods do?

Save to ▾
Show answer
It makes a test run only after specified tests pass, otherwise it is skipped. Use sparingly as it creates coupled tests.
3762

How do you handle a web table in Selenium?

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.
3763

What is data-driven testing?

Save to ▾
Show answer
Running the same test logic with multiple data sets from Excel, CSV, JSON or a database, so coverage increases without duplicating code.
3764

What are the different types of waits in Selenium?

Save to ▾
Show answer
Implicit, explicit (WebDriverWait with ExpectedConditions) and fluent waits; avoid mixing implicit and explicit waits and never rely on Thread.sleep.
3765

POST vs PUT vs PATCH?

Save to ▾
Show answer
POST creates a resource, PUT replaces the whole resource (idempotent) and PATCH updates part of it.
3766

How do you take a screenshot on failure in TestNG?

Save to ▾
Show answer
Implement ITestListener.onTestFailure(): File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); then copy it into the reports folder.
3767

How do you upload a file with Selenium?

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.
3768

What is the difference between == and equals() in Java?

Save to ▾
Show answer
== compares references (or primitive values); equals() compares content when overridden, as in String.
3769

How do you integrate Selenium tests with Jenkins?

Save to ▾
Show answer
Create a job or pipeline that checks out code, runs mvn test, publishes reports and triggers on commits or schedules.
3770

Write an XPath for a button with the text "Login".

Save to ▾
Show answer
//button[normalize-space()='Login'] //button[contains(text(),'Login')]
3771

What is the difference between @BeforeTest and @BeforeMethod?

Save to ▾
Show answer
@BeforeTest runs once before all methods in a test tag of testng.xml; @BeforeMethod runs before every test method.
3772

How do you calculate automation ROI?

Save to ▾
Show answer
Compare effort saved by running automated tests repeatedly against the cost of building and maintaining scripts, counting execution time, defects found earlier and release speed.
3773

What is the difference between throw and throws?

Save to ▾
Show answer
throw actually raises an exception object inside a method; throws declares in the method signature that it may pass an exception to the caller.
3774

What is the difference between an array and an ArrayList?

Save to ▾
Show answer
Arrays have a fixed size and can hold primitives; ArrayList grows dynamically, holds objects and offers helper methods.
3775

What are the advantages of version control for test code?

Save to ▾
Show answer
Git tracks changes, enables code review, branching and rollback and lets teams collaborate on the framework safely.
3776

What is an API and what are common HTTP methods?

Save to ▾
Show answer
An interface for systems to talk to each other. GET reads, POST creates, PUT replaces, PATCH updates partially and DELETE removes.
3777

How do you manage test data in a framework?

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.
3778

What is Postman and how do you automate with it?

Save to ▾
Show answer
An API client. Add tests in JavaScript, use environments and collections, and run them with Newman in a CI pipeline.
3779

How do you validate a JSON response in REST Assured?

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

What is TestNG and why is it used with Selenium?

Save to ▾
Show answer
A test framework offering annotations, grouping, prioritisation, parallel runs, data providers and reports, which structure and scale Selenium tests.
3781

What is the difference between hard and soft assertions?

Save to ▾
Show answer
Hard assert stops the test at the first failure; SoftAssert collects failures and reports them together when assertAll() is called.
3782

What is the Hybrid framework?

Save to ▾
Show answer
A framework combining data-driven, keyword-driven and POM approaches with reporting and utilities, giving flexibility and reuse.
3783

What are relative locators in Selenium 4?

Save to ▾
Show answer
Locators such as above, below, toLeftOf and near that find elements by their position relative to another element.
3784

How do you handle dropdowns in Selenium?

Save to ▾
Show answer
Use the Select class with selectByVisibleText, selectByValue or selectByIndex; for custom dropdowns click and choose from the list of elements.
3785

How do you pass authentication in an API test?

Save to ▾
Show answer
Use headers such as Bearer tokens, basic auth, API keys or OAuth flows; fetch a token in a setup step and reuse it.
3786

Implicit vs explicit vs fluent wait?

Save to ▾
Show answer
Implicit wait applies globally to element lookups. Explicit wait waits for a specific condition (WebDriverWait + ExpectedConditions). Fluent wait is an explicit wait with custom polling and ignored exceptions.
3787

How do you run tests in parallel?

Save to ▾
Show answer
Use TestNG parallel="methods | classes | tests" with thread-count, keep WebDriver in a ThreadLocal, and use Selenium Grid or a cloud grid for multiple browsers.
3788

What new features came with Selenium 4?

Save to ▾
Show answer
Relative locators, improved Grid, W3C compliance, new window or tab creation, Chrome DevTools Protocol access and element-level screenshots.
3789

What is a constructor and can it be overloaded?

Save to ▾
Show answer
A special method that initialises an object. It can be overloaded with different parameters, and testers use it to pass the WebDriver into page classes.
3790

What is the difference between SOAP and REST?

Save to ▾
Show answer
SOAP is a strict XML protocol with WSDL and WS-Security; REST is a lighter architectural style using HTTP and usually JSON.
3791

Difference between ArrayList and LinkedList?

Save to ▾
Show answer
ArrayList has fast random access and slower inserts in the middle; LinkedList has fast inserts and deletes but slow access by index.
3792

How do you handle dynamic elements whose ids change?

Save to ▾
Show answer
Use CSS or XPath with contains(), starts-with() or stable attributes, relative axes, or data-test attributes agreed with developers.
3793

What are wrapper classes in Java?

Save to ▾
Show answer
Classes such as Integer and Double that wrap primitive types as objects, needed for collections and for parsing text from web elements.
3794

How do you handle environment-specific configuration?

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.
3795

What is the execution order of TestNG annotations?

Save to ▾
Show answer
@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite.
3796

Method overloading vs overriding?

Save to ▾
Show answer
Overloading: same method name, different parameters, in the same class (compile time). Overriding: a subclass redefines a parent method with the same signature (runtime polymorphism). WebDriver driver = new ChromeDriver() is runtime polymorphism.
3797

How do you test an API that depends on another service that is down?

Save to ▾
Show answer
Use mocks or stubs such as WireMock to simulate the dependency and test your service in isolation.
3798

How would you design an automation framework from scratch?

Save to ▾
Show answer
Maven project → POM with a BasePage → driver factory with ThreadLocal → config files → data-driven utilities (Excel/JSON) → TestNG or Cucumber runner → logging → Extent reports with screenshots on failure → Jenkins pipeline.
3799

How do you scroll a page in Selenium?

Save to ▾
Show answer
Use JavascriptExecutor with window.scrollTo or scrollIntoView, or the Actions class scroll methods in Selenium 4.
3800

What are the Actions class use cases?

Save to ▾
Show answer
Mouse and keyboard actions such as hover, drag and drop, double click, right click and key combinations, built with moveToElement(...).perform().
3801

What are try-with-resources and why use them?

Save to ▾
Show answer
A try block that automatically closes resources such as file readers or streams, preventing leaks without a finally block.
3802

How do you handle iframes?

Save to ▾
Show answer
switchTo().frame(index, name or element) enters the frame, and switchTo().defaultContent() returns to the main page.
3803

How do you handle multiple windows?

Save to ▾
Show answer
String parent = driver.getWindowHandle(); for (String h : driver.getWindowHandles()) if (!h.equals(parent)) driver.switchTo().window(h); // ...then switch back to parent
3804

What are Java collections and which ones do testers use most?

Save to ▾
Show answer
ArrayList and LinkedList for lists, HashSet for unique values, HashMap for key-value test data, and Iterator for traversing them, for example collecting web elements in a list.
3805

What is WebDriver and how does it communicate with the browser?

Save to ▾
Show answer
WebDriver sends commands over HTTP (W3C protocol) to a browser-specific driver such as chromedriver, which controls the actual browser.
3806

What are Java 8 streams and lambdas?

Save to ▾
Show answer
Lambdas are short anonymous functions; streams process collections declaratively with filter, map and collect, for example filtering link text from a list of elements.
3807

Difference between an abstract class and an interface?

Save to ▾
Show answer
An abstract class can hold state and concrete methods; an interface defines a contract (with default methods since Java 8). A class extends one abstract class but can implement many interfaces.
3808

Difference between absolute and relative XPath?

Save to ▾
Show answer
Absolute starts from the root (/html/...) and breaks easily; relative starts anywhere with // and is more stable, for example //input[@id='email'].