0% found this document useful (0 votes)
15 views9 pages

Automation Tester Questions Set #1 2024

The document contains various Java programming examples and concepts, including methods for removing duplicate characters from a string, generating prime numbers, and finding missing values in an array. It also discusses design patterns like Singleton, serialization, and differences between Selenium versions, as well as TestNG features like parameter passing and retry logic. Additionally, it covers object-oriented programming principles and the Java Collections Framework.

Uploaded by

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

Automation Tester Questions Set #1 2024

The document contains various Java programming examples and concepts, including methods for removing duplicate characters from a string, generating prime numbers, and finding missing values in an array. It also discusses design patterns like Singleton, serialization, and differences between Selenium versions, as well as TestNG features like parameter passing and retry logic. Additionally, it covers object-oriented programming principles and the Java Collections Framework.

Uploaded by

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

Want to become a Job Ready Automation Tester in 4 months?

Course Join - https://sdet.live/become

### Java program to remove duplicates characters from given String.

public class RemoveDuplicates {


public static String removeDuplicates(String str) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
char current = str.charAt(i);
if (result.indexOf(String.valueOf(current)) == -1) {

y
result.append(current);

m
}
}
return result.toString();

de
}

public static void main(String[] args) {

}
ca
String input = "hello";
System.out.println(removeDuplicates(input)); // Output: helo
gA
}

### Program Remove the second highest element from the HashMap.
tin

import java.util.*;

public class RemoveSecondHighest {


es

public static void main(String[] args) {


HashMap<Integer, String> map = new HashMap<>();
map.put(1, "One");
eT

map.put(2, "Two");
map.put(3, "Three");
Th

Collection<String> values = map.values();


ArrayList<String> list = new ArrayList<>(values);
list.sort(Comparator.reverseOrder());

if (list.size() > 1) {
System.out.println("Second highest element: " + list.get(1));
} else {
System.out.println("HashMap doesn't have a second highest element.");
}
}
}
### Java program to Generate prime numbers between 1 & given 4 number

public class GeneratePrimes {


public static void main(String[] args) {
int n = 20;
System.out.println("Prime numbers between 1 and " + n + ":");
for (int i = 2; i <= n; i++) {
if (isPrime(i)) {
System.out.print(i + " ");
}

y
}

m
}

private static boolean isPrime(int num) {

de
if (num <= 1) return false;
for (int i = 2; i <= Math.sqrt(num); i++) {
if (num % i == 0) return false;

}
} ca
return true;
gA
}

### How to find the missing values from a sorted array.


tin

public class MissingValues {


public static void main(String[] args) {
int[] array = {1, 2, 3, 5, 7, 9}; // Example sorted array
es

int n = array.length + 1;
int totalSum = n * (n + 1) / 2;
int arraySum = 0;
eT

for (int num : array) {


arraySum += num;
}
Th

int missingValue = totalSum - arraySum;


System.out.println("Missing value in the array: " + missingValue);
}
}

### Java program to input name, middle name and surname of a person and print
only the initials.

import java.util.Scanner;

public class PrintInitials {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter first name, middle name, and last name: ");
String firstName = scanner.next();
String middleName = scanner.next();
String lastName = scanner.next();
System.out.println("Initials: " + firstName.charAt(0) + middleName.charAt(0) +
lastName.charAt(0));
}
}

y
m
### Program to Print all TreeMap elements?

import java.util.*;

de
public class PrintTreeMapElements {
public static void main(String[] args) {
ca
TreeMap<Integer, String> treeMap = new TreeMap<>();
treeMap.put(1, "One");
treeMap.put(2, "Two");
gA
treeMap.put(3, "Three");

for (Map.Entry<Integer, String> entry : treeMap.entrySet()) {


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

}
}
}
es

### What is a singleton Design Pattern? How do you implement that in your
framework?
eT

Singleton pattern ensures that a class has only one instance and provides a global
point of access to that instance.
Th

Here's an example implementation:

public class Singleton {


private static Singleton instance;

private Singleton() {}

public static Singleton getInstance() {


if (instance == null) {
instance = new Singleton();
}
return instance;
}
}

### Write the Top 5 test cases for Booking Coupons.


1. Test case to verify that a coupon is successfully applied to the booking.
2. Test case to ensure that an expired coupon cannot be applied.
3. Test case to validate the discount amount applied after using a coupon.
4. Test case to check if the correct error message is displayed when an invalid coupon code
is entered.
5. Test case to verify that the coupon usage limit is correctly enforced.

y
### What is serialization and deserialization?

m
Serialization is the process of converting an object into a stream of bytes to store it in
memory, a file, or to transmit it over a network. Deserialization is the process of
reconstructing the object from the serialized form.

de
### What is the Difference between status codes 401 and 402?
- 401 Unauthorized: It indicates that the request has not been applied because it lacks valid
ca
authentication credentials for the target resource.
- 402 Payment Required: This status code is reserved for future use and is intended to be
used when the functionality it represents is implemented.
gA
### Difference between selenium 3 and selenium 4?
Selenium 4 introduced several new features and improvements over Selenium 3, including:
- Native support for Chrome DevTools Protocol.
tin

- Improved W3C WebDriver support.


- Updated Selenium Grid architecture.
- New Selenium IDE with enhanced capabilities.
es

### What is delegate in Java and where do you use Delegate in your Framework?
In Java, there is no direct equivalent to delegates in languages like C#. However, a similar
eT

concept can be achieved using interfaces or functional interfaces. In my framework, I might


use interfaces to define callback mechanisms or event handling.
Th

Example:

public interface TaskDelegate {


void onComplete();
}

public class TaskRunner {


public void runTask(TaskDelegate delegate) {
// Execute some task
System.out.println("Task completed.");
delegate.onComplete();
}
}

public class Main {


public static void main(String[] args) {
TaskRunner taskRunner = new TaskRunner();
taskRunner.runTask(() -> System.out.println("Task callback executed."));
}
}

### How many maximum thread-pool can you open in the TestNG?
The maximum number of threads in a TestNG thread pool is determined by the parameter

y
`thread-count` in the testng.xml file or programmatically through the TestNG API. It depends

m
on the hardware resources available and the nature of tests being executed.

### What are the Major challenges that come into the picture when you do parallel

de
testing using TestNG and Grid?
Some major challenges of parallel testing using TestNG and Grid include:
- Synchronization issues: Ensuring proper synchronization between tests running
ca
concurrently.
- Resource contention: Managing shared resources such as database connections or files.
- Test data isolation: Preventing interference between tests that manipulate common data.
gA
- Logging and reporting: Consolidating logs and reports from parallel executions for easy
analysis.
- Scalability: Ensuring the testing infrastructure can scale efficiently as the number of parallel
executions increases.
tin

### How do you integrate your automation framework with the Jenkins pipeline?
Integration with Jenkins pipeline involves creating Jenkinsfile and configuring Jenkins to
execute the pipeline. Steps include:
es

1. Define stages: Define stages such as build, test, and deploy in the Jenkinsfile.
2. Configure build steps: Specify commands to build and execute tests in each stage.
3. Add post-build actions: Include actions like archiving artifacts and triggering downstream
eT

jobs.
4. Configure Jenkins job: Create a Jenkins job and link it to the repository containing the
Jenkinsfile.
Th

5. Run pipeline: Execute the pipeline to build, test, and deploy the application.

Example Jenkinsfile:
groovy
pipeline {
agent any
stages {
stage('Build') {
steps {
// Build commands
}
}
stage('Test') {
steps {
// Test execution commands
}
}
stage('Deploy') {
steps {
// Deployment commands
}
}
}
}

y
m
de
### What will happen if we remove the main method from the Java program?
If you remove the `main` method from a Java program, the program won't have an entry
point, and it won't be executable as a standalone application. You'll encounter a compilation
ca
error indicating that the main method is not found. The `main` method serves as the starting
point for execution in Java applications.
gA
### What is the component of your current Project?
The components of my current project include:
- User interface (UI) layer: Responsible for user interaction and presentation.
- Business logic layer: Contains the core business rules and processing logic.
tin

- Data access layer: Handles data storage, retrieval, and manipulation.


- Test automation framework: Facilitates automated testing of the application.
- Integration layer: Manages communication between different system components and
external services.
es

- Logging and monitoring: Tracks application behavior and performance for analysis and
troubleshooting.
eT

### How do you pass parameters in TestNG?


You can pass parameters in TestNG using the `@Parameters` annotation and by specifying
parameter values in the testng.xml file or through the TestNG API.
Th

Example:

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class ParameterizedTest {


@Test
@Parameters("browser")
public void testWithParameter(String browser) {
System.out.println("Executing test on " + browser);
// Test logic using the specified browser
}
}

testng.xml:
xml
<suite name="Test Suite">
<test name="Parameterized Test">
<parameter name="browser" value="Chrome"/>
<classes>
<class name="ParameterizedTest"/>
</classes>
</test>

y
</suite>

m
### Write the logic of retrying the failed test case with a minimum of 3 numbers of

de
times in Automation Testing. Which Interface do you use for it?
You can implement retry logic using the `IRetryAnalyzer` interface provided by TestNG.

Example: ca
import org.testng.IRetryAnalyzer;
gA
import org.testng.ITestResult;

public class RetryAnalyzer implements IRetryAnalyzer {


private int retryCount = 0;
tin

private static final int MAX_RETRY_COUNT = 3;

@Override
public boolean retry(ITestResult result) {
es

if (retryCount < MAX_RETRY_COUNT) {


retryCount++;
return true;
eT

}
return false;
}
Th

Usage:

import org.testng.annotations.Test;

public class MyTest {


@Test(retryAnalyzer = RetryAnalyzer.class)
public void testMethod() {
// Test logic
}
}
### What is the OOPs concept in Java?
Object-oriented programming (OOP) is a programming paradigm based on the concept of
"objects", which can contain data in the form of fields (attributes or properties), and code, in
the form of procedures (methods or functions). Java supports the following OOP concepts:

1. Encapsulation: Bundling of data and methods that operate on the data into a single unit
(class).
2. Inheritance: Mechanism by which one class can inherit properties and behavior from

y
another class.

m
3. Polymorphism: Ability of objects to take on multiple forms based on their context.
4. Abstraction: Process of hiding the implementation details and showing only the essential
features of an object.

de
5. Class: Blueprint for creating objects, which defines its properties and behaviors.
6. Object: Instance of a class that encapsulates data and methods.
7. Method: Function defined within a class to perform certain actions.
ca
### Difference Between Classes and Objects?
- Class: A class is a blueprint or template for creating objects. It defines the properties and
gA
behaviors common to all objects of that type.
- Object: An object is an instance of a class. It represents a specific entity in memory and
has its own set of properties and behaviors.
tin

### What is collection in Java?


In Java, a collection is a framework that provides an architecture to store and manipulate a
group of objects. The Java Collections Framework (JCF) provides a set of interfaces (e.g.,
List, Set, Map) and classes (e.g., ArrayList, HashSet, HashMap) to represent collections and
es

perform common operations like insertion, deletion, and traversal.

### In How many ways can we create an object?


eT

In Java, there are several ways to create objects:


1. Using the new keyword: `ClassName obj = new ClassName();`
2. Using newInstance() method of Class class: `ClassName obj = (ClassName)
Th

Class.forName("ClassName").newInstance();`
3. Using clone() method: `ClassName obj2 = (ClassName) obj1.clone();` (Requires
implementing Cloneable interface)
4. Using deserialization: Read object from file or stream using ObjectInputStream.
5. Using factory method: Define static factory methods within the class to create objects.
6. Using dependency injection frameworks: Let frameworks like Spring manage object
creation and injection.

### Why is Java not 100% Object-oriented?


Java is considered mostly object-oriented, but not 100% due to the following reasons:
1. Primitive data types: Java has primitive data types like int, double, etc., which are not
objects.
2. Static members and methods: Static members and methods belong to the class rather
than individual objects, breaking the paradigm of object-oriented programming.
3. Wrapper classes: Although Java has wrapper classes for primitive types (e.g., Integer,
Double), they are not true objects in the sense of user-defined classes.

y
m
de
ca
gA
tin
es
eT
Th

You might also like