Login / Register |
5 Years Experience QA Automation with TestNG, Jenkins
#java #automation #selenium #QA
Posted by TechElliptica at 23 Jun 2025 ( Day(s) Before)

Do you use Page Object in your project? Suppose I want to add a new object to the object repository. How will I add that?

What is an Object Repository?

An object repository is a centralised place where you store and manage locators (like XPath, ID, CSS selectors) of web elements. It allows easier updates and reuse of elements across tests.



In our framework, we use a Page Object Model (POM) structure where each web page has its own class file representing the page's elements and actions.
To add a new field or element to the object repository:
  1. I identify the web element using browser developer tools (Inspect element).
  2. Then I create a new WebElement in the corresponding page class using @FindBy or driver.findElement() with an appropriate locator (like ID, XPath, or CSS).
  3. I also add a method to interact with that element — for example, to input text or click a button.
This way, our object repository remains organized, and if the locator changes later, we only need to update it in one place.


public class LoginPage {

WebDriver driver;

public LoginPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}

// Existing elements
@FindBy(id = "username")
WebElement usernameField;

// New field added
@FindBy(id = "newFeatureInput")
WebElement newFeatureInput;

public void enterNewFeatureData(String data) {
newFeatureInput.sendKeys(data);
}
}


To add a new field to the object repository, I first inspect the web element and identify a reliable locator. Then I update the relevant page object class by adding a new WebElement or entry, depending on whether we use Page Object Model or external files like .properties. This ensures centralized and reusable access to the element.

What is the difference between a single slash (/) and a double slash (//) in XPath?

single slash / is used to define an absolute path starting from the root node of the HTML. it goes to direct child in DOM tree.

For example, /html/body/div/input will select the element only if it matches that exact hierarchy.


double slash // is used for relative paths, allowing you to find an element anywhere in the DOM. it navigate to distant child in DOM tree

For example, //input[@id='email'] will find the input with id 'email' no matter where it is in the document.


In Selenium, we mostly use combination of relative and absolute both.

What are the different TestNG annotations, and what is their execution order?

TestNG provides various annotations that help control the flow of test execution.

The most commonly used ones are:


  1. @BeforeSuite, @BeforeTest, and @BeforeClass — used for setup activities like initialising drivers or test data.
  2. @BeforeMethod runs before each @Test, often used for opening the browser or navigating to a page.
  3. @Test is the actual test case.
  4. @AfterMethod is used to clean up after each test, like closing pop-ups or logging out.
  5. @AfterClass, @AfterTest, and @AfterSuite are for teardown — like closing browsers, releasing resources, or generating reports.



Sequence will look like

BeforeSuite - BeforeTest - BeforeClass - BeforeMethod - Test - AfterMethod - AfterClass - AfterTest - AfterSuite


The execution order starts from @BeforeSuite and ends at @AfterSuite. Using these annotations ensures our tests are well-structured, maintainable, and easy to debug.

Can you explain how Jenkins works in your project? How are you executing your automation framework in Jenkins?

Jenkins is an open-source automation server used to build, test, and deploy software continuously. It plays a crucial role in Continuous Integration and Continuous Delivery (CI/CD) pipelines.


In the context of automation testing, we use Jenkins to automatically trigger our test scripts whenever code is pushed to the repository. For example, when a developer commits code to Git, Jenkins pulls the latest code, builds the project using tools like Maven or Gradle, and runs automated tests, both UI and API.


We've configured Jenkins to run Selenium tests via Maven using a JenkinsFile or freestyle project. After execution, test reports like Extent Reports or Allure Reports are published and shared with the team.


I’ve also set up Jenkins jobs to run on schedule (e.g., nightly regression), configured email notifications for test results, and integrated it with GitHub and Slack for team visibility.

Jenkins helps catch issues early, ensures code quality, and allows us to maintain faster release cycles.

How do you handle alerts in Selenium?

To handle JavaScript alerts in Selenium, I use the Alert interface.


First, I switch the driver's context to the alert using

Alert alert = driver.switchTo().alert();

  1. use accept() to click OK. For confirmation alerts,
  2. use dismiss() to click Cancel.
  3. For prompt alerts, I use sendKeys() to enter text before accepting.
  4. For getText from alert, I use getText() method.


alert.accept();
alert.dismiss();
alert.sendKeys("abc");
String alertText = alert.getText();


I also wrap alert handling with WebDriverWait using ExpectedConditions.alertIsPresent() to ensure stability in case the alert takes time to appear.


Suppose I have a file. I want to upload that file in our server. What will be process we will use for this ?

If Element File Type is file


To handle file upload buttons in Selenium, I first check if the input element has type='file'.

If it does, I use the sendKeys() method to directly pass the file path, like:



driver.findElement(By.id("fileUpload")).sendKeys("C:\path\to\file.png");


Native OS Dialog


If the file upload opens a native OS dialog, I use Java’s Robot class to simulate keyboard actions like pasting the path and pressing Enter. In some cases, I’ve also used AutoIt scripts when interacting with complex upload windows that Robot couldn’t handle reliably.

What is polymorphism, and how is it applied in Selenium?

Polymorphism is an OOP concept where a method or object can take many forms.


In Selenium, we apply runtime polymorphism (Method Overriding) using the WebDriver interface. For example:


WebDriver driver = new ChromeDriver();


Here, WebDriver is an interface and ChromeDriver is a class that implements it. We can later replace ChromeDriver with FirefoxDriver or EdgeDriver without changing our test logic.


We also use method overloading in our framework to create reusable utility functions with the same method name but different parameters – that's compile-time polymorphism.

These principles help us write more flexible and maintainable automation code.

Can you describe your current project and explain its main components?


Currently, I’m working on a web-based insurance application that allows users to buy, renew, and manage their insurance policies online. It has modules like

  1. user registration
  2. policy management
  3. payments
  4. claims processing
  5. admin dashboards


The front end is built with React, and the backend is powered by Java Spring Boot APIs with MySQL as the database. All APIs are documented using Swagger, and we use Postman for initial testing.


From the QA side, we have both manual and automation processes. I work mainly on the UI automation using Selenium WebDriver with Java, and the framework is built on TestNG with Maven. We're also covering API automation using Rest Assured.


We run our tests in Jenkins as part of the CI/CD pipeline, and reports are generated using Extent Reports. Version control is done through Git, and we use JIRA for test and defect management.


I’ve contributed to designing and maintaining the automation framework, writing reusable methods, creating scripts for regression and smoke suites, and integrating test execution into Jenkins pipelines.


Note:

Banking Project – Mention modules like fund transfers, transactions, authentication, dashboards.

E-commerce Project – Mention cart, checkout, payments, inventory, user profiles.

Healthcare Project – Mention patient portals, appointment systems, medical records.


Please explain your automation framework?

In my current project, we are using a Hybrid Automation Framework built using Selenium WebDriver with Java, integrated with TestNG for test execution and Maven for build management.


The framework supports both data-driven and modular approaches. We use Apache POI for reading test data from Excel files, and our test scripts are written using Page Object Model (POM) to maintain scalability and reusability.


For reporting, we have integrated Extent Reports, and for CI/CD, our framework runs on Jenkins with triggers on every code commit.

In terms of my role, I was responsible for enhancing the framework by adding reusable utilities, writing new test scripts, maintaining the


object repository, and setting up parallel execution using TestNG XML.

We also used Git for version control and Allure reports in some modules to better visualize test results."

Can you explain the purpose of the Robot class in Selenium?

The Robot class in Java is used in Selenium when we need to simulate low-level keyboard and mouse events that Selenium WebDriver alone cannot handle.

It comes from the java.awt package and is especially useful for scenarios like:


Use Cases:

  1. Handling OS-level pop-ups or dialogs
  2. (e.g., File Upload/Download windows that are outside the browser DOM)
  3. Simulating keyboard events
  4. (e.g., pressing Enter, Tab, Ctrl+C, etc.)
  5. Mouse movements and clicks
  6. (for custom mouse operations)


Example: Handling File Upload Window

Robot robot = new Robot();
robot.delay(2000);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V); // paste file path
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);


This sequence simulates pasting a file path into an OS file upload dialog and pressing Enter.


Why Robot Class?

  1. Selenium interacts with web elements in the DOM.
  2. Robot is helpful when we need to interact with non-DOM-based components, like native OS windows.


Why is Page Factory used in object repositories?

Page Factory is used in Selenium to implement the Page Object Model (POM) in a more efficient and readable way. It helps manage object repositories by initializing web elements using annotations, making the code cleaner and easier to maintain.


Key Reasons for Using Page Factory:

Improves Readability and Maintainability:

You define all elements at the top of the class using @FindBy, separating the element locators from the test logic.


Efficient Object Initialization:

Page Factory uses initElements() method to initialize all @FindBy annotated elements when the page class is instantiated.


Reduces Boilerplate Code:

No need to repeatedly use driver.findElement(); Page Factory handles it automatically.


Supports Lazy Initialization (with AjaxElementLocatorFactory):

It waits until the element is actually used in the code, which is helpful in dynamic or AJAX-heavy pages


public class LoginPage {
WebDriver driver;

@FindBy(id = "username")
WebElement usernameField;

@FindBy(id = "password")
WebElement passwordField;

@FindBy(id = "login")
WebElement loginButton;

public LoginPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}

public void login(String user, String pass) {
usernameField.sendKeys(user);
passwordField.sendKeys(pass);
loginButton.click();
}
}


So as summary, Page Factory is a clean and efficient way to organize element locators and is especially helpful in large projects for making object repositories modular and reusable.

How do you launch Internet Explorer in Selenium WebDriver?

To launch Internet Explorer in Selenium WebDriver, I use the InternetExplorerDriver class. Here are the steps I follow:

  1. Download the IE Driver Server from the official Selenium website, and ensure the version (32-bit or 64-bit) matches the installed IE browser.
  2. Set the system property in my Java code to specify the path of the IEDriverServer.exe.
  3. Create an instance of InternetExplorerDriver and use it like any other WebDriver.

System.setProperty("webdriver.ie.driver", "C:\\Drivers\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("https://www.example.com");


  1. I also ensure required IE settings are in place:
  2. Protected mode settings must be the same for all zones.
  3. Zoom level should be set to 100%.
  4. IE Enhanced Security Configuration should be turned off.


I typically avoid using IE unless required, as it's deprecated and less stable. In most modern projects, I prefer using Chrome, Edge, or Firefox.

How do you use the Select class in Selenium for handling dropdowns?

How to Use the Select Class in Selenium (Java)


Approach of Select:

  1. Identify the <select> element using a locator (e.g., By.id, By.name).
  2. Create a Select object by passing the WebElement.
  3. Use available methods to select or deselect options.


Example:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class DropdownExample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();

try {
driver.get("https://example.com/dropdown");

// Locate the dropdown element
WebElement dropdown = driver.findElement(By.id("dropdownId"));

// Create Select object
Select select = new Select(dropdown);

// Select by visible text
select.selectByVisibleText("Option 1");

// Select by value
select.selectByValue("option1");

// Select by index (starting from 0)
select.selectByIndex(2);

// Get selected option
WebElement selectedOption = select.getFirstSelectedOption();
System.out.println("Selected: " + selectedOption.getText());

} finally {
driver.quit();
}
}
}

Could you write a program for taking a screenshot in Selenium?

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;

public class ScreenshotExample {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
try {
// Open a website
driver.get("https://www.example.com");
// Take screenshot and store as a file
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
// Define where to save the screenshot
File destination = new File("screenshot.png");
// Copy file to destination
FileUtils.copyFile(screenshot, destination);
} catch (IOException e) {
System.out.println("Error while saving screenshot: " + e.getMessage());
} finally {
driver.quit();
}
}
}