Login / Register |
4 Years Experience SDET with Selenium4
#java #automation #EY #sdet #selenium #bdd
Posted by TechElliptica at 01 Jul 2025 ( Day(s) Before)

What is the purpose of the static keyword in Java.

The static keyword in Java is used to define members that belong to the class rather than any instance. A static variable is shared across all instances of a class, and a static method can be called without creating an object. It's useful for utility methods, constants, or shared data.

static keyword is shared and class member


For example, Math.max() is a static method because it doesn't require an object to be use


Where static Can Be Used:

Use Case

Description

static variable

Shared by all instances of a class (also called class variables).

static method

Can be called without creating an object of the class.

static block

Executes once when the class is loaded (used for static initialization).

static class

Inner classes can be declared static (called static nested classes).


Examples:

1. Static Variable

class Employee {
static String company = "ABC Corp"; // shared across all employees
String name;
}


2. Static Method

class MathUtils {
static int square(int x) {
return x * x;
}
}
int result = MathUtils.square(5);


3. Static Block

class Config {
static {
System.out.println("Static block executed!");
}
}

What does the term "Velocity" refer to in Agile Testing?

What is Velocity in Agile Testing?

  1. Velocity refers to the amount of work a team completes during a sprint.
  2. It's usually measured in story points, hours, or number of user stories.
  3. It helps predict how much work the team can handle in future sprints.


How is Velocity Calculated?

At the end of each sprint:

Velocity = Total Story Points Completed in the Sprint

For example, if your team completes 5 user stories totaling 30 story points in a 2-week sprint, the velocity is 30.


In Agile Testing, velocity refers to the number of story points or work items a team completes in a sprint. It helps gauge the team’s performance and is used to forecast how much work can be taken on in future sprints. For example, if we consistently complete around 25–30 story points per sprint, that becomes our average velocity and guides our planning.


What does the following statement mean

WebDriver driver = new FirefoxDriver();

Explanation of

WebDriver driver = new FirefoxDriver();
  1. WebDriver is an interface in Selenium that defines the methods for browser automation (like get(), findElement(), click(), etc.).
  2. driver is the reference variable of type WebDriver.
  3. new FirefoxDriver() creates an instance of the Firefox browser driver (the concrete class that implements the WebDriver interface specifically for Firefox).
  4. This line essentially launches a new Firefox browser window controlled by Selenium.


Why use this?

  1. By coding to the WebDriver interface, you can easily switch browsers by just changing the instantiation part (new ChromeDriver(), new EdgeDriver(), etc.) without changing the rest of your test code.
  2. This promotes code flexibility and reusability.


Could you explain the difference between getWindowHandle() and getWindowHandles() in Selenium?

getWindowHandle()

  1. Returns a String representing the unique identifier (handle) of the current browser window that the WebDriver is controlling.
  2. Use this when you want to keep track of or switch back to the current window.
  3. Example use: Saving the parent window handle before opening a new window.


getWindowHandles()

  1. Returns a Set<String> containing the handles of all open browser windows/tabs initiated by the WebDriver session.
  2. Use this to get all available windows so you can switch between them.
  3. Helpful when a new window or tab opens, and you need to identify and switch to it.


Method

Returns

Use Case

getWindowHandle()

String (current window)

Store or switch back to the current window

getWindowHandles()

Set (all windows)

Iterate and switch between multiple windows


getWindowHandle() returns the unique handle of the current window the driver is focused on, which is useful to store so you can switch back to it later. getWindowHandles() returns a set of all window handles opened by the WebDriver, allowing you to iterate through them and switch between multiple windows or tabs.

Could you write a Selenium snippet for performing below actions

Handling a child window,
Performing operations
Switching back to the parent window

Approach of the program:



  1. getWindowHandle() returns the current window’s unique ID.
  2. getWindowHandles() returns a set of all open window handles.
  3. We switch to the window handle that is not the parent to get the child window.
  4. After operations, we close the child window (optional) and switch back to the parent window.



// Assume driver is your WebDriver instance and already initialized

// Step 1: Get the current window handle (parent window)
String parentWindowHandle = driver.getWindowHandle();

// Step 2: Perform action that opens new window/tab
driver.findElement(By.id("openChildWindowBtn")).click(); // Example button that opens child window

// Step 3: Get all window handles
Set<String> allWindowHandles = driver.getWindowHandles();

// Step 4: Loop through handles and switch to the child window
for (String windowHandle : allWindowHandles) {
if (!windowHandle.equals(parentWindowHandle)) {
driver.switchTo().window(windowHandle);
break;
}
}

// Step 5: Perform operations on child window
driver.findElement(By.id("childWindowInput")).sendKeys("Sample text");
driver.findElement(By.id("childWindowSubmit")).click();

// Step 6: Close child window (optional)
driver.close();

// Step 7: Switch back to the parent window
driver.switchTo().window(parentWindowHandle);

// Now you can continue working in the parent window
System.out.println("Switched back to parent window.");

What does the super() keyword do in Java?

What does super() do?


super() is used to call the constructor of the parent (super) class.
It allows a subclass to initialize the inherited fields or behavior by invoking the parent class constructor.
It must be the first statement in the subclass constructor if used.
If you don’t explicitly call super(), Java automatically inserts a no-argument call to the parent’s constructor.


Why use super()?

  1. To reuse the parent class constructor code.
  2. To ensure the parent class is properly initialized before the subclass adds its own initialization.


Example:

class Animal {
Animal() {
System.out.println("Animal constructor called");
}
}

class Dog extends Animal {
Dog() {
super(); // Calls Animal() constructor
System.out.println("Dog constructor called");
}
}

public class Test {
public static void main(String[] args) {
Dog dog = new Dog();
}
}


super() is a keyword in Java used to call the constructor of the parent class from the subclass constructor.

This allows the subclass to initialize the parent class before executing its own constructor logic.

It helps in code reuse and ensures proper object initialization in inheritance hierarchies.

Could you provide an example of a High Priority but Low Severity Bug?



Imagine your web application has a typo in the company logo text on the homepage.

  1. The typo does not affect functionality at all (so technically, the bug has low severity).
  2. However, since this page is visible to all users and affects the company’s brand image, the product owner wants it fixed immediately to avoid a bad impression — so it has high priority.


How would you define the Severity and Priority of a Bug?

What is Severity?


Severity refers to the impact of the bug on the system or application.
It indicates how serious the bug is from a technical perspective.
Usually assigned by testers or developers.


Example:

Severity Level

Description

Critical

Crash or data loss, app unusable

Major

Major functionality broken

Minor

Minor impact, non-blocking bugs

Trivial

Cosmetic issues, typos, UI glitches


What is Priority?


Priority indicates how soon the bug should be fixed.
It’s a business decision, usually set by the product owner or manager.
Priority is about the order of fixing bugs based on business needs.


Example:

Priority Level

Description

High

Must fix immediately

Medium

Fix in upcoming releases

Low

Can be fixed later



Severity defines how badly a bug affects the application’s functionality or system, for example, a crash or data loss would be critical severity. Priority, on the other hand, indicates how quickly the bug should be fixed based on business needs. A cosmetic bug may have low severity but could have high priority if it affects customer perception. Severity is usually assigned by testers or developers, while priority is decided by product owners or project managers.

What is the Action class in Selenium, and could you mention a few of its methods?

What is the Actions Class?

  1. It’s a class provided by Selenium WebDriver for building a sequence of actions like drag-and-drop, mouse hover, right-click, double-click, and keyboard key presses.
  2. It helps automate advanced user gestures in web applications.



How to Use Actions Class:

You first create an Actions object and then build a chain of actions which can be performed together.


Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();


Commonly Used Methods in Actions Class:

Method

Description

moveToElement(WebElement)

Moves the mouse to the middle of the element (mouse hover)

click()

Clicks at the current mouse location

click(WebElement)

Clicks on a specific element

contextClick()

Performs right-click

doubleClick()

Performs double-click

dragAndDrop(source, target)

Drags an element and drops it onto another element

sendKeys(CharSequence)

Sends keyboard keys to the active element

keyDown(Keys)

Presses a keyboard key without releasing it

keyUp(Keys)

Releases a pressed keyboard key


The Actions class in Selenium is used for performing advanced user interactions like mouse hover, drag and drop, right-click, and keyboard events which are not possible with regular WebDriver methods.

For example, to perform a mouse hover, we use moveToElement(), or to drag and drop elements, we use dragAndDrop(source, target). These actions are built as a sequence and executed using build().perform().

What are the advantages and disadvantages of using Automation Frameworks?

Automation frameworks offer significant advantages by providing a structured and reusable foundation for writing test scripts, which improves consistency, maintainability, and scalability of automated tests. They help teams achieve faster test execution, better coverage, and easier integration with CI/CD pipelines, ultimately accelerating the software delivery process. Frameworks also promote standard coding practices, enhance collaboration among testers and developers, and often come with built-in reporting and logging features that simplify defect tracking and debugging.


However, automation frameworks also have drawbacks, including the initial setup cost and the time required to design and implement them properly. They can introduce complexity, especially if over-engineered or not tailored to the project’s needs, making them harder for new team members to learn. Additionally, maintaining the framework alongside evolving applications may require continuous effort, and if the application under test changes frequently, it can lead to fragile scripts and higher maintenance overhead.

What factors should be considered when selecting an automation tool?

When selecting an automation tool, I consider several factors. First, the tool must support the type of application we’re testing — whether web, mobile, or desktop. It should be compatible with our technology stack and easy for the team to learn and use. Integration with CI/CD pipelines like Jenkins and test management tools like JIRA is also important for smooth workflows.

Additionally, cross-browser and cross-platform support ensures our tests cover all user environments. Maintenance ease and scalability matter since our application evolves frequently. Cost is also a factor — open-source tools like Selenium are popular for their zero licensing cost.

Finally, good reporting features, community support, and performance help ensure reliable and efficient automation.

What is an Abstract Class and an Abstract Method?

1. What is an Abstract Class?


An abstract class is a class that cannot be instantiated on its own — it’s meant to be inherited by other classes. It can contain:

  1. Abstract methods (no body — just declared)
  2. Concrete methods (with full implementation)

Purpose: To define a common base for other classes with shared behavior, while leaving some details to be defined in child classes.


Example in Java:

public abstract class BaseTest {
public void openBrowser() {
System.out.println("Opening browser...");
}

// Abstract method
public abstract void runTest(); // No implementation
}


2. What is an Abstract Method?


An abstract method is a method that:

  1. Has no body (just a signature).
  2. Must be implemented in a subclass.


Only abstract classes can contain abstract methods.


public abstract void runTest(); // No method body


Then, in a subclass:


public class LoginTest extends BaseTest {
public void runTest() {
System.out.println("Running login test");
}
}


An abstract class in Java is a class that can’t be instantiated and may contain both abstract and non-abstract methods. Abstract methods are declared without a body and must be implemented by the subclass.


In automation frameworks, we often use an abstract base class to define common setup or teardown logic, and leave methods like runTest() abstract.

That way, child classes implement their specific test logic, promoting reusability and structure.