Skip to content

Cognizant Automation Testing Interview Questions & Answers

Curated interview practice questions with answers. These are practice scenarios, not a verified list of past interview questions.

Solved for CognizantStart 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

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

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).
03

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

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

What is the execution order of TestNG annotations?

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

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

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

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));
09

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

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

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

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

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

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

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

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

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().
18

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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
67

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.