Types of Testing:
Start WebDriver:
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") +
"/src/test/resources/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5000));
driver.manage().window().maximize();
driver.navigate().refresh();
driver.get("https://google.com");
JavascriptExecutor:
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement searchBox = driver.findElement(By.xpath("//*[@name='q']"));
js.executeScript("arguments[0].click();", searchBox);
TakesScreenshot:
TakesScreenshot sc = (TakesScreenshot)driver;
File screenshot = sc.getScreenshotAs(OutputType.FILE);
File destFile = new File("E:\\"+"/Screen.png");
Files.copy(screenshot, destFile);
Wait:
Implicit:
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5000));
Explicit:
Wait<WebDriver> wait = new WebDriverWait(driver,Duration.ofSeconds(5000));
WebDriverWait wait1 = new WebDriverWait(driver,Duration.ofSeconds(5000));
wait.until(ExpectedConditions.visibilityOf(searchBox));
Fluent:
Wait<WebDriver> fluent = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(10))
.pollingEvery(Duration.ofSeconds(1))
.ignoring(ElementNotInteractableException.class);
TestNG Parallel Testing
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite thread-count="2" parallel="methods" name="Suite">
<parameter name="browsers" value="chrome"></parameter>
<test thread-count="2" parallel="tests" name="Test">
<packages>
<package name="com.mani"/>
</packages>
</test> <!-- Test -->
</suite> <!-- Suite -->
Challenges of selenium:
Selenium challenges include browser compatibility, dynamic content handling, synchronization issues,
pop-up management, complex locators, and test maintenance requirements.
Check Broken Links:
public class CheckBrokenLinks extends BaseTest {
@Test
public void getAllLinks() {
driver.get("https://bstackdemo.com/");
List<WebElement> links = driver.findElements(By.tagName("a"));
// Iterating each link and checking the response status
for (WebElement link : links) {
String url = link.getAttribute("href");
verifyLink(url);
}
driver.quit();
}
public static void verifyLink(String url) {
try {
URL link = new URL(url);
HttpURLConnection httpURLConnection = (HttpURLConnection)
link.openConnection();
httpURLConnection.setConnectTimeout(3000); // Set connection timeout to 3
seconds
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
System.out.println(url + " - " +
httpURLConnection.getResponseMessage());
} else {
System.out.println(url + " - " + httpURLConnection.getResponseMessage()
+ " - " + "is a broken link");
}
} catch (Exception e) {
System.out.println(url + " - " + "is a broken link");
}
}
Remove space from String:
package com.mani;
public class RemoveSpaceFromString {
public static void main(String[] args) {
String s = "G ee ks f or e e k s";
//s=s.replaceAll(" ", "");
s=s.replaceAll("\\s", "");
System.out.println(s);
List of common WebDriver exceptions:
NoSuchElementException - When an element is not found in the DOM
TimeoutException - When a command takes too long to complete
StaleElementReferenceException - When an element is no longer attached to the DOM
ElementNotVisibleException - When an element is present in the DOM but not visible
ElementNotInteractableException - When an element is present in the DOM but not interactable
InvalidElementStateException - When an element is in an invalid state for the command
InvalidSelectorException - When an invalid selector is used
NoSuchWindowException - When a window is not found
SessionNotFoundException - When a session is not found
UnhandledAlertException - When an unexpected alert is present
WebDriverException - General exception for WebDriver errors
To get all elements on a webpage using Java and Selenium, use driver.findElements(By.xpath("//*")) to
select all elements and then iterate through them to retrieve their tag names.
When committing code, you might face issues like overlapping changes from different team members,
forgetting to include important updates, or having unclear commit messages. There can also be
permission problems, network issues, and confusion over multiple branches. These challenges can
complicate teamwork and make tracking changes harder.
What are HTTP methods in API Testing?
In API testing, HTTP methods define the actions that can be performed on resources. Here are the
primary HTTP methods used:
GET: Retrieves data from a server. It should not alter any data. For example, fetching user details.
POST: Sends data to the server to create a new resource. For instance, submitting a registration form.
PUT: Updates an existing resource or creates it if it doesn’t exist. It replaces the entire resource with the
provided data.
PATCH: Partially updates a resource. Unlike PUT, it only sends the changes rather than the entire
resource.
DELETE: Removes a resource from the server. For example, deleting a user account.
HEAD: Similar to GET but retrieves only the headers, not the body. It’s useful for checking if a resource
exists.
OPTIONS: Describes the communication options for the target resource, allowing clients to discover
supported methods.
TRACE: Echoes back the received request for diagnostic purposes, mainly used for debugging.
Where you used oops concepts in Selenium framework?
I used OOPs concepts in my framework for creating reusable components, inheritance, and
encapsulation.
Used inheritance to create a base test class with common methods and properties.
Implemented encapsulation to hide the internal details of the test cases.
Utilized polymorphism for creating different types of test cases using the same interface.
How postman helps for API testing?
Postman helps in API testing by providing a user-friendly interface to send requests, automate testing,
and analyse responses.
Postman allows testers to easily send requests to APIs and view responses in a user-friendly
interface.
It provides features for automating API testing, such as creating test scripts and running
collections of tests.
Postman also offers tools for analysing responses, including detailed logs and test reports.
It supports various authentication methods, environment variables, and integrations with other
testing tools.
Overall, Postman simplifies the process of API testing and helps testers efficiently validate the
functionality of APIs.
Purpose of pass, break and continue keywords:
The pass, break, and continue keywords are used in programming to control the flow of execution in
loops and conditional statements.
The pass keyword is used as a placeholder for code that will be implemented later.
The break keyword is used to exit a loop or switch statement.
The continue keyword is used to skip the rest of the current iteration and move to the next
iteration in a loop.
Enum:
Enum is a special data type in Java used to define a set of constants.
Enums can be used to create a set of related constants that can be used throughout the code.
Enums can have constructors, methods, and fields like a regular class.
Enums can be used in switch statements.
Example: enum Color { RED, GREEN, BLUE }
Example: Color c = Color.RED;
How to get URL of webpage?
System.out.println("CurrentURL: "+ driver.getCurrentUrl());
OR:
To get the URL of a webpage, you can use the window.location object in JavaScript.
Use window.location.href to get the full URL of the webpage
Use window.location.hostname to get the domain of the webpage
Use window.location.pathname to get the path of the webpage
Use window.location.protocol to get the protocol of the webpage (http or https)
Why string immutable in java ?
String is immutable in Java to ensure security, thread safety, and optimization.
Immutable strings prevent accidental modification of data.
Immutable strings can be safely shared among multiple threads.
Immutable strings allow for efficient memory allocation and caching.
Immutable strings are used in various security-related operations.
Immutable strings enable the use of string pooling for optimization.
Agile Process (Agile vs Waterfall model):
Agile is iterative and flexible, while Waterfall is sequential and rigid.
Agile involves continuous feedback and adaptation, while Waterfall follows a linear approach.
Agile allows for changes throughout the development process, while Waterfall requires detailed
planning upfront.
Agile promotes collaboration and communication among team members, while Waterfall has distinct
phases with limited interaction.
Agile is better suited for projects with evolving requirements, while Waterfall is ideal for projects with
well-defined scope.
what is Test closure?
Test closure is the final phase of the testing process where all testing activities are completed and the
testing team evaluates the testing process.
Test closure involves documenting the test results and preparing the final test closure report.
It includes analysing the test metrics to assess the quality of the testing process.
Test closure also involves releasing the test environment and resources used during testing.
It marks the end of the testing phase and ensures that all testing objectives have been met.
Pillar of OOPs:
1. Abstraction
Definition: Abstraction is the concept of hiding the complex implementation details and
showing only the essential features of an object.
Purpose: To reduce complexity and increase efficiency by exposing only necessary parts.
Implementation: Achieved through abstract classes and interfaces.
Example: An abstract class Vehicle with an abstract method move(), where subclasses like Car
and Bike provide specific implementations.
2. Encapsulation
Definition: Encapsulation is the bundling of data (attributes) and methods (functions) that
operate on that data into a single unit (class) while restricting direct access to some of the
object's components.
Purpose: To protect the internal state of an object and to control how the data is accessed or
modified.
Implementation: Achieved using access modifiers (private, public, protected) and providing
getter/setter methods.
Example: A BankAccount class with private fields for account number and balance, and public
methods to deposit and withdraw money.
3. Inheritance
Definition: Inheritance is the mechanism by which one class (subclass) can inherit fields and
methods from another class (superclass).
Purpose: To promote code reuse and establish a hierarchical relationship between classes.
Implementation: Achieved using the extends keyword for classes and the implements keyword
for interfaces.
Example: A class Dog that extends an abstract class Animal, inheriting its properties and
methods while also defining its specific behaviors.
4. Polymorphism
Definition: Polymorphism allows objects to be treated as instances of their parent class,
enabling a single interface to represent different underlying forms (data types).
Purpose: To provide a way to perform a single action in different forms and increase flexibility in
code.
Implementation: Achieved through method overloading (compile-time) and method overriding
(runtime).
Example: A method sound() in an Animal class that is overridden in subclasses Dog and Cat,
allowing for different implementations.
Summary Table
Concept Definition Purpose Implementation Example
Hiding complex Abstract class
Reduce
Abstraction details, exposing Abstract classes, interfaces Vehicle with method
complexity
essentials move()
Bundling data and
Protect internal Access modifiers, BankAccount with
Encapsulation methods, restricting
state getters/setters private balance field
access
Mechanism for one
Promote code
Inheritance class to inherit from extends keyword Dog extends Animal
reuse
another
Polymorphis Ability to treat Provide Method Method sound() in
Concept Definition Purpose Implementation Example
objects of different Animal, overridden
m flexibility overloading/overriding
types uniformly in Dog and Cat
Conclusion
In interviews, clearly articulate each concept's definition, purpose, implementation, and provide a
relevant example to demonstrate your understanding. This approach will help convey your knowledge
of OOP principles effectively!
Smoke Testing
Definition
Smoke Testing is a preliminary test to check the basic functionality of an application after a new
build or version is released. It's often referred to as a "build verification test."
Purpose
To ensure that the critical functionalities of the application are working correctly.
To verify that the build is stable enough for further testing.
Sanity Testing
Definition
Sanity Testing is a narrow and focused test conducted after receiving a software build to ensure
that a specific function or bug fix works as intended.
Purpose
To verify that a particular functionality is working after changes have been made (like bug fixes
or enhancements).
To check that the changes have not adversely affected other parts of the application.
Read Data from Excel:
static HashMap<String, String> mataTagsData;
public static HashMap<String, String> readFromExcel(String titleName) throws IOException{
mataTagsData = new HashMap<>();
DataFormatter formatter = new DataFormatter();
File file = new File("./TestData.xlsx");
FileInputStream fin = new FileInputStream(file);
XSSFWorkbook wb = new XSSFWorkbook(fin);
XSSFSheet sheet = wb.getSheetAt(0);
int rows = sheet.getLastRowNum();
for(int i=0;i<=rows;i++) {
String title = formatter.formatCellValue(sheet.getRow(i).getCell(1));
if(title.trim().equalsIgnoreCase(titleName)) {
int headingNo = sheet.getRow(0).getLastCellNum();
for (int j=0;j<headingNo;j++) {
mataTagsData.put(formatter.formatCellValue(sheet.getRow(0).getCell(j)),
formatter.formatCellValue(sheet.getRow(i).getCell(j)));
}
}
}
return mataTagsData;
}