1. Please introduce yourself.
I am Gemini, a large language model, trained by Google.
2. Please explain your Automation Framework, all the components.
An automation framework is a set of guidelines, a structure, and a library of
reusable components that help in creating and maintaining automated test
scripts. A typical automation framework for a web application might include
the following components:
Test Runner: A tool like TestNG or JUnit that executes the test cases
and provides reporting functionalities.
Selenium WebDriver: The core library that interacts with the browser
to perform actions like clicking, typing, and navigating.
Programming Language: A language like Java, Python, or C# used
to write the test scripts.
Build Tool: A tool like Maven or Gradle that manages dependencies,
builds the project, and runs the tests.
Page Object Model (POM): A design pattern that separates the UI
elements from the test logic, making tests more readable and
maintainable.
Data-Driven Testing: A mechanism to read test data from external
sources like Excel, CSV, or a database, allowing a single test script to
be executed with multiple data sets.
Reporting: A reporting tool like Extent Reports or Allure Reports to
generate detailed, customizable, and visually appealing reports of the
test execution.
CI/CD Tool: A tool like Jenkins or GitLab CI/CD to integrate the
automation tests into the continuous integration and continuous
deployment pipeline.
Version Control: A tool like Git to manage the source code, track
changes, and collaborate with other team members.
3. What is a Page Object Model?
The Page Object Model (POM) is a design pattern used in test automation
that aims to create a more maintainable and readable test suite. In POM,
each web page or a significant part of a page is represented as a separate
class. This class contains all the web elements (locators) and the methods
that interact with those elements.
The key idea is to separate the code that identifies the web elements (the
"what") from the code that performs actions on those elements (the "how").
This separation ensures that if the UI changes, you only need to update the
Page Object class, and not all the test scripts that use that page.
4. How do you run your test cases in parallel in Cucumber?
Cucumber itself doesn't have built-in support for parallel execution. You need
to use a test runner like TestNG or JUnit to achieve this.
Using TestNG: You can use the
[Link] class. In the
[Link] file, you can set the parallel attribute to methods or classes
and define the thread-count. This will run the feature files in parallel.
Using Maven Surefire Plugin: This is another popular approach. You
can configure the maven-surefire-plugin in your [Link] to execute
test classes in parallel.
5. Explain the contents of the Runner File in Cucumber?
A Cucumber runner file is a Java class that tells JUnit or TestNG how and
where to run the Cucumber tests. A typical runner file contains:
@RunWith([Link]): (For JUnit) This annotation tells JUnit to
use the Cucumber class as the test runner.
@CucumberOptions: This is the most important annotation. It
contains various options to configure the test run:
o features: The path to the feature files.
o glue: The package where the step definitions are located.
o tags: A way to group and execute specific scenarios or features.
o plugin: Specifies the reporting format. Common plugins include
pretty, html:target/cucumber-html-report,
json:target/[Link], and rerun:target/[Link].
o monochrome: Set to true to make the console output more
readable.
o dryRun: Set to true to check if all the steps in the feature files
have corresponding step definitions without actually executing
them.
6. What is a Singleton Design Pattern?
The Singleton design pattern ensures that a class has only one instance and
provides a global point of access to that instance. This is useful when you
need to control access to a shared resource, like a WebDriver instance in a
test automation framework.
A Singleton class is typically implemented with:
A private constructor to prevent the class from being instantiated from
outside.
A private static variable of the same class type to hold the single
instance.
A public static method that provides access to the instance. This
method creates the instance on the first call and returns the same
instance on subsequent calls.
7. What are the advantages and disadvantages of the Page Object
Model?
Advantages:
Maintainability: If the UI of a page changes, you only need to update
the corresponding Page Object class, not all the test scripts that use
that page.
Readability: Test scripts become more readable as they contain high-
level actions (e.g., [Link]()) rather than a sequence
of low-level Selenium commands.
Reusability: Page Object methods can be reused across different test
scripts.
Separation of Concerns: It separates the test logic from the UI
elements, making the code cleaner and easier to understand.
Disadvantages:
Initial Setup: It requires more effort to set up the framework and
create the Page Object classes initially.
Overhead: For small projects or simple tests, the overhead of creating
Page Object classes might not be worth it.
Increased Complexity: The project structure becomes more complex
with multiple Page Object classes and their dependencies.
8. What is Selenium Grid?
Selenium Grid is a tool that allows you to run your Selenium tests on multiple
machines in parallel. This is particularly useful for:
Cross-browser testing: Running the same test on different browsers
and their versions simultaneously.
Distributed execution: Distributing the test load across multiple
machines to reduce the total execution time.
Selenium Grid consists of a Hub and one or more Nodes. The Hub acts as a
central point, receiving test requests and distributing them to the
appropriate Nodes. The Nodes are the machines where the actual browsers
are running.
9. Explain the WebDriver create statement line?
The WebDriver create statement line typically looks like this:
Java
WebDriver driver = new ChromeDriver();
Let's break down this line:
WebDriver: This is an interface provided by the Selenium library. It
defines the core methods for interacting with a web browser (e.g.,
get(), findElement(), click()).
driver: This is the reference variable of type WebDriver. It's a standard
variable name, but you can name it anything you want.
new ChromeDriver(): This is the implementation of the WebDriver
interface for the Chrome browser. It creates a new instance of the
ChromeDriver class, which launches a Chrome browser and sets up the
communication between your script and the browser.
This line of code is an example of polymorphism in object-oriented
programming, where a reference of a parent interface (WebDriver) can hold
an object of a child class (ChromeDriver). This makes the code flexible, as
you can easily switch to another browser by simply changing the new
ChromeDriver() part to new FirefoxDriver() or new EdgeDriver().
11. Explain the Maven Lifecycle?
The Maven build lifecycle is a predefined sequence of phases that a Maven
project goes through during its build process. The most important default
lifecycles are:
default: This is the main lifecycle responsible for building the project.
clean: This lifecycle handles project cleanup.
site: This lifecycle creates project documentation.
The default lifecycle consists of several phases, and executing a phase
means executing all the phases that come before it. Some key phases of the
default lifecycle are:
validate: Validates the project structure.
compile: Compiles the source code.
test: Runs the unit tests.
package: Packages the compiled code into a distributable format
(e.g., JAR, WAR).
integration-test: Runs integration tests.
verify: Runs checks to ensure the package is valid.
install: Installs the package into the local repository.
deploy: Deploys the package to a remote repository.
12. How do you run the failed test cases?
There are a few ways to run only the failed test cases, depending on the test
runner and framework you're using.
TestNG: TestNG generates a [Link] file in the test-output
folder after a test run. This file contains only the test methods that
failed. You can simply run this XML file to re-execute the failed tests.
Cucumber: When you configure the Cucumber runner file with the
rerun plugin, Cucumber generates a text file (e.g., target/[Link])
containing the path to the feature files and the line numbers of the
failed scenarios. You can then create another runner file to use this
[Link] file as input to re-run only the failed tests.
13. How do you generate Reports in Selenium?
Selenium WebDriver itself doesn't provide built-in reporting functionalities.
You need to use external libraries or test runners to generate reports.
TestNG: TestNG generates basic HTML reports in the test-output folder
by default.
JUnit: JUnit also provides some basic reports.
Extent Reports: This is a popular third-party library that generates
beautiful, detailed, and customizable HTML reports. You integrate it
into your framework by using listeners and event handling.
Allure Reports: Allure is another powerful and comprehensive
reporting tool that provides a clear overview of test results, including
test steps, screenshots, and test execution history.
Cucumber Reports: Cucumber can generate various types of reports
using plugins like html, json, junit, and pretty.
14. How do you customise reports after your test execution?
The process of customizing reports depends on the reporting tool you are
using:
Extent Reports: You can customize Extent Reports by:
o Adding screenshots to the report on test failure.
o Adding custom logs and messages to the report.
o Modifying the report's theme, title, and other details.
Allure Reports: Allure provides extensive customization options:
o You can use annotations (@Step, @Attachment) to add detailed
steps, screenshots, and other attachments to the report.
o You can add custom properties to the test results to include
environment information.
o The Allure Commandline tool allows you to generate the reports
with different options.
TestNG Listeners: For TestNG, you can use listeners like ITestListener
to programmatically handle test events (e.g., onTestFailure) and add
custom logic, such as taking screenshots and adding them to the
report.
15. What kind of waits are there in Selenium?
There are three main types of waits in Selenium:
Implicit Wait: This is a global wait that is applied to all elements in
your test script. When you set an implicit wait, Selenium will wait for
the specified amount of time before throwing a
NoSuchElementException if an element is not found immediately.
Explicit Wait: This wait is more flexible and is applied to a specific
element with a specific condition. You can tell Selenium to wait until a
certain condition is met (e.g., an element is clickable, visible, or
present) before proceeding.
Fluent Wait: A fluent wait is a more advanced explicit wait. It allows
you to specify a polling interval and to ignore certain exceptions during
the waiting period. It's useful when you need to wait for an element
that might not be available immediately but could appear within a
certain timeframe.
16. Write the Code Snippet for Explicit Wait?
Java
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class ExplicitWaitExample {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
[Link]("[Link]
// Create a WebDriverWait object with a timeout of 10 seconds
WebDriverWait wait = new WebDriverWait(driver,
[Link](10));
// Wait until the element with the name "q" is visible
WebElement searchBox =
[Link]([Link]([Link]("q")));
// Now that the element is visible, you can interact with it
[Link]("Selenium WebDriver");
17. Write the Code Snippet for Drag and Drop in Selenium?
Java
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class DragAndDropExample {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
[Link]("[Link]
// Switch to the iframe containing the draggable and droppable
elements
[Link]().frame([Link]([Link]("demo-
frame")));
WebElement draggable = [Link]([Link]("draggable"));
WebElement droppable = [Link]([Link]("droppable"));
// Create an Actions class object
Actions actions = new Actions(driver);
// Perform the drag-and-drop action
[Link](draggable, droppable).build().perform();
18. How do you switch to different Windows in Selenium?
To switch between different windows or tabs in Selenium, you use the
[Link]().window() method. You need to get the window handles first.
Java
import [Link];
import [Link];
import [Link];
import [Link];
public class WindowSwitchingExample {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
[Link]("[Link]
// Get the handle of the parent window
String parentWindowHandle = [Link]();
// Perform an action that opens a new window/tab
// e.g., click a link
[Link]([Link]("newWindowLink")).click();
// Get all the window handles
Set<String> allWindowHandles = [Link]();
// Iterate through all the handles to find the new window
for (String handle : allWindowHandles) {
if () {
// Switch to the new window
[Link]().window(handle);
// Now you can perform actions in the new window
[Link]("Switched to new window. Title: " +
[Link]());
// Close the new window
[Link]();
}
// Switch back to the parent window
[Link]().window(parentWindowHandle);
[Link]("Switched back to parent window. Title: " +
[Link]());
19. Why do we use SET in Window Handles?
We use a Set<String> to store the window handles because a Set is a
collection that does not allow duplicate elements.
Each window or tab in a browser has a unique identifier called a
window handle.
When you use [Link](), it returns a Set of all the
unique window handles currently open in the browser session.
Using a Set ensures that you are working with unique identifiers for
each window, which is exactly what you need to switch between them.
20. Write the Code for taking screenshot in Selenium?
Java
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class ScreenshotExample {
public static void main(String[] args) throws IOException {
WebDriver driver = new ChromeDriver();
[Link]("[Link]
// Convert WebDriver object to TakeScreenshot
TakesScreenshot ts = (TakesScreenshot) driver;
// Call getScreenshotAs method to create image file
File source = [Link]([Link]);
// Define the destination where the screenshot will be saved
File destination = new File("D:\\[Link]");
// Copy the source file to the destination
[Link](source, destination);
[Link]("Screenshot saved to: " +
[Link]());
Note: You need to add the commons-io dependency to your project for
FileUtils.
21. What is the difference between Scenario and Scenario Outline in
Cucumber?
Scenario: A Scenario is used to describe a single test case. It contains
a set of steps with fixed data. Each time you run a Scenario, it
executes with the same data.
Scenario Outline: A Scenario Outline is used to run the same
scenario multiple times with different sets of data. It uses
<placeholder> variables in the steps, and the actual data is provided
in an Examples table. Cucumber will execute the scenario once for
each row in the Examples table, replacing the placeholders with the
data from that row.
Example of Scenario:
Gherkin
Scenario: Login with valid credentials
Given I am on the login page
When I enter "admin" and "password"
And I click the login button
Then I should be logged in successfully
Example of Scenario Outline:
Gherkin
Scenario Outline: Login with different credentials
Given I am on the login page
When I enter "<username>" and "<password>"
And I click the login button
Then I should be logged in "<loginStatus>"
Examples:
| username | password | loginStatus |
| admin | password | successfully|
| invalid | wrong | unsuccessfully |
22. How do you pass data to your Selenium Scripts?
You can pass data to your Selenium scripts in several ways:
Hardcoding: The simplest but least flexible way is to hardcode the
data directly in the script.
External Files: A more common approach is to store data in external
files like:
o Excel: Using libraries like Apache POI.
o CSV: Using libraries like OpenCSV.
o Properties Files: For simple key-value pairs (e.g., for
configuration data).
o JSON/YAML: For structured data.
Data-Driven Framework: You can build a data-driven framework that
reads data from these external sources and passes it to the test
methods.
TestNG DataProvider: TestNG has a @DataProvider annotation that
allows you to provide test data to a test method from a separate
method in the same class.
Cucumber Examples: As mentioned earlier, Cucumber's Scenario
Outline uses an Examples table to pass data to the scenarios.
23. How do you decide the priorities of your Test Cases?
You can decide the priorities of your test cases based on several factors:
Functionality Criticality: Prioritize test cases that cover the most
critical or frequently used functionalities of the application.
Business Impact: Prioritize test cases that test functionalities with a
high business impact.
Risk: Prioritize test cases that test areas with high risk of failure or
those that have had a history of defects.
Dependencies: Prioritize test cases that have dependencies on other
features.
Test Type: You can prioritize smoke tests and sanity tests over
regression tests, as they need to be executed first to ensure the basic
functionalities are working.
TestNG Priorities: In TestNG, you can use the priority attribute in the
@Test annotation to define the execution order of your test methods.
24. If you want to execute one test case again and again how do you
do that?
TestNG invocationCount: In TestNG, you can use the
invocationCount attribute in the @Test annotation.
Java
@Test(invocationCount = 5)
public void myTest() {
// Your test logic
This will execute the myTest method 5 times.
Loops: You can use a simple for loop within your test method to
execute a block of code multiple times. This is useful if you want to
repeat a specific part of the test logic.
Data-Driven Testing: If you want to repeat the test with different
data, a data-driven approach using DataProvider in TestNG or Scenario
Outline in Cucumber is the best way to do it.
25. What are the different annotations used in TestNG?
TestNG has several annotations to control the execution flow of the tests:
Test Annotations:
o @Test: Marks a method as a test method.
Before/After Annotations (Hierarchy):
o @BeforeSuite: Runs once before all tests in the suite.
o @AfterSuite: Runs once after all tests in the suite.
o @BeforeTest: Runs once before all the test classes in a <test>
tag.
o @AfterTest: Runs once after all the test classes in a <test> tag.
o @BeforeClass: Runs once before the first method of a class.
o @AfterClass: Runs once after all the test methods of a class.
o @BeforeMethod: Runs before each test method.
o @AfterMethod: Runs after each test method.
Other Annotations:
o @DataProvider: Marks a method as a data provider for a test
method.
o @Factory: A factory class to create instances of a test class at
runtime.
o @Listeners: To define a listener for a test class.
o @Parameters: To pass parameters to a test method.
o @Groups: To group test methods.
26. Write the hierarchy of annotations in TestNG?
The execution hierarchy of TestNG annotations is as follows:
1. @BeforeSuite
2. @BeforeTest
3. @BeforeClass
4. @BeforeMethod
5. @Test
6. @AfterMethod
7. @AfterClass
8. @AfterTest
9. @AfterSuite
Note: If you have multiple classes in a test, @BeforeClass and @AfterClass
will run for each class, and @BeforeMethod and @AfterMethod will run for
each test method within each class.
27. What is the defect life cycle?
The defect life cycle is the process of a defect from its discovery to its
resolution and closure. The typical stages are:
1. New: The tester finds a defect and reports it.
2. Assigned: The test lead or manager assigns the defect to a developer.
3. Open: The developer starts working on the defect.
4. Fixed/Resolved: The developer fixes the bug and reports it as fixed.
5. Test/Re-test: The tester re-tests the functionality to verify the fix.
6. Closed: If the fix is verified, the tester closes the defect.
7. Reopen: If the fix fails, the tester reopens the defect and assigns it
back to the developer.
8. Deferred: If the defect is not critical, it can be deferred to a later
release.
9. Rejected: The developer may reject the defect if it's not a valid bug.
28. What is the difference between Agile and Waterfall Model?
Feature Agile Model Waterfall Model
Linear and sequential. The
Incremental and iterative.
project flows in one
Approach The project is broken into
direction, from one phase
smaller cycles (sprints).
to the next.
Rigid and difficult to change
Highly flexible and
Flexibility requirements once a phase
adaptable to changes.
is complete.
High customer
Limited customer
Customer involvement and
involvement, typically at
Involvement collaboration throughout
the beginning and the end.
the project.
Testing is an ongoing Testing is a separate phase
Testing process throughout the that happens at the end of
development lifecycle. the development.
Risks are handled and Risks are identified and
Risk mitigated early and addressed late in the
continuously. process.
A working product is A single, complete product
Deliverables delivered at the end of is delivered at the end of
each sprint. the project.
29. What is the difference between 201 and 204 Status Code?
Both 201 and 204 are successful HTTP status codes.
201 Created: This status code indicates that the request has been
fulfilled and a new resource has been created. The server typically
returns a 201 with a Location header that points to the newly created
resource. This is commonly used for POST requests.
204 No Content: This status code indicates that the server has
successfully fulfilled the request, but there is no content to send in the
response body. The server will not return any data. This is often used
for DELETE or PUT requests where the server successfully processes
the request but doesn't have anything new to return.
30. What is the difference between 401 and 403 Status Code?
Both 401 and 403 are client error status codes.
401 Unauthorized: This status code means that the client must
authenticate itself to get the requested response. The client has not
provided valid authentication credentials (e.g., a username and
password or an API key).
403 Forbidden: This status code means that the client has a valid
identity (they have authenticated), but they do not have the necessary
permissions to access the requested resource. The server understands
the request but refuses to authorize it.
31. What are the components of an API Request?
A typical API request consists of the following components:
Endpoint: The URL of the API resource. It consists of the base URL and
the resource path.
Method: The HTTP method used to perform the action. Common
methods are GET, POST, PUT, DELETE, and PATCH.
Headers: Key-value pairs that contain metadata about the request,
such as content type (Content-Type), authentication tokens
(Authorization), and caching information.
Body: The data that is sent to the server. The body is used in POST,
PUT, and PATCH requests to create or update resources.
Query Parameters: Key-value pairs appended to the URL after a ? to
filter or paginate the data.
32. What is the difference between Query Parameters and Path
Parameters?
Path Parameters: These are a part of the URL path itself. They are
used to identify a specific resource. They are separated by /.
o Example: /users/{id} where {id} is a path parameter.
o Use Case: To retrieve, update, or delete a specific resource.
Query Parameters: These are key-value pairs appended to the URL
after a ?. They are used to filter, sort, or paginate the results.
o Example: /users?role=admin&status=active where role and
status are query parameters.
o Use Case: To provide optional parameters for modifying the API
response.
33. How do you resolve Conflicts in Git?
A merge conflict occurs when two or more developers have modified the
same lines of code in the same file and Git cannot automatically decide
which change to keep. To resolve a conflict:
1. Pull the latest changes: Run git pull to get the latest code from the
remote repository.
2. Identify the conflict: Git will mark the conflicting files. The conflicted
code will be marked with <<<<<<< HEAD, =======, and
>>>>>>> [branch-name].
3. Edit the file: Manually edit the file to remove the conflict markers and
choose the correct version of the code. You might need to combine
code from both branches.
4. Add the resolved file: After editing, use git add <file-name> to stage
the resolved file.
5. Commit the merge: Use git commit -m "Merge branch 'your-branch'
with conflict resolution" to commit the changes.
6. Push the changes: Finally, git push the merged and resolved
changes to the remote repository.
34. What is the difference between git pull and git patch?
git pull: This is a command that combines two other Git commands:
git fetch and git merge.
o git pull fetches the latest changes from the remote repository
and automatically merges them into your current local branch.
o It is used to update your local repository with the latest code
from the remote.
git patch: A patch is a file (typically with a .patch extension) that
contains the changes between two commits.
o git format-patch is used to create a patch file from a set of
commits.
o git apply is used to apply a patch file to a branch.
o A patch is a way to share a set of changes with other developers
without having to use the standard pull and push workflow. It's
often used in open-source projects for code reviews.
35. Explain the use of Jenkins in the Automation Framework?
Jenkins is an open-source automation server that plays a crucial role in a
CI/CD pipeline. In an automation framework, Jenkins is used to:
Continuous Integration (CI): Jenkins can be configured to
automatically trigger the execution of the automation tests whenever a
new commit is pushed to the version control system (e.g., Git). This
ensures that any new code changes are immediately validated.
Scheduled Runs: You can schedule the automation tests to run at a
specific time (e.g., nightly) to get a daily report on the application's
health.
Build Automation: Jenkins can be used to build the project (e.g.,
using Maven or Gradle), run the tests, and generate reports
automatically.
Reporting and Notifications: Jenkins can send email notifications
with the test results, including links to the generated reports, to the
relevant team members after a test run.
Deployment: Jenkins can be used to deploy the application to
different environments (e.g., staging, production) after a successful
test run.
Integration: Jenkins integrates with various tools and plugins for
source code management (Git), reporting (Allure, Extent), and more,
making it a central hub for the entire automation process.