Test Automation Complex Interview
Test Automation Complex Interview
com
9123820085
Test Automation
Complex Interview
QnA
kasper-analytics
kasperanalytics.com
9123820085
2. Encapsulations:
I. As Instance variables are the most important variable in your entire
app code. We ensure that instance variables are private and are
only accessed via getters and setters.
II. Example POJO Classes.
3. Inheritance:
I. In order to make code reusable we implement Child and Parent
Class relationship.
II. Test Base class is parent class for test classes IJson Is an interface
implement by all api pojo which helped in achieving loose coupling
4. Abstraction:
I. We have hidden the complexity of selenium, rest assured and
Appium by creating browser utility classes/android utility and api
helper classes
II. These classes have wrapped the complex selenium/restassured
and APPIUM code so that people who are writing test need not need
to learn or deal with any of these libraries. Hence in this way
abstraction was achieved.
kasper-analytics
kasperanalytics.com
9123820085
5. Polymorphism:
I. We have ensured that function names are reusable because it helps
in remembering less names and functionalities.
II. So, for that we did method overloading. That’s the compile time
polymorphism
6. PRO Tip
In order to use OOPs effectively we have ensured to use Design
Patterns for our classes. Design Pattern Comment
kasper-analytics
kasperanalytics.com
9123820085
kasper-analytics
kasperanalytics.com
9123820085
<dependency>
<groupId>org.codehaus.jackson</groupId>
kasper-analytics
kasperanalytics.com
9123820085
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
kasper-analytics
kasperanalytics.com
9123820085
Explain POJO ?
a. POJO stands for plain old java object
b. In POJO the instance variables of the class will be private
c. There will one or more parameterized constructor
d. There will be getters and setters for the setting and retrieving the
values of the instance variables
e. There will be a toString() to get the entire state of Object. (what are
the current values of the instance variables)
kasper-analytics
kasperanalytics.com
9123820085
the arraylist.
4. ArrayList is non-synchronized
5. Hence ArrayList is Fast in a MultiThreaded Program
II. LinkedList:
1. Linked List is another which implements List Interface
2. Linked List also implements Queue Interface
3. Linked List stores the data in a concept of node
4. A node consist of 3 things
a. Address of previous node
b. Data
c. Address to next node
5. Every node is connected with other node
and the data can be stored in different
memory addresses.
• Which means they can store duplicate values in them!
d. Set:
I. Set is a data structure which does not store duplicate values in
them
1. Set Interface is implemented by 2 classes
a. HashSet
I. HashSet is a class which
will store the data based on
the HashCode of the
elements
II. These HashCode helps in faster retrieval of values
III. Duplicate Values
cannot be stored
inside the HashSet
b. TreeSet:
I. TreeSet is a class which also implements Set Interface
II. TreeSet retrieves the value either in
1. Alphabetical or Ascending order of the value of elements
kasper-analytics
kasperanalytics.com
9123820085
1. Exception Hierarchy:
Throwable: The base class for all exceptions and errors in Java. Exception:
Represents recoverable issues within the application's control, like
NullPointerException or FileNotFoundException.
2. Exception Types:
Checked vs Unchecked:
Unchecked: Compiler doesn't force handling, but ignoring them can lead
to unpredictable behavior. Usually represent logic errors or invalid inputs.
Specific vs Generic:
kasper-analytics
kasperanalytics.com
9123820085
4. Best Practices:
Provide Informative Error Messages: Clearly explain the error to users and
developers. Test Exception Handling: Ensure your code handles expected
exceptions gracefully.
5. Architectural Patterns:
kasper-analytics
kasperanalytics.com
9123820085
kasper-analytics
kasperanalytics.com
9123820085
What it is:
How it works:
Key points:
kasper-analytics
kasperanalytics.com
9123820085
For simple scenarios where you expect minor delays in element loading.
To provide a basic level of synchronization for your tests.
When you need precise control over waiting for specific conditions like
element visibility or clickability.
When you want to avoid unnecessary delays in test execution.
When you're dealing with dynamic elements or unpredictable loading
times.
Best practices:
Example:
kasper-analytics
kasperanalytics.com
9123820085
Key Points:
Headless browsers run without a visible UI, making them ideal for
automated testing, web scraping, and performance optimization.
They offer faster execution, reduced resource consumption, and
compatibility with environments without display capabilities (e.g.,
servers).
Setting Up:
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
WebDriver driver = new ChromeDriver(options);
kasper-analytics
kasperanalytics.com
9123820085
Benefits:
kasper-analytics
kasperanalytics.com
9123820085
kasper-analytics
kasperanalytics.com
9123820085
Shadow DOM is a functionality that allows the web browser to render DOM
elements without putting them into the main document DOM tree. This
creates a barrier between what the developer and the browser can reach;
the developer cannot access the Shadow DOM the same way they would
with nested elements, while the browser can render and modify that code
the same way it would with nested elements
Shadow host: The regular DOM node to which the Shadow DOM is
attached. Shadow tree: The DOM tree inside the Shadow DOM.
Shadow boundary: The place where the Shadow DOM ends and the
regular DOM begins. Shadow root: The root node of the Shadow tree.
When we try to find the Shadow DOM elements using Selenium locators,
we get NoSuchElementException as it is not directly accessible to the
DOM.
kasper-analytics
kasperanalytics.com
9123820085
kasper-analytics
kasperanalytics.com
9123820085
Writing Code
You write the Java code using a text editor, just like writing a recipe
with instructions for the computer to follow.
Compilation
The compiler acts as your kitchen assistant. It takes the .java file and
checks for errors, like missing ingredients or mixing instructions.
Execution
The Java Virtual Machine (JVM) is like your oven. It takes the .class file
and executes the instructions step by step.
It brings your code to life, performing the actions you specified and
producing the desired output (like a delicious dish!).
Bytecode: The .class file contains bytecode, a special format that the JVM
kasper-analytics
kasperanalytics.com
9123820085
understands
Notes:
kasper-analytics
kasperanalytics.com
9123820085
if (sum == n) {
System.out.print(i + " is a perfect number");
} else {
System.out.print(i + " is not a perfect number");
}
Output:
Enter a number: 6
6 is a perfect number
kasper-analytics
kasperanalytics.com
9123820085
Output:
Enter a number: 4732
Each digits of given number are: 4 7 3 2
kasper-analytics
kasperanalytics.com
9123820085
int a, b;
int sum;
Scanner sc = new Scanner(System.in);
System.out.print("Enter any two integers: ");
a = sc.nextInt();
b = sc.nextInt();
sum = a - ~b - 1;
System.out.print("
Sum of two
integers: " +
sum);
}
Output:
kasper-analytics
kasperanalytics.com
9123820085
kasper-analytics
kasperanalytics.com
9123820085
Output:
1 | 2
2 | 4
8 | 1
3 | 1
5 | 1
public class
DuplicateElement {
public static void
main(String[] args) {
//Initialize array
int [] arr = new int [] {1, 2, 3, 4, 2, 7, 8, 8, 3};
System.out.println("Duplicate elements
in given array: ");
//Searches for duplicate
element for(int i = 0; i <
arr.length; i++) {
for(int j = i + 1; j <
arr.length; j++) {
if(arr[i] == arr[j])
System.out.println(arr[j]);
}
kasper-analytics
kasperanalytics.com
9123820085
Output:
kasper-analytics