Interview Question Part - 1
Interview Question Part - 1
For example, if I open Amazon's homepage, the XPath for the search bar can be:
bash
Copy code
//input[@id='twotabsearchtextbox']
I locate the search bar using the id attribute in the HTML. However, if this doesn't work, I
can create a more robust XPath based on its position in the DOM or other attributes like
this:
4. XPath: Powerful but can be slower; used for complex DOM hierarchies.
Yes, I use CSS selectors for faster and more efficient element identification, especially
when the element's ID or Name is not available. For example:
input#username
input[type='text'][name='username']
4. Types of XPath?
1. Absolute XPath: Starts from the root of the HTML DOM tree. Example:
/html/body/div/header/input
• Scenario Outline: This is used when you need to run the same scenario with
different sets of data.
• Abstraction: Using interfaces and abstract classes for better test design and
reusability.
7. Open the online compiler, create a string, enter some words (e.g., "This is a Java
Program"), remove the space, print it, and reverse the string. Explain the program.
• Explanation: First, the program removes all spaces using replaceAll("\\s", "").
Then, it reverses the string using StringBuilder and prints both the space-free and
reversed strings.
8. SDLC Lifecycle.
SDLC stands for Software Development Life Cycle. The stages include:
4. Testing: Testers verify the software to ensure it meets the requirements and is
free of defects.
9. How will you prioritize the methods in TestNG? If two methods have the same
priority, which one will execute first?
In TestNG, you can prioritize methods using the priority attribute in the @Test
annotation. If two methods have the same priority, TestNG will execute them in the
order they appear in the class.
@Test(priority = 2)
• Finally block: To ensure cleanup actions, like closing resources, always run.
1. Alert Handling:
alert.accept(); // for OK
driver.switchTo().window(windowHandle);
4|Inter view Qu estion and A nswer part 1
13. Explain the folder structure of your framework.
The pom.xml file is the configuration file for Maven projects. It contains:
• Plugins: Defines build plugins for tasks like packaging and reporting.
15. Have you ever done cross-browser testing? How do you do that?
Yes, I've done cross-browser testing using Selenium and tools like BrowserStack. In
Selenium, I initialize the WebDriver based on the browser:
if (browser.equals("chrome")) {
} else if (browser.equals("firefox")) {
• Functional Testing
• Regression Testing
• Smoke Testing
• Cross-browser Testing
• Smoke Testing: A quick test to ensure that the basic functionality of the
application is working. It's performed after every build.
Yes, I have created multiple automation frameworks from scratch. I typically use a
combination of:
HashMap in Java is used to store data in key-value pairs. It is particularly useful when
you need fast access to data based on a specific key. In automation projects, I use
HashMap to store test data, configuration properties, or even web element locators. For
example, in a framework, you could store device details for multiple connected devices,
where the key could be the device ID, and the value could be its details (e.g., platform,
version).
Example:
deviceDetails.put("Device1", "Android");
deviceDetails.put("Device2", "iOS");
Java Collections are used to manage groups of objects, and they provide several utility
classes like ArrayList, HashMap, HashSet, LinkedList, etc. In automation projects,
collections are used to manage test data, maintain lists of elements, and manage
configuration or result sets.
Examples:
• HashSet: Used to store unique test data, such as a list of user IDs.
22. How will you ensure all test cases for the Login page have passed?
To ensure all test cases for the Login page have passed:
23. Write a Java program to find the number of occurrences of a specific character
in your name.
int count = 0;
if (name.charAt(i) == specificChar) {
count++;
//div[@id='p-lang']//a
This XPath expression navigates to the sidebar where languages are listed (id='p-lang')
and selects all anchor tags (<a> elements), which typically represent the language links.
Constructors in Java are special methods used to initialize objects. They are called
when an object of a class is created. The primary role of constructors is to set the initial
state of the object or to provide initial values to instance variables.
• Types:
Example:
String username;
int age;
// Parameterized constructor
this.username = username;
this.age = age;
7. How would you swap two values without using a third variable?
a = a + b; // a becomes 15
b = a - b; // b becomes 5
a = a - b; // a becomes 10
1. Page Object Model (POM): Where each page of the application has its own class
with locators and methods to interact with the elements.
2. Properties File: I store element locators in a .properties file and fetch them
during runtime.
login.username = //input[@id='username']
login.password = //input[@id='password']
28. What essential Git commands do you use, and how do you merge code using
Git?
5. git pull: To fetch and merge changes from the remote repository to the local
branch.
• git pull origin master: Pull the latest changes from the remote master branch.
• git merge master: Merge the master branch into the feature branch.
• git push origin feature_branch: Push the merged changes back to the remote
feature branch.
11 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
29. What is Collections in Java?
The Collections framework in Java is a set of classes and interfaces that provide data
structures to store and manipulate groups of objects. It includes interfaces such as
List, Set, Queue, and classes like ArrayList, HashSet, LinkedList, and HashMap. The
framework provides methods to perform operations like searching, sorting, insertion,
manipulation, and deletion of elements.
TestNG provides several types of listeners to listen to different events in the lifecycle of
a test execution. Some key listeners include:
1. String:
2. StringBuffer:
3. StringBuilder:
o Mutable.
12 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
o Not thread-safe (faster than StringBuffer in single-threaded
environments).
REST APIs use status codes to indicate the result of an HTTP request. Some common
codes include:
• 403 Forbidden: The request is valid, but the server is refusing action.
To schedule a job in Jenkins to run at midnight, you use the Build Triggers section and
specify the cron-like syntax. The cron expression for midnight would be:
Copy code
00***
• 0 minutes
• 0 hours (midnight)
34. Write a code to move all zeros to the beginning of this array: {6, 8, 7, 0, 5, 0, 3, 0}.
13 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
int n = arr.length;
int index = n - 1;
if (arr[i] != 0) {
result[index--] = arr[i];
Output: 0 0 0 6 8 7 5 3
1. Syntax:
2. Performance:
3. Typing:
14 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
4. Memory Management:
o Both use garbage collection, but Java provides more control over memory
allocation.
5. Use Cases:
o Python is often used for scripting, data science, and machine learning.
To validate a JSON schema in Java, you can use libraries like json-schema-validator
from everit or com.networknt. Here’s an example using everit:
import org.everit.json.schema.Schema;
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;
import org.json.JSONTokener;
JSONSchemaValidation.class.getResourceAsStream("/schema.json")));
JSONSchemaValidation.class.getResourceAsStream("/data.json")));
15 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
37. What is Karate framework?
Karate is an open-source API testing framework that allows users to write tests for HTTP
services. It is built on top of the Cucumber framework and uses the Gherkin syntax. It
supports BDD-style tests for REST APIs, SOAP APIs, and GraphQL APIs. Karate enables
easy integration of data-driven tests and validation of responses using JSON or XML
structures.
2. Selective Execution: Only execute critical or impacted test cases (e.g., via test
tags or priorities).
6. Efficient Locators: Ensure element locators are precise to avoid slow or failing
tests.
1. Use the testng-failed.xml file that is generated after a test suite run. This file
contains only the failed test cases, which can be rerun.
Example of IRetryAnalyzer:
16 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
@Override
retryCount++;
return true;
return false;
6. Date and Time API: A new java.time package for working with dates and times.
Example:
17 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
42. How do you schedule a Jenkins job for midnight?
To schedule a Jenkins job for midnight, use the following cron syntax in the Build
Triggers section:
00***
Where:
• MINUTE: 0 to 59
• HOUR: 0 to 23
H/15 * * * *
Explanation: The job will run every 15 minutes, on any hour, day, and month.
00***
06***
30 15 * * 1-5
18 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
5. Run a job every Sunday at 1:00 PM
0 13 * * 0
Explanation: The job will run at 1:00 PM every Sunday (since 0 is Sunday).
0 8 1,15 * *
Explanation: The job will run at 8:00 AM on the 1st and 15th day of every month.
0 23 L * *
Explanation: L stands for the last day of the month, so the job will run at 11:00 PM on the
last day of each month.
30 0 * * 1#1
Explanation: The job will run at 12:30 AM on the first Monday of every month.
0 H/5 * * *
Explanation: The job will run every 5 hours starting from 12:00 AM.
0 12 * * 1-5
Explanation: The job will run at 12:00 PM (noon) from Monday to Friday.
Important Notes:
• H (Hash) Usage: Jenkins provides the H character to distribute load evenly. For
example, H 0 * * * would randomly choose a minute within the hour for the job to
start, helping to avoid congestion when multiple jobs are scheduled.
• Special Characters:
o ,: Separates multiple values (e.g., 1,15 for the 1st and 15th of the month).
19 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
Example: Schedule a Jenkins Job to Run at 10:00 PM Every Friday and 7:00 AM on
the 1st Day of Every Month
0 22 * * 5
071**
Explanation:
• The first line schedules the job to run at 10:00 PM every Friday.
• The second line schedules the job to run at 7:00 AM on the 1st day of every
month.
Explanation: This job will run every 30 minutes from 9:00 AM to 6:00 PM, Monday to
Friday.
By using this cron syntax, you can efficiently manage your Jenkins jobs to execute at the
desired times!
1. Functional Testing: Ensure that all buttons, forms, links, and interactive
elements function as expected.
20 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
3. Cross-Browser Testing: Test the page in different browsers like Chrome, Firefox,
Edge, and Safari.
4. Performance Testing: Measure page load times, especially for critical sections.
5. Security Testing: Check for vulnerabilities like SQL injection, XSS, and CSRF.
6. API Testing: If the page interacts with backend services, test the API calls.
API testing involves sending requests to the API endpoints and validating the responses.
Steps include:
1. Understand the API: Read API documentation to know the endpoints, methods
(GET, POST, PUT, DELETE), request parameters, headers, and authentication.
2. Create test cases: Write test cases for various scenarios, including positive,
negative, and edge cases.
3. Use tools: Start testing using tools like Postman or automate API tests using
tools like Rest Assured.
4. Validate responses: Check the status codes, response times, headers, and
data in the response body.
5. Check integration: Ensure that the API works well with other systems and
services.
• 201 Created: The request was successful, and a resource was created.
• 204 No Content: The request was successful, but there is no content to send in
the response.
• 400 Bad Request: The server could not understand the request due to invalid
syntax.
21 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• 403 Forbidden: The request was understood, but the server refuses to authorize
it.
47. Can you explain the difference between 401 and 403 response codes?
• 401 Unauthorized: This means that authentication is required, but the client
either didn’t provide credentials or provided invalid credentials. The server
expects the client to authenticate first.
• 403 Forbidden: This means that the client is authenticated, but does not have
permission to access the resource. The server knows the user but refuses to
grant access.
• Preconditions: Setup required before executing the test (e.g., user logged in).
• Pass/Fail Criteria: Whether the test passed or failed based on expected results.
22 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• Priority: The importance of the test case.
6. Set the priority: Assign the severity (Low, Medium, High, Critical).
51. What is the difference between git push and git push --force?
• git push: Pushes your local commits to the remote repository. It will not override
changes if there is a conflict with the remote branch.
• git push --force: Force pushes your local commits, potentially overriding the
history in the remote repository. It is useful when you need to overwrite the
remote changes, but should be used with caution as it can cause data loss for
others who rely on the repository.
git reset is used to undo changes in the local repository. It can be used in different
modes:
• --soft: Moves the HEAD to a different commit, but keeps the changes in the
working directory and index (staging area).
23 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• --mixed: Moves the HEAD to a different commit, resets the index, but keeps the
changes in the working directory.
• --hard: Moves the HEAD to a different commit and discards all changes in the
working directory and index. This is the most destructive option, as it erases
uncommitted work.
53. How would you start with a BDD framework from scratch?
4. Create step definitions: Map Gherkin steps to actual code by writing step
definition classes.
5. Implement page objects: For UI tests, use the Page Object Model (POM) to
interact with the web/mobile elements.
7. Automate and validate: Run the tests and ensure the behavior matches the
expected outcomes.
pom.xml (Project Object Model) is the configuration file for a Maven project. It manages
the project’s dependencies, build configuration, plugins, and versioning. Through the
pom.xml, developers can declare libraries and tools needed for the project, which are
automatically downloaded and added to the project classpath.
24 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
56. Write a program to find duplicate values in a given map.
import java.util.*;
map.put(1, "John");
map.put(2, "Doe");
map.put(3, "John");
map.put(4, "Jane");
if (!uniqueValues.add(value)) {
duplicateValues.add(value);
int a = 5;
25 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
int b = 10;
a = a + b; // a becomes 15
b = a - b; // b becomes 5
a = a - b; // a becomes 10
import java.util.*;
list.set(list.size() - i - 1, temp);
26 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
}
def check_odd_even(num):
if num % 2 == 0:
print(f"{num} is even")
else:
print(f"{num} is odd")
//input[@id='username']
//div[@class='container']/a
//button[text()='Submit']
2. Interact with elements: Once switched to the frame, you can locate elements
inside the frame.
27 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• Implicit Wait: Waits for a certain amount of time before throwing an exception if
an element is not found. It applies globally.
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
• Explicit Wait: Waits until a certain condition is met for an element. It’s more
flexible and specific.
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("element")));
• Fluent Wait: Waits for a condition while also defining the polling frequency and
ignoring exceptions.
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);
☞ Can you explain the differences between Abstraction and Interfaces in Java?
1. Abstraction:
28 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
o An abstract class can have both abstract methods (without a body) and
concrete methods (with a body). It can also have instance variables and
constructors.
o Example:
void stop() {
System.out.println("Vehicle stopped.");
2. Interfaces:
o All methods in an interface are abstract by default (unless they are static
or default).
o Example:
interface Drivable {
void drive();
void park();
64. Write a program to determine whether the strings “Car” and “Arc” are anagrams
of each other.
import java.util.Arrays;
29 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
String str2 = "Arc";
Arrays.sort(charArray1);
Arrays.sort(charArray2);
You can perform a drag-and-drop action using the Actions class in Selenium. Here's an
example:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.chrome.ChromeDriver;
30 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
public class DragAndDropExample {
driver.get("URL_OF_THE_PAGE");
actions.dragAndDrop(sourceElement, targetElement).perform();
driver.quit();
66. What are the differences between the get() and navigate().to() methods in
Selenium?
• get(String url):
o Example: driver.get("http://example.com");
• navigate().to(String url):
o It is more flexible, allowing for actions like forward and back navigation.
o Example: driver.navigate().to("http://example.com");
67. How would you execute a context click and a double-click action in Selenium?
To execute a context click (right-click) and a double-click action, you can use the
Actions class as shown below:
31 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.chrome.ChromeDriver;
driver.get("URL_OF_THE_PAGE");
WebElement elementToDoubleClick =
driver.findElement(By.id("doubleClickElement"));
// Right-click action
actions.contextClick(elementToRightClick).perform();
// Double-click action
actions.doubleClick(elementToDoubleClick).perform();
driver.quit();
68. What is the purpose of Selenium Grid, and how do you configure it?
Purpose:
32 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• Selenium Grid allows you to run tests on different machines against different
browsers in parallel. This speeds up the execution of tests and helps in cross-
browser testing.
Configuration:
1. Download Selenium Server: Download the Selenium Server jar file from the
Selenium website.
2. Start Hub: Open a command prompt and navigate to the directory where the
Selenium Server jar file is located. Start the hub with the following command:
3. Start Node: On the node machine, open a command prompt and run:
bash
Copy code
1. Retries: Implement a retry mechanism for failed tests. You can use TestNG's
@RetryAnalyzer to automatically retry failed tests.
3. Error Handling: Capture and analyze the errors to identify patterns and adjust
your test strategy accordingly.
A Test Runner in TestNG is a Java class that serves as an entry point for executing test
cases. Its purposes include:
• Executing Tests: It triggers the execution of test methods defined in test classes.
33 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• Test Configuration: It allows for configuration of test parameters and listeners.
• Reports: It generates test reports that provide insights into the execution results.
• Grouping: It enables the grouping of test cases for more organized execution.
import org.testng.TestNG;
testng.run();
Grouping tests in TestNG allows you to categorize tests based on their functionality,
priority, or type. This helps in:
• Selective Execution: You can run specific groups of tests without executing the
entire test suite, which saves time.
• Parameterized Testing: You can define different parameters for different groups,
facilitating varied test scenarios.
<suite name="SuiteName">
<test name="TestGroup1">
<groups>
<run>
<include name="group1"/>
</run>
34 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
</groups>
<classes>
<class name="YourTestClass"/>
</classes>
</test>
</suite>
71. Can you explain the difference between rebase and merge in Git?
• Merge:
o Combines the changes from two branches and creates a new commit in
the current branch that contains both sets of changes.
• Rebase:
o It results in a cleaner, linear project history but can lead to lost commit
history if not done carefully.
Use merge when you want to preserve the complete history, and use rebase for a
cleaner commit history.
• Automated Builds: Automatically build the code when changes are pushed to
the repository.
• Automated Testing: Run tests (unit, integration, UI) automatically after builds to
ensure code quality.
73. Can you describe your experience with the investment banking domain? What
challenges have you faced during the automation of banking features, and how did
you address them?
3. Integration with Legacy Systems: Many banking systems are built on legacy
technologies. I worked on creating wrappers and interfaces to integrate our
automated tests with these systems without disrupting their operations.
74. What are three OOP concepts used in your framework? Please explain in detail.
1. Encapsulation:
2. Inheritance:
36 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
o Inheritance allows a new class (subclass or derived class) to inherit
properties and behaviors (methods) from an existing class (superclass or
base class). This promotes code reuse and establishes a hierarchical
relationship between classes.
3. Polymorphism:
• ArrayList:
o Use Case: Suitable for storing and accessing data frequently without
many modifications.
• LinkedList:
37 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• POST:
• PUT:
77. Write a program to count and print the number of 'A's in a given string.
int count = 0;
if (c == 'A' || c == 'a') {
count++;
78. What is a Stale Element Exception? Why does it occur, and how do you handle
it?
38 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• Definition: A Stale Element Exception occurs when the element you are trying to
interact with is no longer attached to the DOM (Document Object Model). This
typically happens when the page is refreshed, or the element is modified after it
has been located.
• Causes:
• Handling:
o Example:
try {
element.click();
} catch (StaleElementReferenceException e) {
• 401 Unauthorized:
o This error indicates that the request has not been applied because it lacks
valid authentication credentials for the target resource.
o It is a generic error message and does not provide specific details about
the issue.
80. What is an Element Not Found Exception? Why does it occur, and how do you
handle it?
39 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• Definition: An Element Not Found Exception occurs when an attempt is made to
locate an element in the DOM, but the element cannot be found.
• Causes:
o The element may not be present in the current context (e.g., wrong page
or section).
• Handling:
o Use explicit waits to wait for the element to become visible or present in
the DOM.
o Example:
WebElement element =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("myElement")));
import java.util.Scanner;
long factorial = 1;
factorial *= i;
scanner.close();
40 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
}
import java.util.Scanner;
int reversed = 0;
while (num != 0) {
num /= 10;
scanner.close();
• List:
o Example:
41 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
list.add("Apple");
• Set:
o Does not allow duplicate elements and does not guarantee the order of
elements.
o Example:
set.add("Apple");
import java.util.HashMap;
if (charCountMap.containsKey(c)) {
} else {
charCountMap.put(c, 1);
System.out.println("Duplicate Characters:");
42 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
for (HashMap.Entry<Character, Integer> entry : charCountMap.entrySet()) {
if (entry.getValue() > 1) {
85. Which CI/CD pipeline tools have you used? Can you explain your experience
with them?
86. Can you explain the differences between Abstraction and Interfaces in Java?
• Abstraction:
• Interfaces:
• Key Differences:
43 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
o Implementation: Abstract classes can have both abstract methods
(without body) and concrete methods (with body), while interfaces can
only have abstract methods until Java 8 introduced default methods.
87. Write a program to determine whether the strings “Car” and “Arc” are
anagrams of each other.
import java.util.Arrays;
Arrays.sort(charArray1);
Arrays.sort(charArray2);
if (Arrays.equals(charArray1, charArray2)) {
} else {
44 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
}
To perform a drag-and-drop action in Selenium, you can use the Actions class. Here's
an example:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
driver.get("URL_OF_YOUR_PAGE");
actions.dragAndDrop(source, target).perform();
driver.quit();
45 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
89. What are the differences between the get() and navigate().to() methods in
Selenium?
• get():
o The get() method is used to open a specific URL in the browser. It waits for
the page to load completely before returning control to the script.
o Example: driver.get("http://www.example.com");
• navigate().to():
o It may not wait for the page to load completely, depending on how it is
implemented.
o Example: driver.navigate().to("http://www.example.com");
90. How would you execute a context click and a double-click action in Selenium?
To perform a context click (right-click) and a double-click action in Selenium, you can
also use the Actions class.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
driver.get("URL_OF_YOUR_PAGE");
46 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
// Create an Actions object and perform context click
actions.contextClick(element).perform();
driver.quit();
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
driver.get("URL_OF_YOUR_PAGE");
actions.doubleClick(element).perform();
driver.quit();
47 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
}
91. What is the purpose of Selenium Grid, and how do you configure it?
o Selenium Grid allows you to run your tests on multiple machines and
browsers simultaneously, facilitating parallel test execution. It is useful
for reducing test execution time and for testing across different
environments.
• Configuration:
1. Set up a Hub:
2. Set up Nodes:
3. Run Tests:
▪ In your test scripts, you can specify the hub URL to direct tests to
run on the grid.
Flaky tests are tests that sometimes pass and sometimes fail without any changes in
the code. Here are some
93. What are three OOP concepts used in your framework? Please explain in detail.
• ArrayList:
o Use case: Best when you need to frequently access elements by index or
when the size of the list remains relatively stable.
• LinkedList:
o Use case: Best when you expect to make a lot of insertions and deletions,
especially in the middle of the list.
• POST:
49 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
o The POST method is used to send data to the server to create a new
resource. It is not idempotent, meaning multiple identical requests can
result in different effects (e.g., creating multiple entries).
• PUT:
96. Write a program to count and print the number of 'A's in a given string.
int count = 0;
if (c == 'A' || c == 'a') {
count++;
97. What is a Stale Element Exception? Why does it occur, and how do you handle
it?
50 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• Handling it:
o Use try-catch blocks to handle the exception and retry locating the
element.
try {
} catch (StaleElementReferenceException e) {
• 401 Unauthorized:
o This error code indicates that the request requires user authentication. It
means the client has not provided valid authentication credentials for the
target resource. To resolve this, the client must authenticate itself with the
correct credentials.
99. What is an Element Not Found Exception? Why does it occur, and how do you
handle it?
• Handling it:
51 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
o Use explicit waits to allow the element to become present before trying to
interact with it.
WebElement element =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("elementId")));
int result = 1;
result *= i;
int reversed = 0;
while (number != 0) {
number /= 10;
}
52 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
System.out.println("Reversed number is " + reversed);
• List:
• Set:
import java.util.HashMap;
System.out.println("Duplicate characters:");
53 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
if (charCount.get(c) > 1) {
104. Which CI/CD pipeline tools have you used? Can you explain your experience
with them?
• Jenkins: I have set up Jenkins for automating builds and tests. I configured jobs
for various projects, integrating with Git for version control. I also implemented
plugins for notifications and reporting.
• GitLab CI: I utilized GitLab CI for CI/CD in projects hosted on GitLab. I wrote
.gitlab-ci.yml files to define stages for building, testing, and deploying
applications.
106. How many team members have you led in your projects?
107. Can you explain Polymorphism, along with examples of Method Overloading
and Method Overriding?
• Polymorphism:
54 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
o Polymorphism allows objects of different classes to be treated as objects
of a common superclass. It enables a single action to behave differently
based on the context.
• Method Overloading:
o Method overloading occurs when two or more methods in the same class
have the same name but different parameters (different type or number).
It is resolved at compile-time.
return a + b;
return a + b;
return a + b + c;
• Method Overriding:
class Animal {
void sound() {
55 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
class Dog extends Animal {
void sound() {
System.out.println("Dog barks");
• Java: 4/5 - I have strong knowledge and experience in Java, including OOP
concepts, data structures, and design patterns.
104. What are your roles and responsibilities in your current/previous role?
• Writing and executing test plans and test cases to ensure application quality.
56 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• Analyzing test results, identifying issues, and collaborating with developers for
resolution.
• Data-Driven Framework: This framework reads test data from external sources
like Excel or CSV files and runs the same test with different data inputs.
• Using Select class: For standard <select> dropdowns, you can use the Select
class to select options by visible text, value, or index.
dropdown.selectByVisibleText("Option 1");
• Using WebElement: For non-standard dropdowns, you can click the dropdown
and select options based on their XPath or CSS selectors.
107. Give a scenario where you need to click on Electronics in Flipkart using the
Action class.
In this scenario, we might need to use the Action class to move to a menu item that may
not be directly clickable or requires hover action before selection. Here's how you can
do it:
WebElement electronicsMenu =
driver.findElement(By.xpath("//span[text()='Electronics']"));
actions.moveToElement(electronicsMenu).click().perform();
57 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
Polymorphism in Java is the ability of a method to perform different tasks based on the
object that it is acting upon. It allows for methods to have the same name but behave
differently in different contexts. There are two types of polymorphism:
An interface in Java is a reference type that can contain only constants, method
signatures, default methods, static methods, and nested types. It cannot contain
instance fields or constructors. Interfaces are used to specify what a class must do,
without dictating how it must do it. They provide a way to achieve abstraction and
multiple inheritance.
Example:
interface Animal {
System.out.println("Dog barks");
110. What is Cucumber, and how does it fit in your testing strategy?
Cucumber is a BDD testing framework that allows writing test cases in a natural
language format (Gherkin) that can be understood by non-technical stakeholders. It fits
into my testing strategy by facilitating collaboration between developers, testers, and
business analysts. By defining acceptance criteria in Gherkin syntax, I ensure that the
tests are closely aligned with business requirements.
111. What is the difference between Scenario Outline and Data Tables in
Cucumber?
58 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• Scenario Outline: It allows for running the same scenario multiple times with
different sets of inputs. It uses placeholders and an example table to define the
variable data.
Example:
Examples:
• Data Tables: They allow for passing a list of values or a structured set of data
within a single step. It is used for scenarios that require multiple inputs in a
tabular format.
Example:
| username | password |
| user1 | pass1 |
| user2 | pass2 |
Hooks in Cucumber are blocks of code that run at specific points in the test execution
lifecycle. They allow for setting up or tearing down tests, managing preconditions, or
logging test execution. Common hooks include @Before, @After, @BeforeStep, and
@AfterStep.
Example:
@Before
59 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
}
@After
Tagging in Cucumber allows you to categorize and filter scenarios based on tags. It
helps in executing a subset of tests or organizing tests based on specific features or
requirements. You can use tags in the command line to run specific scenarios or in the
feature files to group related tests.
Example:
@smoke
You can run tests with the @smoke tag using the command:
114. What is the difference between Dry Run and Strict in Cucumber?
• Dry Run: This feature checks if all steps in the feature file have corresponding
step definitions. It does not execute the tests but verifies the mapping between
the feature file and step definitions.
• Strict: When set to strict mode, Cucumber will fail the execution if there are any
undefined or pending steps in the feature file. It ensures that all steps have
corresponding implementations before executing the tests.
Yes, Cucumber supports TestNG integration. You can run Cucumber tests using TestNG
by creating a TestNG runner class and using the @CucumberOptions annotation to
specify the feature files and step definitions.
Example:
@RunWith(Cucumber.class)
60 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
}
Encapsulation is an OOP principle that involves bundling the data (attributes) and
methods (functions) that operate on the data into a single unit, typically a class, while
restricting access to some of the object's components. This is achieved through access
modifiers (private, protected, public).
Example:
balance += amount;
return balance;
117. Write a Java program to find duplicate characters from a word without using
for loops.
import java.util.HashMap;
charCount.put(c, charCount.getOrDefault(c, 0) + 1)
61 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
);
charCount.forEach((k, v) -> {
if (v > 1) {
});
Example:
# ObjectRepository.properties
loginButton = //button[@id='login']
usernameField = //input[@name='username']
passwordField = //input[@name='password']
You can store data in a .properties file by using key-value pairs. Each line represents a
key-value mapping, with the key on the left and the value on the right, separated by an
equal sign (=).
Example:
baseUrl = https://example.com
timeout = 30
browser = chrome
62 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
Page Factory is a design pattern in Selenium that provides an efficient way to initialize
Page Objects. It uses annotations to define the web elements in the Page Object class
and initializes them lazily, meaning elements are only found when they are accessed for
the first time.
Example:
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
@FindBy(id = "username")
@FindBy(id = "password")
PageFactory.initElements(driver, this);
usernameField.sendKeys(username);
passwordField.sendKeys(password);
63 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
• @BeforeClass: This annotation runs once before any of the test methods in the
current class. It is typically used for setup that is class-specific, such as
initializing WebDriver for tests in that class.
• @BeforeTest: This annotation runs once before any test methods belonging to
the classes that are part of the test tag in the TestNG XML file. It is used for test
setup that needs to be shared across multiple classes or test methods.
121. What are the tasks typically written under the @BeforeTest annotation?
You can skip a test case in Cucumber by using the @skip tag. When running the tests,
you can exclude tests with this tag.
Example:
@skip
To rerun failed test cases in TestNG, you can use the ITestListener interface and
implement the onTestFailure method to rerun failed tests. Alternatively, you can
configure the testng.xml file to specify the rerun-failed configuration.
Example:
<listeners>
<listener class-name="org.testng.IRetryAnalyzer"/>
</listeners>
64 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
124. How do you group and run test cases in TestNG?
You can group test cases in TestNG using the groups attribute in the @Test annotation
and by specifying the groups in the testng.xml file.
Example:
@Test(groups = {"smoke"})
// test code
In testng.xml:
<suite name="Suite">
<test name="SmokeTests">
<groups>
<run>
<include name="smoke"/>
</run>
</groups>
<classes>
<class name="TestClass"/>
</classes>
</test>
</suite>
Under the @BeforeSuite annotation, you can include tasks that need to be executed
once before all tests in the suite, such as:
• Link Text: Locate anchor tags (<a>) by the text they display. Example:
driver.findElement(By.linkText("Click here")).
• Partial Link Text: Locate anchor tags by a part of their text. Example:
driver.findElement(By.partialLinkText("Click")).
A collection in Java is a data structure that allows you to store and manipulate groups of
related objects. Java Collections Framework provides various interfaces and classes,
such as List, Set, Map, and their implementations (ArrayList, HashSet, HashMap, etc.).
Collections provide methods for storing, accessing, and manipulating data efficiently.
• Unchecked Exceptions: These are exceptions that are not checked at compile-
time and include runtime exceptions. They extend RuntimeException and do not
require explicit handling. Examples include NullPointerException,
ArrayIndexOutOfBoundsException.
• Throwable
66 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1
o Exception
▪ Checked Exceptions
▪ Unchecked Exceptions
▪ RuntimeException
67 | I n t e r v i e w Q u e s t i o n a n d A n s w e r p a r t 1