0% found this document useful (0 votes)
13 views21 pages

Infosys

Interview questions infosys

Uploaded by

nithya.singam07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views21 pages

Infosys

Interview questions infosys

Uploaded by

nithya.singam07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

1. What is STLC?

 STLC stands for Software Testing Life Cycle. It is a systematic


approach to testing software applications that ensures thorough
testing and validation of the software before it is released to the
end-users. STLC consists of several phases including requirement
analysis, test planning, test case development, test execution,
defect tracking, and test closure.
2. Difference between Test Plan, Test Case, and Test Scenario:
 Test Plan: A test plan is a document that outlines the scope,
objectives, approach, resources, and schedule for a testing
project. It provides a roadmap for the testing activities and
serves as a guide for the testing team throughout the project.
 Test Case: A test case is a detailed set of conditions or steps to
be followed to verify a particular functionality or feature of the
software. It includes preconditions, test steps, expected results,
and actual results. Test cases are derived from test scenarios
and are used to ensure that the software behaves as expected
under various conditions.
 Test Scenario: A test scenario is a high-level description of a
particular functionality or feature to be tested. It outlines the
conditions or situations under which testing will be performed.
Test scenarios are used as the basis for creating test cases.
3. Positive and Negative Scenarios on Pen:
 Positive Scenario: A positive scenario on a pen could be
testing whether the pen writes smoothly on paper when ink is
available, the pen cap can be easily removed and placed back
securely, and the pen is comfortable to hold.
 Negative Scenario: A negative scenario on a pen could be
testing what happens when the pen runs out of ink (e.g., does it
write at all, does it leave streaks or scratches on paper), testing
if the pen cap can be removed accidentally, or if the pen leaks
ink when placed in a pocket.
4. Selenium Framework:
 A Selenium framework is a structured set of guidelines,
practices, and reusable components that help in organizing and
maintaining Selenium test automation projects efficiently. It
typically includes libraries, utilities, and templates for tasks such
as test case design, test execution, reporting, and management.
Common Selenium frameworks include Page Object Model (POM),
Data-Driven Testing Framework, Keyword-Driven Testing
Framework, and Hybrid Testing Framework.
5. How to Write Selenium Test Cases:
 Identify the test scenarios based on requirements or user stories.
 Create test cases for each scenario, specifying preconditions,
test steps, expected results, and actual results.
 Implement test cases using Selenium WebDriver and the
programming language of your choice (e.g., Java, Python, C#).
 Use appropriate Selenium commands and methods to interact
with web elements, perform actions, and validate outcomes.
 Execute the test cases and observe the results.
 Analyze any failures or defects and report them appropriately.
 Iterate on the test cases as needed based on feedback and
changes in the application under test.

Writing Selenium test cases involves a combination of technical skills,


domain knowledge, and understanding of testing principles. It's essential to
design test cases that cover both positive and negative scenarios, handle
edge cases, and ensure comprehensive test coverage.
6.Types of wait in Selenium:
 Implicit Wait: It waits for a certain amount of time before
throwing a NoSuchElement exception.
 Explicit Wait: It waits for a certain condition to occur before
proceeding further in the code.
 Fluent Wait: It waits for a condition with polling interval and
timeout.
7.How to run test cases in parallel using TestNG:
 You can use TestNG's parallel attribute in the suite XML file or
use parallel annotations at the test or method level.

Q5. Challenges in Selenium:

 Dynamic Elements: Selenium struggles with dynamic web elements


that change their attributes or positions on the page dynamically,
making it challenging to locate them consistently.
 Cross-Browser Testing: Ensuring compatibility across different web
browsers and versions can be challenging due to variations in browser
behavior and rendering engines.
 Handling Asynchronous Operations: Selenium may encounter
difficulties in handling asynchronous operations like AJAX requests, as
it may not wait for these operations to complete before performing
subsequent actions.
 Test Maintenance: Maintaining test scripts can become challenging,
especially in large-scale projects, as changes in the application's UI or
functionality may require frequent updates to the test scripts.
 Limited Support for Non-Web UI: Selenium is primarily designed for
testing web applications and lacks built-in support for testing non-web
UI components such as desktop applications or mobile apps.

Q6. Handling Broken Links in Selenium:


 To handle broken links in Selenium, you can:
 Use the HttpURLConnection class in Java to send HTTP requests
to each link and verify the response status codes (e.g., 200 for
OK, 404 for Not Found).
 Iterate through all links on the webpage using Selenium
WebDriver methods like findElements(By.tagName("a")) .
 Use try-catch blocks to handle exceptions and log the details of
broken links.
 Implement this logic as part of your Selenium test scripts or as a
separate utility function.

Q7. WebDriver Exceptions:

 WebDriver exceptions are thrown when Selenium encounters errors or


unexpected conditions during test execution. Some common
WebDriver exceptions include:
 NoSuchElementException : Thrown when an element could not be
found using the specified locator.
 TimeoutException : Thrown when a timeout occurs while waiting
for an element to be present, visible, or clickable.
 StaleElementReferenceException : Thrown when the reference to
an element is no longer valid because the DOM has been
refreshed or the element has been removed from the page.
 ElementNotVisibleException : Thrown when attempting to interact
with an element that is present in the DOM but not visible on the
page.
 ElementNotInteractableException : Thrown when an element is
present in the DOM but not in a state to be interacted with, such
as being disabled or obscured by another element.

Q8. Limitations of Selenium:

 Limited Support for Desktop and Mobile Applications: Selenium


is primarily designed for automating web applications and lacks built-in
support for testing desktop applications or mobile apps.
 Complexity in Handling Dynamic Elements: Selenium struggles
with dynamic web elements that change attributes or positions on the
page dynamically, requiring complex locators or wait strategies.
 No Built-in Reporting and Test Management: Selenium does not
provide built-in reporting or test management features, necessitating
integration with third-party tools or frameworks for comprehensive
reporting and test orchestration.
 Browser Compatibility: Selenium may encounter compatibility
issues across different browsers and versions due to variations in
browser behavior and rendering engines, requiring additional effort for
cross-browser testing and maintenance.
 No Built-in Support for Data-Driven Testing: Selenium lacks built-
in support for data-driven testing, where test data is externalized from
test scripts, requiring additional frameworks or libraries for
implementing data-driven testing.
HTTP operations that are frequently used in web development and testing:

1. GET: The GET method is used to retrieve data from a specified


resource. It requests data from a server based on a URL and is typically
used for fetching web pages, images, documents, etc.
2. POST: The POST method is used to submit data to be processed to a
specified resource. It sends data to the server inside the body of the
request and is commonly used for submitting forms, uploading files, or
performing database operations.
3. PUT: The PUT method is used to update or replace an existing
resource on the server with the data provided in the request. It sends
the entire resource data to the server, replacing the existing resource
if it already exists, or creating a new resource if it doesn't.
4. DELETE: The DELETE method is used to delete a specified resource
from the server. It requests the server to remove the resource
identified by the URL from its database or storage.
5. PATCH: The PATCH method is used to apply partial modifications to a
resource on the server. It sends only the data that needs to be
changed, allowing clients to update specific fields of a resource without
affecting the rest of the resource data.
6. HEAD: The HEAD method is similar to the GET method but only
requests the headers of the response, without actually retrieving the
response body. It is commonly used to check the headers or metadata
of a resource, such as content type, content length, etc.
7. OPTIONS: The OPTIONS method is used to request information about
the communication options available for a resource. It allows the client
to determine the supported HTTP methods, headers, and other
capabilities of the server for a given resource.

These are some of the common HTTP operations used in web development
and testing. Depending on the requirements of a specific project or task,
different HTTP methods may be utilized to interact with web servers and
exchange data over the internet.

Q11. Purpose of pass, break, and continue keywords:

 pass: In Python, pass is a null operation that does nothing when it is


executed. It is typically used as a placeholder when syntactically
required but no action is needed. For example, in an empty class or
function definition, or in a conditional statement where no action is
required for a particular branch.
 break: The break statement is used to exit from a loop prematurely.
When break is encountered within a loop (such as for or while), it
immediately terminates the loop and control flows to the statement
immediately following the loop.
 continue: The continue statement is used to skip the rest of the
current iteration of a loop and continue with the next iteration. When
continue is encountered within a loop, the remaining code within the
loop for the current iteration is skipped, and control moves to the next
iteration of the loop.

Q12. One Task Repetition of Characters Count Logic:

# Example Java code to count the repetition of characters in a string

import java.util.HashMap;

import java.util.Map;

public class CharacterCounter {

public static void main(String[] args) {

String str = "Hello, World!";

Map<Character, Integer> charCountMap = new HashMap<>();

// Convert the string to char array

char[] charArray = str.toCharArray();

// Iterate through each character in the char array

for (char c : charArray) {

// Check if the character is already present in the map

if (charCountMap.containsKey(c)) {

// If yes, increment its count

charCountMap.put(c, charCountMap.get(c) + 1);

} else {

// If not, add it to the map with count as 1


charCountMap.put(c, 1);

// Print the character count

for (Map.Entry<Character, Integer> entry : charCountMap.entrySet()) {

System.out.println(entry.getKey() + ": " + entry.getValue());

This code defines a function count_characters that takes a string as input and
counts the repetition of each character in the string using a dictionary to
store the counts. It then prints out the count for each character.

Q13. Why are strings immutable in Java?

 In Java, strings are immutable, meaning once a string object is created,


its state cannot be changed. There are several reasons why strings are
immutable in Java:
1. Thread Safety: Immutable strings are inherently thread-safe,
as multiple threads can access them simultaneously without the
risk of data corruption or inconsistency.
2. String Pooling: String pooling is a memory optimization
technique in Java, where multiple string literals with the same
value are stored in a common pool and shared among different
parts of the program. Immutable strings ensure that string
literals remain consistent and can safely be shared.
3. Security: Immutable strings are used extensively in security-
sensitive operations such as encryption and hashing, where any
modification to the string could compromise security.
4. Caching: Immutable strings can be cached and reused
efficiently, leading to performance optimizations and reduced
memory overhead.
5. Predictable Behavior: Immutable strings simplify the
programming model by guaranteeing that once created, a
string's value will remain unchanged, ensuring predictable
behavior and avoiding unexpected side effects.
 Test Plan:
1. Definition: A test plan is a detailed document that outlines the
scope, objectives, approach, resources, schedule, and
deliverables of a testing project. It provides a roadmap for the
testing activities and serves as a guide for the testing team
throughout the project lifecycle.
2. Contents: A test plan typically includes sections such as
introduction, objectives, scope, test strategy, test
methodologies, test environment setup, test deliverables, test
schedules, resource allocation, risks and mitigation strategies,
and approval criteria.
3. Focus: A test plan focuses on the specific details of testing
activities, including what needs to be tested, how it will be
tested, who will perform the testing, and when it will be done.
4. Level: Test plans are usually created at a project level and may
cover one or more testing phases, such as unit testing,
integration testing, system testing, and acceptance testing.
5. Audience: Test plans are typically reviewed and approved by
project stakeholders, including project managers, test managers,
developers, and business analysts.
 Test Strategy:
1. Definition: A test strategy is a high-level document that outlines
the overall approach and objectives of testing for a project or
organization. It provides guidance on how testing activities will
be organized, managed, and executed to achieve the desired
quality goals.
2. Contents: A test strategy typically includes sections such as
introduction, objectives, scope, testing approach, testing
techniques, test automation strategy, test environment strategy,
defect management process, and resource allocation.
3. Focus: A test strategy focuses on defining the overarching
principles, methodologies, and best practices that will govern
testing activities across multiple projects or testing phases.
4. Level: Test strategies are usually created at an organizational or
program level and provide a framework for developing project-
specific test plans. They may be tailored or customized based on
the specific needs and requirements of individual projects.
5. Audience: Test strategies are typically reviewed and approved
by senior management, quality assurance managers, and other
stakeholders responsible for defining and implementing testing
standards and practices across the organization.

In summary, while both a test plan and a test strategy are important
documents in the testing process, they serve different purposes and are
created at different levels of detail. A test plan provides detailed guidance
for a specific testing project, while a test strategy outlines the overarching
principles and approaches for testing across multiple projects or testing
phases within an organization. During an interview, it's important to
understand the distinctions between these two documents and articulate
how they contribute to the overall testing effort.

2. Difference between findElement and findElements in


Selenium:
 findElement : Returns the first web element matching the
specified locator. If no element is found, it throws a
NoSuchElementException .
 findElements : Returns a list of web elements matching the
specified locator. If no elements are found, it returns an
empty list.
3. Difference between Implicit and Explicit Waits:
 Implicit Wait: Sets a maximum time limit for Selenium
WebDriver to wait for an element to be found when trying
to locate elements. It is applied globally and waits for a
specified amount of time before throwing a
NoSuchElementException .
 Explicit Wait: Allows Selenium WebDriver to wait for a
certain condition to occur before proceeding with
executing the next command. It is applied to specific
elements and waits for a certain condition to be met
within a specified timeout period.
4. Syntax for Explicit Wait in Selenium:
javaCopy code
WebDriverWait wait = new WebDriverWait (driver, timeoutInSeconds);
WebElement element =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.locator( "elementLocator
" )));
5. How to Invoke a Browser in Selenium:
 In Selenium, you can invoke a browser using the
WebDriver object and specifying the desired browser as a
capability. For example:
javaCopy code
WebDriver driver = new ChromeDriver ();
6. What are TestNG Annotations:
 TestNG annotations are special Java annotations used to
control the flow of test execution in TestNG-based test
scripts. Examples include @Test, @BeforeTest, @AfterTest,
@BeforeMethod, @AfterMethod, etc.
7. How to Read Excel File in Selenium:
 You can use Apache POI library in Selenium to read Excel
files. Here's a basic example:
javaCopy code
FileInputStream fis = new FileInputStream ( "path/to/excel/file.xlsx" ); Workbook
workbook = new XSSFWorkbook (fis); Sheet sheet =
workbook.getSheet( "Sheet1" ); // Iterate through rows and cells to read data
8. How to Do Parallel Testing in Selenium:
 Parallel testing in Selenium can be achieved using
TestNG's parallel execution features, where you can
specify the parallelization mode at the suite, test, or
method level.
9. Tools Used in Selenium Framework:
 Some common tools used in Selenium frameworks
include TestNG, Apache POI, Log4j, Extent Reports,
Maven/Gradle, Jenkins, Docker, and various IDEs like
Eclipse or IntelliJ IDEA.
10. Exceptions in Selenium:
 Common exceptions in Selenium include
NoSuchElementException , TimeoutException ,
StaleElementReferenceException , ElementNotVisibleException , etc.
11. Stale Element Exceptions:
 Stale Element Reference Exception occurs when an
element is no longer attached to the DOM (Document
Object Model) but is still being referenced by the script.
12. How to Do Drag and Drop in Selenium:
 You can perform drag and drop using the Actions class in
Selenium. Here's an example:
javaCopy code
WebElement source = driver.findElement(By.id( "source" )); WebElement target =
driver.findElement(By.id( "target" )); Actions actions = new Actions (driver);
actions.dragAndDrop(source, target).build().perform();
13. Write a Program to Find Two Largest Numbers:
javaCopy code
public static void findTwoLargest(int[] nums) { int max1 = Integer.MIN_VALUE;
int max2 = Integer.MIN_VALUE; for ( int num : nums) { if (num > max1) { max2 =
max1; max1 = num; } else if (num > max2 && num != max1) { max2 = num; } }
System.out.println( "Largest number: " + max1); System.out.println( "Second largest
number: " + max2); }
14. What is Collection:
 Collection in Java is a framework that provides a set of
interfaces and classes to represent and manipulate
groups of objects, known as collections. Examples include
List, Set, Map, etc.
15. Difference between final and finally:
 final is a keyword used in Java to declare constants,
immutable variables, or methods that cannot be
overridden.
 finally is a block in Java used in exception handling to
ensure that a block of code is always executed,
regardless of whether an exception is thrown or not.
16. What is Constructor:
 A constructor in Java is a special type of method that is
used to initialize objects of a class. It has the same name
as the class and does not have a return type.
Constructors are called automatically when an object is
created.
17. What is Defect Bug Cycle:
 The defect bug cycle, also known as the defect lifecycle,
is the process of identifying, reporting, tracking, fixing,
and retesting defects or bugs in software applications. It
typically consists of stages like defect identification,
defect logging, defect triage, defect resolution, and defect
verification.
18. What is SDLC:
 SDLC stands for Software Development Life Cycle. It is a
process used by software development teams to design,
develop, test, and deploy software applications. Common
SDLC models include Waterfall, Agile, Iterative, and Spiral
models.
19. Access Modifiers in Java:
 Access modifiers in Java are keywords used to control the
visibility and accessibility of classes, methods, and
variables. The main access modifiers are public, private,
protected , and default.
20. Checked and Unchecked Exceptions:
 Checked exceptions are exceptions that must be either
caught using a try-catch block or declared in the
method's throws clause. Examples include IOException,
SQLException, etc.
 Unchecked exceptions (also known as runtime
exceptions) are exceptions that do not need to be
explicitly handled or declared. Examples include
NullPointerException, ArrayIndexOutOfBoundsException,
etc.
21. How to Handle Alerts in Selenium:
 You can handle alerts in Selenium using the Alert
interface. Here's an example:
javaCopy code
Alert alert = driver.switchTo().alert(); String alertText = alert.getText();
alert.accept(); // To accept the alert // Or alert.dismiss(); // To dismiss the alert
22. How to Handle Frames in Selenium:
 You can switch to frames using the switchTo().frame()
method in Selenium. Here's an example:
javaCopy code
driver.switchTo().frame( "frameName" ); // Or driver.switchTo().frame( 0 ); //
Switching by index // Perform actions within the frame
driver.switchTo().defaultContent(); // Switch back to the main content
Open google.com, Enter Username Password, Show Authentication Popup:
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");

// Locate the username and password fields and enter credentials


WebElement usernameField = driver.findElement(By.id("username"));
usernameField.sendKeys("your_username");

WebElement passwordField = driver.findElement(By.id("password"));


passwordField.sendKeys("your_password");

// Trigger authentication popup (if applicable)


Alert authenticationPopup = driver.switchTo().alert();
authenticationPopup.accept(); // Or dismiss() if needed
How to Confirm Which User is Logged in:
 After logging in, you can verify the logged-in user's information by
inspecting elements on the webpage, such as username labels, profile
pictures, or any personalized messages displayed after successful
login.
Passing Parameter in Second Checkbox out of 3 Checkboxes:
 You can use the findElements method to locate all checkboxes and
then select the second one using indexing. Here's an example:
 List<WebElement> checkboxes = driver.findElements(By.xpath("//input[@type='checkbox']"));
 if (checkboxes.size() >= 3) {
 checkboxes.get(1).click(); // Clicking the second checkbox
 }This
code locates all checkboxes on the page and selects the second
checkbox by index (indexing starts from 0).

Super:
the super keyword is used to refer to the immediate parent class object.

 Array List: Internally, an array list is backed by an array. Elements are


stored in contiguous memory locations, allowing for fast random
access but slower insertion and deletion operations in the middle.
 Linked List: A linked list consists of nodes where each node contains
a data element and a reference (or pointer) to the next node in the
sequence. It doesn't use contiguous memory locations, so random
access is slower, but insertion and deletion operations are faster,
especially in the middle.

2. Types of Frameworks in Selenium:


 Data-Driven Testing Framework
 Keyword-Driven Testing Framework
 Hybrid Testing Framework
 Behavior Driven Development (BDD) Framework
3. Difference between throw and throws:
 throw is a keyword used to explicitly throw an exception within a method.
 throws is a keyword used in the method signature to declare the
exceptions that a method might throw, indicating that the method could
potentially throw those exceptions.
4. Difference between arrays and ArrayList:
 Arrays are fixed in size and can hold primitive data types or objects,
whereas ArrayList is a dynamic array implementation in Java that can
dynamically resize itself and can only hold objects.
5. Hashmap and HashSet:
 HashMap is a collection that stores key-value pairs and allows unique
keys. It does not maintain the insertion order.
 HashSet is a collection that stores unique elements and does not allow
duplicate values. It does not maintain any order.
6. Probability of getting NullPointerException:
 NullPointerException occurs when attempting to access or manipulate an
object that is null. The probability of encountering it depends on how well
null checks are implemented in the code. If proper null checks are in place
and null conditions are handled gracefully, the probability of getting
NullPointerException decreases.
7. Types of wait in Selenium:
 Implicit Wait: It waits for a certain amount of time before
throwing a NoSuchElement exception.
 Explicit Wait: It waits for a certain condition to occur before
proceeding further in the code.
 Fluent Wait: It waits for a condition with polling interval and
timeout.
8. How would you fix your Selenium code if it is slow:
 Use efficient locators like CSS or XPath.
 Minimize the usage of Thread.sleep() as it can cause
unnecessary delays.
 Implement explicit waits instead of implicit waits.
 Optimize the execution flow and remove redundant code.
 Use headless browsers for faster execution in some cases.
9. If there is a button on a page and it is visible but not clickable,
what could be the reason:
 The button might be disabled via CSS or JavaScript.
 It could be overlapped by another element.
 There could be some JavaScript running asynchronously,
preventing the button from being clickable immediately.
10. How to switch back to the parent window:
 You can use driver.switchTo().defaultContent() to switch back to
the parent window in Selenium.
11. How to run test cases in parallel using TestNG:
 You can use TestNG's parallel attribute in the suite XML file or
use parallel annotations at the test or method level.
12. Parameterization in TestNG:
 Parameterization in TestNG allows you to execute the same test
method multiple times with different sets of data. This can be
achieved using the @Parameters annotation along with the
testng.xml file or by using the @DataProvider annotation to
supply test data.
13. Assertions:
 Assertions are used in testing to verify that expected conditions
are met during the execution of a test script. In Java, assertions
are typically implemented using the assert keyword or through
assertion methods provided by testing frameworks like TestNG or
JUnit. They help in validating the expected outcomes of test
cases and identifyi

ng issues or bugs in the application under test.


14. Exceptions thrown by findElement and findElements in
Selenium:
 Both fzindElement and findElements methods in Selenium
WebDriver can throw a NoSuchElementException if the element
being searched for is not found within the specified timeout
period. This exception indicates that the element could not be
located on the page.
15. How many types of exceptions in Selenium:
 There are several types of exceptions that can occur in Selenium
WebDriver. Some common ones include:
1. NoSuchElementException : When an element could not be
found.
2. TimeoutException: When a command does not complete in
the specified time.
3. ElementNotVisibleException : When an element is present in
the DOM but is not visible on the page.
4. StaleElementReferenceException : When the referenced
element is no longer present in the DOM.
5. WebDriverException: General exception type for
WebDriver-related errors.
16. Probability of WebDriverException:
 WebDriverException can occur due to various reasons such as
network issues, browser compatibility issues, element not
interactable, etc. The probability of encountering a
WebDriverException depends on the stability of the testing
environment, the robustness of the test scripts, and the
reliability of the WebDriver implementation being used.
16. Switch between frames:
 You can switch between frames in Selenium WebDriver using the
switchTo().frame() method. You can switch by index, frame name, or
frame WebElement. Here's an example:
javaCopy code
// Switch to frame by index driver.switchTo().frame( 0 ); // Switch to frame by name
or ID driver.switchTo().frame( "frameName" ); // Switch to frame by WebElement
WebElement frameElement = driver.findElement(By.tagName( "iframe" ));
driver.switchTo().frame(frameElement);
17. Use of ITestListener:
 ITestListener interface in TestNG allows you to listen to events
occurring in the TestNG lifecycle such as before/after test,
before/after suite, before/after method, etc. You can implement
this interface to customize and perform actions based on these
events, like logging test results, taking screenshots, etc.
18. Static keyword:
 static keyword in Java is used to define class-level members (variables
and methods) that are shared among all instances (objects) of the
class
 The static keyword in Java is used to declare members (variables
and methods) that belong to the class rather than to any specific
instance of the class. Static members are shared among all
instances of the class. Static variables retain their values
throughout the program's execution, while static methods can be
called without creating an instance of the class.
19. Difference between Static and Final:
 static: Used to create variables and methods that belong to the
class rather than to any specific instance. Static
variables/methods are shared among all instances of the class.
Static variables retain their values throughout the program's
execution.
 final: Used to declare constants, variables, or methods that
cannot be changed or overridden. Once a final variable is
initialized, its value cannot be changed. Final methods cannot be
overridden in subclasses.
20. Program to find duplicate value from an ArrayList:
 You can find duplicate values in an ArrayList by iterating through
the list and using a HashSet to track unique elements. Here's a
sample Java program to find duplicate values:
javaCopy code
import java.util.ArrayList; import java.util.HashSet; public class Main { public
static void main(String[] args) { ArrayList<Integer> list = new ArrayList <>();
list.add( 1 ); list.add( 2 ); list.add( 3 ); list.add( 2 ); list.add( 4 ); list.add( 1 );
HashSet<Integer> set = new HashSet <>(); HashSet<Integer> duplicates = new
HashSet <>(); for (Integer num : list) { if (!set.add(num))
{ duplicates.add(num); } } System.out.println( "Duplicate values: " +
duplicates); } }

Certainly, here are the answers to your questions:

21. What is an Abstract class:


 An abstract class in object-oriented programming (OOP) is a class that
cannot be instantiated on its own, meaning you cannot create objects
directly from it. Instead, it serves as a blueprint for other classes to
inherit from.
 An abstract class in Java is a class that cannot be instantiated
directly and may contain abstract methods, which are methods
without a body. Abstract classes are meant to be extended by
subclasses, and they can provide a partial implementation for
those subclasses to build upon.
22. What is Selenium. Is it a tool or framework or library:
 Selenium is a suite of tools for automating web browsers. It is
primarily a set of different software tools, each with a different
approach to supporting browser automation. So, Selenium is
often considered a tool.
23. Dynamic polymorphism with example:
 Dynamic polymorphism, also known as runtime polymorphism,
occurs when a method call is resolved at runtime rather than at
compile-time. It is achieved through method overriding. Here's
an example:
javaCopy code
class Animal { void sound() { System.out.println( "Animal makes a sound" ); } }
class Dog extends Animal { void sound() { System.out.println( "Dog barks" ); } }
public class Main { public static void main(String[] args) { Animal animal = new
Dog (); // Upcasting animal.sound(); // Calls Dog's sound() method dynamically } }
24. Dry run in Cucumber:
 A dry run in Cucumber is a mode where Cucumber executes the
feature files and steps without actually running the scenarios. It's
a way to verify that all the steps in the feature files are
implemented correctly and are correctly mapped to step
definitions.
25. How would you find if a scenario is missing from the
feature file:
 You can review the feature files manually to ensure that all
scenarios are properly defined. Additionally, some IDEs or tools
may provide features to detect unused or undefined step
definitions, which can help identify missing scenarios.
26. What does String object hold:
 A String object in Java holds a sequence of characters. Strings
are immutable, meaning once created, their values cannot be
changed. They can hold text data such as words, sentences, or
even entire documents.
27. What are non-access data types:
 Non-access data types are data types in Java that do not directly
control access to class members. Examples include primitive
data types like int, float, double, boolean, and reference data
types like String, arrays, and user-defined classes.
28. How to find hidden elements in DOM:
 You can find hidden elements in the DOM using
JavaScriptExecutor to execute JavaScript code to manipulate the
DOM directly. For example:
javaCopy code
WebElement element =
driver.findElement(By.cssSelector( "input[type='hidden']" ));
29. What if there are multiple exceptions in a program:
 Multiple exceptions in a program can be handled using multiple
catch blocks or a single catch block with multiple catch clauses
(multi-catch). Each catch block or clause can handle a specific
type of exception.
30. Why REST API:
 REST APIs are popular because they are simple, lightweight, and
platform-independent. They use standard HTTP methods for
communication and can be easily consumed by various clients,
including web browsers, mobile devices, and other applications.
31. Query params in REST API:
 Query parameters in a REST API are additional parameters added
to the URL of a request to provide additional information to the
server. They are typically used for filtering, sorting, or pagination
purposes.
32. Difference between POST and PATCH:
 POST is used to create a new resource on the server, while
PATCH is used to update an existing resource partially. POST is
idempotent, meaning calling it multiple times with the same
input will produce the same result. PATCH is not necessarily
idempotent, as calling it multiple times with the same input could
result in different outcomes.
33. Host and endpoints:
 In the context of REST APIs, a host is the server where the API is
hosted, typically identified by a domain name or IP address.
Endpoints are specific URLs or URIs within the API that
correspond to different resources or operations.

Count of duplicate string:

import java.util.HashMap;

import java.util.Map;

public class CountDuplicates {

public static void main(String[] args) {

String str = "hello world";

Map<Character, Integer> charCount = new HashMap<>();

// Count occurrences of each character in the string

for (char c : str.toCharArray()) {

if (charCount.containsKey(c)) {

charCount.put(c, charCount.get(c) + 1);

} else {

charCount.put(c, 1);

}
// Print duplicate characters and their counts

System.out.println("Duplicate characters in the string:");

for (Map.Entry<Character, Integer> entry : charCount.entrySet()) {

if (entry.getValue() > 1) {

System.out.println(entry.getKey() + ": " + entry.getValue());

Checking symmetric in array

public class CheckSymmetry {

public static void main(String[] args) {

int[] arr = {1, 2, 3, 3, 2, 1};

boolean isSymmetric = true;

// Check symmetry by comparing elements from both ends

for (int i = 0; i < arr.length / 2; i++) {

if (arr[i] != arr[arr.length - 1 - i]) {

isSymmetric = false;

break;

if (isSymmetric) {

System.out.println("The array is symmetric.");

} else {

System.out.println("The array is not symmetric.");

}
}

1. Different Types of Testing:


 Unit Testing: Testing individual units or components of a
software application in isolation to ensure they function
correctly.
 Integration Testing: Testing the integration and interaction
between different modules or components to verify that they
work together as expected.
 System Testing: Testing the entire system as a whole to
evaluate its compliance with specified requirements.
 Acceptance Testing: Testing conducted to determine whether
a system satisfies acceptance criteria and is ready for
deployment.
 Functional Testing: Testing the functional requirements of a
system to ensure that it performs as expected.
 Non-functional Testing: Testing aspects of a system such as
performance, scalability, reliability, and security.
 Regression Testing: Testing performed to ensure that changes
or enhancements to a system have not adversely affected
existing functionality.
 Smoke Testing: A preliminary testing phase aimed at quickly
determining whether the software build is stable enough for
further testing.
 Load Testing: Testing the system's behavior under normal and
peak load conditions to assess its performance and scalability.
 Security Testing: Testing the system for vulnerabilities and
weaknesses to ensure that it is secure against unauthorized
access and attacks.
 Usability Testing: Testing conducted to evaluate the user-
friendliness and ease of use of the system.
 Accessibility Testing: Testing conducted to ensure that the
system is accessible to users with disabilities and meets
accessibility standards.
2. Regression Testing:
 Regression testing is a type of software testing that verifies
that recent code changes have not adversely affected existing
functionality. It involves re-running previously executed test
cases to ensure that previously developed and tested software
still performs correctly after a change. The goal of regression
testing is to catch defects that may have been inadvertently
introduced while making changes to the software or fixing bugs.
Regression testing is essential for maintaining software quality
and ensuring th at new developments do not cause regression
errors.

A test cycle, also known as a testing cycle or test phase, is a distinct phase in
the software testing process that encompasses specific activities aimed at
ensuring the quality and reliability of the software product. The test cycle
typically occurs within the larger software development life cycle (SDLC) and
may vary in duration and complexity based on project requirements and
testing methodologies. Here's an overview of the typical stages involved in a
test cycle:

1. Test Planning:
 In this initial stage, the testing team collaborates with
stakeholders to define the objectives, scope, and approach for
testing. Test plans and strategies are developed outlining the
testing activities, resources, timelines, and deliverables.
2. Test Case Design:
 Test cases are designed based on requirements, specifications,
and user stories. Test scenarios are identified, and test cases are
created to validate the functionality, features, and performance
of the software application.
3. Test Environment Setup:
 The testing environment, including hardware, software, and test
data, is set up to mimic the production environment as closely as
possible. This ensures that tests are conducted under realistic
conditions and that the results are reliable.
4. Test Execution:
 Test cases are executed according to the test plan and schedule.
Testers run the tests, record test results, and document any
defects or issues encountered during testing. Both manual and
automated testing techniques may be employed during this
stage.
5. Defect Management:
 Defects identified during test execution are logged, tracked, and
prioritized using a defect tracking system or issue management
tool. Defects are assigned to developers for resolution, and the
testing team verifies fixes once they are implemented.
6. Regression Testing:
 As changes are made to the software during the development
process, regression testing ensures that existing functionality
has not been negatively impacted. Previously executed test
cases are re-run to confirm that no regression errors have been
introduced.
7. Test Reporting:
 Test results, including test execution status, defect metrics, and
other key performance indicators, are compiled and reported to
stakeholders. Test reports provide insights into the quality of the
software, identify areas of improvement, and inform decision-
making.
8. Test Closure:
 The test cycle concludes with a formal review of testing activities
and deliverables. Test closure activities may include
documenting lessons learned, archiving test artifacts, and
conducting post-mortem meetings to assess the effectiveness of
the testing process.

Throughout the test cycle, collaboration, communication, and coordination


among team members are essential to ensure that testing objectives are
met, defects are addressed promptly, and the software product meets
quality standards and user expectations.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy