Top 10 Selenium Interview Questions and Answers for QA Engineers (2025 Update)
1. What are the roles and responisibilities you have in your current project?
In my current role as a QA Automation Engineer, I’m responsible for both automation and manual testing activities, with a strong focus on ensuring product quality throughout the development lifecycle.I actively participate in requirement grooming sessions to understand user stories and acceptance criteria. I also estimate testing efforts and prepare test plans in alignment with sprint goals. I write and maintain detailed test cases for both manual and automated testing. I develop and maintain automation scripts using Selenium WebDriver with Java, along with TestNG. I’ve implemented frameworks using Page Object Model, and integrated with tools like Maven, Git, and Jenkins for CI/CD. I collaborate with the DevOps team to integrate test suites with Jenkins pipelines for nightly builds and regression runs. I log detailed and reproducible bugs using JIRA, assign them to the respective team members, and follow up on resolution. I mentor junior QAs in automation best practices and code reviews.
2. How to Load a Properties File in TestNG?
Ans: Use Properties
and FileInputStream
in Java.
import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; public class ConfigReader { public static void main(String[] args) throws IOException { Properties prop = new Properties(); FileInputStream fis = new FileInputStream("config.properties"); prop.load(fis); System.out.println(prop.getProperty("browser")); } }
3. What is the defect life cycle ?
The Defect Life Cycle (also called the Bug Life Cycle) is the process a defect goes through from its identification to closure. It ensures issues are properly tracked, fixed, and verified in a structured manner.
Stages of Defect Life Cycle
- New: A defect is logged by the tester. It awaits review or triage.
- Assigned: The defect is assigned to a developer or responsible person.
- Open / In Progress: The developer starts analyzing and working on the fix.
- Fixed / Resolved: Developer fixes the bug and marks it as resolved.
- Retest: The QA team retests the issue to verify the fix.
- Reopened: If the issue persists, it's reopened and sent back to the developer.
- Closed: If the fix works correctly, the tester closes the defect.
- Rejected / Not a Bug (Optional): The defect is invalid or as per design.
- Deferred / Postponed (Optional): The issue is valid but postponed for future release.
Example Flow
Tester finds a login issue → Logs it as New → Assigned to developer → Marked In Progress → Fixed → Retested by QA → Closed or Reopened as needed.
4. Explain the maven Lifecycle ?
Maven Build Lifecycle
The Maven Lifecycle is a sequence of steps that defines the order in which the goals are executed during a Maven build. Maven has three built-in lifecycles:
- default – handles project deployment
- clean – handles project cleaning
- site – handles project documentation
Default Lifecycle Phases
The most commonly used lifecycle is default. It includes the following key phases, executed in order:
- validate: Validates the project structure and configuration.
- compile: Compiles the source code of the project.
- test: Runs the unit tests using a suitable testing framework (e.g., JUnit).
- package: Packages the compiled code into a distributable format, such as a JAR or WAR.
- verify: Runs checks to verify the package is valid and meets quality criteria.
- install: Installs the package into the local Maven repository for use as a dependency in other projects.
- deploy: Copies the final package to the remote repository for sharing with other developers or teams.
Clean Lifecycle Phases
- pre-clean: Executes processes needed before the actual project cleaning.
- clean: Deletes the target directory and other build artifacts.
- post-clean: Executes processes after the clean phase is completed.
Site Lifecycle Phases
- pre-site: Prepares for the site generation.
- site: Generates the project’s documentation site.
- post-site: Executes post-processing on the site generation.
- site-deploy: Deploys the generated site to a web server.
Note:
Each phase may execute one or more goals, and calling a phase will automatically trigger all preceding phases in that lifecycle.
5. Swap Two Variables Without Using a Third Variable
int a = 5, b = 10; a = a + b; b = a - b; a = a - b; System.out.println("After swap: a=" + a + ", b=" + b);
6. Reverse a String Without Using Reverse Function
public class ReverseString { public static void main(String[] args) { String str = "Selenium"; String rev = ""; for (int i = str.length() - 1; i >= 0; i--) { rev += str.charAt(i); } System.out.println(rev); } }
7. What is the difference between List and Set
Feature | List | Set |
---|---|---|
Order | Maintains insertion order | Does not guarantee order (unless using LinkedHashSet or TreeSet) |
Duplicates | Allows duplicate elements | Does not allow duplicates |
Index-Based Access | Supports accessing elements by index (e.g., list.get(0) ) |
No index-based access |
Performance | Faster for accessing elements by position | Faster for searching when using HashSet |
Common Implementations | ArrayList , LinkedList , Vector |
HashSet , LinkedHashSet , TreeSet |
Use Case | When duplicates are allowed or order matters | When unique elements are required |
For more detailed information, check out our full blog post on Master Java Collections Framework: A Complete Guide for Beginners.
8. What are the different annotations used in TestNG
TestNG provides several annotations to control the execution of test methods. Below are the most commonly used annotations:
Annotation | Description |
---|---|
@Test |
Marks a method as a test method. |
@BeforeSuite |
Runs once before all tests in the suite. |
@AfterSuite |
Runs once after all tests in the suite have run. |
@BeforeTest |
Runs before any test method inside the <test> tag in testng.xml. |
@AfterTest |
Runs after all test methods in the <test> tag have run. |
@BeforeClass |
Runs once before the first method in the current class. |
@AfterClass |
Runs once after all the methods in the current class. |
@BeforeMethod |
Runs before each test method. |
@AfterMethod |
Runs after each test method. |
@DataProvider |
Supplies test data to a test method. |
@Parameters |
Passes parameters from testng.xml to test methods. |
@Factory |
Used to execute a set of test cases with different values. |
@Listeners |
Defines listener classes for customizing test execution (like logging, reporting). |
9. How do you run the failed test cases
TestNG provides a simple way to rerun failed test cases using a special XML file generated after execution. Here's how you can do it:
Step-by-Step Process
-
Execute the test suite:
Run your test suite using the main TestNG XML file (e.g.,testng.xml
). -
Locate the failed test XML:
After execution, TestNG automatically creates a file namedtestng-failed.xml
inside thetest-output
folder. -
Run the failed test XML:
You can now run this file as a TestNG suite to execute only the failed test cases.
Example (using IntelliJ or Eclipse):- Right-click on
testng-failed.xml
- Select Run as > TestNG Suite
- Right-click on
10. Explain WebDriver driver = new ChromeDriver();
This line is commonly used in Selenium automation scripts to launch the Chrome browser and control it for automated testing.
Breakdown of the Statement
Part | Description |
---|---|
WebDriver |
This is an interface provided by Selenium that represents the main contract for browser automation. It allows you to interact with different browsers in a browser-independent way. |
driver |
This is the reference variable of type WebDriver . |
= |
Assignment operator – assigns the ChromeDriver object to the WebDriver reference. |
new ChromeDriver() |
This creates a new instance of the ChromeDriver class, which is an implementation of the WebDriver interface.It launches a new Chrome browser window that Selenium will control. |
What Happens When This Line is Executed?
- Chrome browser is launched.
- Selenium establishes a connection with the Chrome browser using ChromeDriver.
- You can now control the browser using Selenium commands like
get()
,click()
,sendKeys()
, etc.
Comments
Post a Comment