Multiple Companys
Multiple Companys
Multiple Companys
Apache POI is an open-source Java library that allows users to create and
manipulate file formats based on Microsoft Office. It provides methods to create,
read, and write into Excel sheets. Apache POI uses interfaces and classes to handle
files in an application
It holds object of HSSFWorkbook class and provides methods to create, read and
write into the Excel sheet.
2. what is maven
Maven is an open-source build automation tool and project management tool used for
Java applications. It's written in Java and can also be used to build projects
written in other languages, such as C#, Scala, and Ruby.
5. what is xpath?
Absolute XPath: Starts from the root node and follows a path down to the desired
node. It begins with a single forward slash /.
Example:
/html/body/div[1]/form/input[2]
Relative XPath: Starts from any node in the XML structure and does not need to
begin from the root node. It does not start with a forward slash.
Example:
//input[@id='username']
Absolute XPath: Starts from the root node and follows a path down to the desired
node. It begins with a single forward slash /.
Example:
/html/body/div[1]/form/input[2]
Relative XPath: Starts from any node in the XML structure and does not need to
begin from the root node. It does not start with a forward slash.
Example:
//input[@id='username']
8. what in diff between method overloading and constructor overloading? with
example?
Constructor Overloading:
String:
The String class is immutable.
String is slow and consumes more memory when we concatenate too many strings
because every time it creates new instance.
String class overrides the equals() method of Object class. So you can compare the
contents of two strings by equals() method.
String class is slower while performing concatenation operation.
String class uses String constant pool.
StringBuffer:
Use explicit waits: Wait for the element to become clickable, visible, or present
on the page before interacting with it. You can use WebDriverWait in combination
with ExpectedConditions.
Use implicit waits: Set a timeout globally for WebDriver to wait for elements
before throwing an exception.
Unique Attributes:
Use XPath or CSS selectors to locate elements based on their position, relationship
with other elements, or any other unique characteristics. These locators can be
more flexible in handling dynamic elements than ID or class name.
Partial Match:
Identify a stable parent element and then navigate to the desired dynamic element
using XPath or CSS selectors. This ensures that even if the child element changes,
the parent's location remains constant.
Retry Mechanism:
Use the Page Object Model pattern to encapsulate web pages' functionality and
locators. This way, if the dynamic elements change, you only need to update the
page object class rather than changing tests' implementation.
import java.util.HashMap;
import java.util.Map;
Interface can have only abstract methods. Since Java 8, it can have default and
static methods also.
Interface supports multiple inheritance.
Interface has only static and final variables.
Interface can't provide the implementation of abstract class.
The interface keyword is used to declare interface.
An interface can extend another Java interface only.
An interface can be implemented using keyword "implements".
Members of a Java interface are public by default.
Definition final is the keyword and access modifier which is used to apply
restrictions on a class, method or variable.
Applicable to Final keyword is used with the classes, methods and variables.
final method cannot be overridden by sub class.
final class cannot be inherited.
Final method is executed only when we call it.
Once declared, final variable becomes constant and cannot be modified.
finally is the block in Java Exception Handling to execute the important code
whether the exception occurs or not.
Finally block is always related to the try and catch block in exception handling.
finally block runs the important code even if exception occurs or not.
Finally block is executed as soon as the try-catch block is executed.
finalize is the method in Java which is used to perform clean up processing just
before object is garbage collected.
finalize() method is used with the objects.
inalize method is executed just before the object is destroyed.
In Java, the main difference between a normal class and a final class is that a
final class cannot be subclassed. A final class is a complete and immutable class,
so data elements do not change by external access
Smoke test is done to make sure that the critical functionalities of the program
are working fine, whereas sanity testing is done to check that newly added
functionalities, bugs, etc., have been fixed. The software build may be either
stable or unstable during smoke testing.
===================================================================================
====
Bosch interview Qustions
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.ss.usermodel.*;
try {
FileInputStream fis = new FileInputStream(filePath);
Workbook workbook = WorkbookFactory.create(fis);
Sheet sheet = workbook.getSheetAt(0); // Assuming data is in the first
sheet
TestNG allows running the tests in parallel by setting the “parallel” attribute in
the “<suite>” tag respectively to “tests”, “methods”, “classes”, “instances”. As
per the setting provided to run the tests, it will start executing the tests in
separate threads.
</suite>
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
// Initialize ChromeDriver
WebDriver driver = new ChromeDriver();
// Navigate to the webpage with the auto-suggest dropdown
driver.get("url_of_the_webpage_with_auto_suggest_dropdown");
To generate daily execution reports in Selenium, you can use various reporting
frameworks and tools available in the Java ecosystem. One popular reporting
framework used with Selenium is ExtentReports. ExtentReports allows you to create
interactive and customizable HTML reports with detailed test execution results.
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.5</version>
<scope>test</scope>
</dependency>
testImplementation 'com.aventstack:extentreports:5.0.5'
Write Test Cases: Write your Selenium test cases using TestNG or JUnit.
Generate ExtentReports: Within your test methods, use ExtentReports API to create
and log test events (e.g., test pass, fail, skip) along with additional information
such as screenshots, logs, etc.
Techmetric interview
1. what is webdriver?
Headless Browser Support: WebDriver supports headless browser testing, enabling you
to run tests without opening a visible browser window. This is useful for running
tests in headless environments like CI/CD pipelines
try {
// Establish database connection
connection = DriverManager.getConnection(url, username, password);
// Execute a query
resultSet = statement.executeQuery("SELECT * FROM mytable");
3. Automation process?
collection is a frame work provided by java , this frame work provides many
interfaces and thair implimented classes in order to store group of objects
(eliments)
import java.util.ArrayList;
import java.util.Iterator;
// Remove an element
arrayList.remove("Banana");
System.out.println("After removing 'Banana': " + arrayList);
if (index != -1) {
System.out.println("Letter '" + searchChar + "' found at index: " +
index);
} else {
System.out.println("Letter '" + searchChar + "' not found in the
string.");
}
}
}
4.reverse a number?
package OOPS;
Page Object Model, also known as POM, is a design pattern in Selenium that creates
an object repository for storing all web elements. It helps reduce code duplication
and improves test case maintenance. In Page Object Model, consider each web page of
an application as a class file.
CSS selectors are generally faster than XPath. CSS selectors are unidirectional,
which allows them to search for elements in the DOM tree more quickly. CSS
selectors are also easier to learn and implement, and they're compatible with most
browsers.
However, XPath has wider document type compatibility than CSS selectors, which only
work with HTML documents. XPath also allows traversal from child to parent, which
CSS selectors do not
NoSuchElementException.
ElementNotVisibleException.
NoSuchFrameException.
NoAlertPresentException.
NoSuchWindowException.
SessionNotFoundException.
StaleElementReferenceException.
InvalidSelectorException.
The "catch" block is used to handle the exception. It must be preceded by try block
which means we can't use catch block alone. It can be followed by finally block
later. The "finally" block is used to execute the necessary code of the program.
Here's how you can generate a basic HTML report using TestNG:
Example testng.xml:
Dynamic Elements: Dealing with dynamic elements on web pages, such as changing IDs
or XPath, can make it difficult to locate elements consistently across test runs.
Test Data Management: Managing test data, especially for complex test scenarios or
environments with large datasets, can be challenging. Generating and maintaining
test data in a consistent and efficient manner is crucial for effective test
automation.
Maintenance of Test Scripts: As applications evolve over time, test scripts may
require frequent updates to adapt to changes in functionality, UI elements, or
underlying technologies. Keeping test scripts maintainable, reusable, and efficient
is an ongoing challenge in test automation.
Test Coverage and Prioritization: Ensuring adequate test coverage and prioritizing
tests based on risk, impact, and business requirements are important challenges in
test automation. Identifying critical test scenarios and optimizing test suites for
efficiency and effectiveness require careful planning and analysis.
Each web page is represented as a separate class: Each web page in the application
has its own corresponding class, called a Page Object. The Page Object encapsulates
the behavior and elements of that specific page.
Page Object contains web elements and methods: The Page Object class contains
methods to interact with the web elements present on the page, such as clicking
buttons, filling forms, or verifying page content. It also contains references to
the web elements, typically using locators such as XPath, CSS selectors, or IDs.
Tests interact with Page Objects: Test scripts interact with the application's web
pages by calling methods provided by the corresponding Page Objects. This promotes
code reusability and makes the tests more readable and maintainable.
Code Reusability: Page Objects encapsulate reusable code for interacting with web
elements, reducing duplication across tests.
Enhanced Maintainability: Updates or changes to web pages can be made in one place
(the corresponding Page Object), without impacting multiple test scripts.
Improved Readability: Tests written using Page Objects are more descriptive and
easier to understand, as they focus on high-level interactions with the application
rather than low-level implementation details.
Using JavaScript: You can execute JavaScript to set the value of the file input
element directly.
by using the actions class and robout class or by using the click method we can
upload a file
======================
Local variables: : These are declared inside a method, constructor, or block. They
are created when the method, constructor, or block is entered and destroyed when it
exits. Local variables are only visible within the declared method, constructor, or
block. They have no default value, so they should be declared and assigned an
initial value before the first use.
Instance variables: : These are declared inside a class outside of any method,
constructor, or block. They are created when an object of the class is created and
destroyed when the object is destroyed. Instance variables are accessible to all
methods and constructors of the class. They have a default value, which is 0 for
numeric variables and null for reference variables.
Static variables: : These are declared inside a class with the static keyword. They
are created when the class is loaded into memory and destroyed when the class is
unloaded from memory. Static variables are accessible to all methods and
constructors of the class, as well as to all objects of the class. They have a
default value, which is 0 for numeric variables and null for reference variables.
byte: 0
short: 0
int: 0
long: 0L
float: 0.0f
double: 0.0d
char: ‘\u0000’ (null character)
boolean: false
====================
what are the predefined classes in java
Predefined classes in Java are classes that are already defined in the Java
standard library and are available for use in your code. Predefined classes are
also known as built-in classes or standard classes. There are many predefined
classes in Java, each with its own set of methods and fields.
Some of the most commonly used predefined classes in Java include:
String: This class represents character strings and provides various methods for
manipulating strings.
Math: This class contains a set of mathematical functions and constants, such as
trigonometric functions, square root, and absolute value.
System: This class provides access to system resources, such as the console and the
file system.
Date: This class represents a date and time.
ArrayList: This class implements a resizable array.
HashMap: This class implements a hash table.
LinkedList: This class implements a linked list.
Predefined classes are a valuable resource for Java programmers, as they provide a
wide range of functionality that can be used to develop a variety of applications.
========================
The super calling statement in Java is a statement that is used to call the
constructor of the superclass from the subclass constructor. It is a reserved
keyword that is used to refer to the immediate parent class of the current class.
The syntax for the super calling statement is:
super();
The super calling statement must be the first statement in the subclass
constructor. If it is not, the compiler will generate an error. The super calling
statement can be used with or without arguments. If it is used with arguments, the
arguments must match the parameters of the superclass constructor.
The super calling statement is used to initialize the inherited members of the
subclass. It is also used to ensure that the superclass constructor is always
called, even if the subclass constructor does not explicitly call it.
super.methodName();