Day 15 of 30
Day 15 of 30
Description: Each web page in the application is represented as a class, and the web
elements on the page are defined as variables within that class. Actions that can be performed
on those elements are defined as methods.
Benefits:
o Improves code readability and maintainability.
o Reduces code duplication.
o Easy to update in case of UI changes.
Description: This pattern is used in combination with POM for creating page objects. The
@FindBy annotations are initialized using the PageFactory class.
Benefits:
o Simplifies the object initialization process.
o Reduces boilerplate code.
Description: Ensures that only one instance of the WebDriver is created throughout the test
execution.
Benefits:
o Prevents multiple WebDriver instances from being created unnecessarily.
o Saves memory and improves performance.
Comparator:
Used to define custom sorting logic that can differ from natural ordering.
Sorting logic is external to the class, often implemented in a separate class.
Ans :
The finally block in Java is used to execute a block of code regardless of whether an exception is
thrown or not in the associated try block. It ensures cleanup or resource release operations are
performed, which is crucial for preventing resource leaks.
Q : What is 3 Amigos ?
Ans :
3 Amigos is a collaborative approach often used in Agile development to ensure a shared
understanding of requirements and improve the quality of deliverables. It involves three key roles
working together—Business Analyst (BA), Developer (Dev), and Tester (QA)—to refine user stories,
clarify requirements, and plan testing strategies.
Purpose of 3 Amigos
Q : In TestNg how will you ensure that screenshots will be taken only for fail test cases.
Ans :
To ensure that screenshots are taken only for failed test cases in TestNG, you can use the IListener
Interface, specifically the ITestListener implementation. Here's a step-by-step guide to achieve this:
1. Create a Listener Class: Implement the ITestListener interface and override the
onTestFailure() method to capture screenshots when a test case fails.
2. Write the Screenshot Logic: Use Selenium's TakesScreenshot interface to capture
screenshots in the onTestFailure() method.
3. Attach the Listener to Your Test Suite: Add the listener to your TestNG XML file or annotate
your test class with @Listeners.
Example :
@Override
public void onTestFailure(ITestResult result) {
captureScreenshot(result.getName());
}
try {
e.printStackTrace();
}
}
}
}
<listeners>
</listeners>
<classes>
</classes>
</test>
try {
URL(url).openConnection();
httpURLConnection.connect();
}
}
}
}
Q : You have 10 links how will you print title of each link using selenium. Give Optimal approach
Ans :
try {
}
}
}
}
A NullPointerException (NPE) in Java is a runtime exception that occurs when your code attempts to
use an object reference that has not been initialized or has been set to null. Essentially, it happens when
you try to call methods, access properties, or perform operations on an object that doesn't point to any
memory location (i.e., it is null).