Testing Notes
Testing Notes
Types of software:
• System software: used to run systems.
Ex: OS, device drivers, servers.
• Application software:
Ex: web applications, mobile apps, desktop app.
pg. 1
SDLC (Software Development life cycle)
Q: What is SDLC?
A: SDLC stands for Software Development Life Cycle. It is a process used by software companies
to design, develop and test software's.
Requirement Analysis ---> design ---> development ---> testing ---> Installation ---> maintenance
Requirement Analysis: Usually, the customer or client gives a requirement in the form of CRS/BRS.
And it is converted into SRS by BA. BA acts as bridge b/w customer and company.
Design: Architect or senior developers will design the software based on the SRS documents. They
will design HLD (High Level Design), LLD (Low Level Design) doc's.
Development: Once the design is done developers start writing the code for application by looking
at design or requirement
Testing: Once coding is done developers will give application to test engineers. All test engineers
start finding the defects. If any defects are found in software applications, it again goes back to the
developers as this process continues.
Installation: Making the software application available for end users is called installation. It is done
by the software company once testing is completed. Customers should approve the installation.
Maintenance: Once software is provided to customers or end users, if they face any problem
support must be provided, that is maintenance. During maintenance, a defect fix will be handled,
and changes will be taken care of.
pg. 2
Waterfall Model:
It is the 1st model used in the initial stages of software development.
Each phase will depend on the previous phase.
Requirement Analysis ---> design ---> development ---> testing ---> deployment ---> maintenance
Advantages:
• The quality of the product will be good because we do detailed documentation in each
phase.
• Req changes are not allowed, so finding bugs will be less.
• Initial investment is less because testers will be hired at later stages.
Disadvantages:
• Req change is not possible.
• If there is a defect in req analysis that will be continued in later phases.
• Investment will be high if we find defects and do re-work.
• Testing will start after coding.
Spiral model:
It is also called a version control model. We follow this model whenever there is dependency on the
modules. In every cycle new software version will be released to customers.
After 1 cycle we deliver software to the customer if there are some changes/req we do it on top of
the (1st) software cycle and that is 2nd cycle.
planning ---> risk analysis (req Anal) ---> engineering & execution (design & dev) ---> evaluation
(testing & maintenance). // each cycle will have all 5 phases.
Advantages:
• Req changes are allowed, but only after every cycle, before going on the next cycle.
• Customers will get to use the software for every module.
Disadvantages:
• There is no testing in the req and design phase.
pg. 3
• Every cycle of spiral looks like a waterfall.
Advantages:
• Testing starts at the initial stage.
• Requirement and design are tested.
• The downward flow of defects is less.
• Requirements change can be made.
• Quality will be high compared to other products.
• Rework will be less.
Disadvantages:
• Documentation work will be more.
• Too many resources are needed.
Agile Methodology:
AGILE is a methodology that promotes continuous iteration of development and testing throughout
the software development life cycle of the project. Both development and testing activities are
concurrent unlike the Waterfall model.
• In the Agile methodology, each project is broken up into several ‘Iterations’.
• Each Iterations should be of the same time duration (between 2 to 8 weeks).
• At the end of each iteration, a working product should be delivered.
• Any remaining features that cannot be delivered in the first iteration will be taken up in the
next iteration or subsequent iterations, based on priority.
pg. 4
When the customers give the requirement in the form of BRS / CRS. It is converted in the form of
SRS by BA. SRS contains more technical details in technical format like data flow, vein diagrams,
flow charts. The SRS will review against the CRS to find the defects. It is conducted in user
Acceptance Testing (UAT).
Based on SRS Doc, Design team will prepare HLD (contains main modules) & LLD Doc and share
with Dev & Test team to make them understand the requirement. based on SRS Doc tester will test
the Software.
Verification Validation
Verification is also termed as static testing.
Validation can be termed as black box testing or
dynamic testing
Verification is for prevention of errors Validation is for detection of errors
Focuses on documentation Validation is a product-focused strategy
Verification checks whether “Are we building Validation checks whether “Are we building the
the product, right?” right product?”
Verification Uses Static Testing Techniques Validation involves Dynamic Testing Techniques
Methods used in verification are reviews, Methods used in validation are Black Box testing,
walkthroughs and inspections. White Box Testing and Non-functional testing.
To test the Docs (like CRS, SRS, LLD...) we use Static testing techniques: (tests only doc)
1) Reviews
2) Walkthrough
3) Inspection
Types of review:
• Requirement Review
• Design review
• Code review
• Test plan review
• Test cases review
Walkthrough:
It is an informal (not pre-planned and can be done whenever required) review.
Author reads the doc / code and discuss it with peers (team).
Inspection:
It is a formal (planned) review.
3 kinds of people were involved readers (author), writer (note down all the issues raised), moderator
(org the meeting).
pg. 5
To test the actual software, we use Dynamic testing techniques: (levels of software testing)
Black Box Testing: is a testing method which is used to test the software without knowing internal
structure of code or program. This testing focuses on validating the functionality based on the
provided specifications or requirements.
• Black box testing is also known as Behavioral Testing or Specification Based Testing,
Functional testing, data-driven testing, closed box testing.
Functional: is a type of Software Testing in which the system is tested against the functional
requirements and specifications.
• This testing is not concerned with the source code of the application. Each functionality of
the software application is tested by providing appropriate test input, expecting the output,
and comparing the actual output with the expected output.
• This test focuses on checking the user interface, APIs, database, security, client or server
application, and functionality of the Application Under Test.
• Functional testing can be manual or automated.
pg. 6
• It focuses on the software’s performance, usability, and scalability.
Equivalence Partitioning:
• Is a technique which divides the application input test data into various partition and selects
data from which the test cases can be derived.
• It reduces test cases and saves time.
We use ECP & BVA techniques in input domain testing (positive & negative testing).
Decision Tables:
• Decision table is a good way to settle different combination inputs with their corresponding
outputs.
• It is also called a cause-effect graphing.
• This tech will be used if we have more conditions and corresponding actions.
• Ex: transfer money.
State Transition:
• If there is a change in input conditions, there is a change in the state of application.
• It allows the tester to test the behavior of an AUT.
• Testing team provides Positive & Negative input test values for evaluating the sys behavior.
Error Guessing:
Guessing errors in the app is based on testers experience and analytical skills.
pg. 7
White-Box testing: is a testing method that involves testing the internal structure and workings of
a Software Application. We need to have coding knowledge.
• White box testing is also known as Structure / Structural testing or Transparent testing or
Code-based testing, clear box testing.
Unit Testing: is the process of testing individual software components or “units” of code to ensure
that they are working as intended. (Coding is required for testing)
Integration testing: Integration testing is the process of testing how different components of the
software work together. This level of testing typically involves testing the interactions between
different units of code and how they function when integrated into the overall system.
Grey-Box Testing: Tester has partial knowledge, such as access to design documents but not the
source code.
• Uses both dynamic and limited static analysis tools depending on available knowledge.
• Also known as Translucent testing.
1) Unit Testing: is the process of testing individual software components or “units” of code to
ensure that they are working as intended. (Coding is required for testing).
Mutation testing: testing the code with multiple input data. (automaton tools: TestNG, Junit)
2) Integration testing: Integration testing is the process of testing how different components of the
software work together. This level of testing typically involves testing the interactions between
different units of code and how they function when integrated into the overall system.
pg. 8
There are 3 types:
• Top-Down: incrementally adding the modules and testing the data flow b/w them, and
ensure module added is the child of previous module (existing).
o Ex: compose email (p) ---> send (c) ---> delete (c)
• Bottom-Up: incrementally adding the modules and testing the data flow b/w them, and
ensure module added is the parent of previous (existing) module.
o Ex: send (c) ---> compose (p)
Non-incremental integration: adding all modules in a single shot and testing the data flow b/w
them.
Drawbacks:
• If there are any defects we can't understand the root cause of defects.
• we may miss data flow b/w some modules.
3) System testing: is the process of testing the entire software system to ensure that it meets the
specified requirements and is working as intended. This level of testing typically involves testing the
software’s functionality, performance, and usability.
• It is also known as end-to-end testing.
Functional Testing: is a type of Software Testing in which the system is tested against the functional
requirements and specifications. Each functionality of the software application is tested by
providing appropriate test input, expecting the output, and comparing the actual output with the
expected output.
Functionality Testing: Functionality testing is subtest of functional testing. During this test, we
validate correctness and completeness of every functionality or requirement in the build with
respect to functionality coverage's:
pg. 9
Database testing:
• We send the data through UI and login into the database and write queries then check the
data in Database. (whenever we perform an action in UI, database will be affected).
• Data will be stored in the form of tables.
• It includes the combination of White Box Testing (database) and Black Box Testing (ui) which
we call Grey Box Testing.
• we mainly focus on DML (Data Manipulation Language) operations
o Select, Insert, Update, Delete.
Error Handling:
• we verify the Error message while performing incorrect actions on the application. (what
kind of error should be displayed will be given in doc).
• Error messages should be readable and in user understandable language.
Non-Functional Testing: will be done only after completion of functional testing and app is stable
(done by separate team)
Performance testing: is focused on evaluating the performance of application to determine how fast
some aspect of a system performs under a specific workload.
• Load testing: gradually increasing the load (users) on the app slowly, then check the speed
of the application. (we can increase the load by using tools)
o We need to note at what point server breakdowns. (benchmark)
• Stress testing: suddenly increase / decrease the load (Too many users, too much data, too
little time) on the app and then checks the speed of the app.
• Volume testing: check how much amount of data the application can handle.
pg. 10
Security testing: is focused on identifying and evaluating the security risks associated with a
software system. This can include testing how the system responds to different types of security
threats, such as hacking attempts, and evaluating the effectiveness of the system’s security
features.
• Authentication: users valid or not
• Authorization / Access: User can access only some features.
Compatibility testing: This makes sure the system works well across different hardware, software,
and network environment.
Usability testing: This evaluates how easy and user-friendly the system is, making sure it provides
good experience for users.
4) User Acceptance Testing: is the final stage of dynamic testing, which is done to ensure that the
software meets the needs of the end users and is ready for release. This level of testing typically
involves testing the software’s functionality and usability from the perspective of the end-user.
Alpha testing: is performed by tester who are usually an internal employee of an organization.
Beta testing: is performed by the client or end users who are not an employee of an organization.
Regression Testing: means testing the software application when it undergoes a code change to
ensure that the new code has not affected existing functionality of software before its release.
• It looks for unexpected side effects.
Regional Regression: testing the modified module along with the impacted modules.
Full Regression: Testing the main feature & remaining part of application.
• If changes are made in many modules, instead of identifying impacted modules we do one
round of full regression.
Re-testing means testing the functionality or bug again to ensure it is fixed. If it is not fixed, defect
needs to be re-opened.
pg. 11
End-To-End Testing: Testing the overall functionalities of the sys including the data integration
among all the modules is called end-to-end testing.
• Ex: login ---> send mail ---> delete mail ---> search bin ---> logout
Exploratory Testing: We must explore the application, understand it (Identify all possible scenarios,
doc it) then use it for testing. We do this testing when the app is ready but there is no requirement.
Drawback:
• Misunderstand a feature as a bug / bug as a feature.
• Time consuming.
Ad hoc Testing: is an informal testing where tester tries to 'break' the system by randomly trying the
system's functionality. Tester should have in-depth understanding about the System.
• Can be achieved with the testing technique called Error Guessing.
• Ad hoc testing is also referred to as random testing and monkey testing.
• Can be performed when there is limited time to do exhaustive testing and usually performed
after the formal test execution
AD HOC testing vs EXPLORATORY testing vs MONKEY testing: No documents (test cases, FRS,
scenarios), no plan, informal testing, random testing is common in all.
Ad hoc Monkey Exploratory
Testers should know app Testers doesn't know app Tester doesn't know app
functionality functionality functionality
Intension is to break the Intension is to break the Intension is to explore and
app/find defects app/find defects learn the functionality of app
Suitable for any application Gaming app any app which is new to tester
pg. 12
Globalization and Localization Testing:
Globalization / Internationalization (I18N) Localization
Performed to ensure the sys / software app can Performed to ensure the sys / software app
run in any cultural or local environment can run in specific geographical and cultural
environment.
supports every language and different supports specific language and usable only in
attributes. specific region.
It tests different currency formats, mobile no, Tests specific currency formats, mobile no, and
and address formats are supported by the app address formats are working properly or not
pg. 13
Tools for analyzing HTTP traffic:
• Wireshark: it's to check all data that passes through the network.
• Firebug: It is the most popular Firefox plugin which can monitor AJAX Transactions. (Though
it's essential feature is to fetch web elements locators).
• Live HTTP Headers: it is Firefox add-on which is helpful for previewing HTTP Headers.
• Browser Mob Proxy: it adds additional functionality into selenium WebDriver for running
automated tests.
When the malicious code is inserted in the page and clicked by some user, the malicious code
becomes part of the web request of the user.
pg. 14
Q: Difference between Static and Dynamic websites?
Static Website Dynamic Website
Contains Web pages with fixed content. Content of the web page changes all the time.
Easy to create & don't require any database Require good knowledge to develop the
design. website with programming and database
knowledge.
user cannot communicate with other and User may communicate with each other.
same information will be displayed to each
user.
pg. 15
STLC (Software Testing Life Cycle)
Q: What is STLC?
A: STLC stands for Software Testing Life Cycle. It is a part of SDLC, used by software companies to
design, develop and test software's.
Phases of STLC:
Requirement Analysis --> Test Plan (Design) --> Environment setup --> Execution --> Test closure
Test plan: Is a doc that describes the test scope, test strategy, objectives, schedule, deliverables,
and resources required to perform testing for an app.
• Test Scope: What to Include and Exclude while testing, what will be the test Environment.
• Test Strategy: Whether to go for manual testing or Automation testing.
• Tools: Which tools might be needed.
• Entry and Exit criteria: When to start and end the testing.
• Resources: How many testers do we need to test this.
• Test schedule: When the test must be completed.
• Test deliverables: What to deliver at the end.
Test Design:
This phase involves creation, verification and rework of test cases & test scripts. We design what to
test in the functional requirements. We test Based on:
• Use Case: Describes the Functional Req Specifications.
o use case contains 3 items:
▪ Actor (user): performs action and gets the outcome.
▪ Action: process
▪ Outcome / Goal: successful user outcome
• Test Scenario: (use cases)
o A possible area to be tested (on what exactly we must conduct testing in the app)
• Test Case: (it needs to get approved)
o Step-by-step actions to be performed to validate functionality of AUT (how to test)
o It contains test steps, expected results & actual results.
pg. 16
Q: What is the Requirement Traceability Matrix (RTM)?
A: RTM describes the mapping of requirement specifications with test cases. It’s main purpose is to
see that if all test cases are covered so no functionality is missed during software testing.
• One Requirement can have multiple test cases.
Test Execution: During this phase test team will carry out the testing based on the test plans and
the test cases prepared. Bugs will be reported back to the development team for correction and
retesting will be performed.
Entry criteria: test cases, test data, test plan. (We need to have these prepared before execution)
Activities:
• Test cases are executed based on test plan.
• Status of test cases are marked like passed, failed, skipped, blocked…
• Doc of test result and log defects for failed cases is done.
• All failed and blocked test cases are assigned with bug id's.
• Retesting once defects are fixed.
• Defects are tracked till closure.
Test cycle closure: Will stop the testing once we meet the criteria. (should not have bugs,)
Activities:
pg. 17
----------
evaluate cycle completion criteria based on time, test coverage, cost, software, critical business
objectives, and quality.
prepare test metrics based on the above parameters.
prepare test summary report.
test result analysis to find out the defect distribution by type and severity.
deliverables:
-------------
test closure report
test metrics
Deliverables: Provides defect and test case execution report with completed results.
Test metrics: To prepare for test metrics we need to collect some data so we can track progress.
number of req
avg no of test cases written per req
total no of test cases written for all req
total no of test cases executed
Number of test cases passed, failed, blocked, un-executed.
Total number of defects identified.
critical, higher, medium, lower defect count.
Number of defects found in UAT.
customer defects. (raised by customer production)
pg. 18
DEFECT / BUG Cycle
Defects / Bugs:
Any mismatched functionality found in the app is called defect / bug / issue. (expected vs actual)
Tester report defects to developers through templates / tools.
Defect Cycle:
If Fixed
When we are executing the test cases if the excepted result and actual result are not same, we come
across the defect, then the defects are raised to the developer
New: Tester logs a new defect with all the required details (steps, severity, screenshots, logs...)
Assigned: The defect is assigned to a developer or a relevant team member for investigation.
In Progress: The developer starts working on the issue. The status may be updated to "Open" or "In
Progress".
pg. 19
Fixed / Resolved: The developer resolves the issue and marks it as "Fixed". The code is updated,
and the fix is available for testing.
Retest: The tester re-tests the issue in the new build or environment to verify the fix.
Reopened: If the issue is still present, the tester reopens the defect, and it goes through the cycle
again.
Closed: The defect is finally closed if the fix is confirmed in production or agreed upon by client.
Request for enhancement (RFE): Tester raises the defect for something which is not given in the
requirement so the developer will take it as suggestion. and changes the status as RFE.
Severity and priority come under defect classification: (it is testers responsibility to classify)
Priority: priority describes the importance of the defect and tells the order in which a defect should
be fixed.
• P0 (High): must be resolved immediately as it affects the sys severely and cannot be used
until it is fixed.
• P1 (Medium): It can wait until a new build / version is released. (within the same release)
• P2 (Low): Can be fixed in later releases. (1 release can have multiple versions)
pg. 20
Severity: It describes the seriousness of the defect and how much it impacts on business workflow
2) Critical: the main functionality is not working. customer business workflow is broken.
ex: fund transfer is not working / ordering product is not working in app.
3) Major: it causes some undesirable behavior, but still the feature/app is functioning correctly.
ex: after sending mail / cab booking there is no confirmation msg.
Defect Resolution:
After receiving defect report from testing team, dev team will conduct a review meeting to fix
defects, then they send a resolution to testing team for further comm.
Resolution types:
Accept
Reject
Duplicate (already reported)
Deferred / Enhancement (new feature which comes in next release)
Cannot Reproduce (defect not found in dev environment, need more info like screen shots, logs)
Fixed
Working as designed.
Defect removal Efficiency: (fixed defects/ (fixed defects + missed defects)) * 100
Defect leakage: (no of defects found in UAT/no of defects found in testing) * 100.
pg. 21
Selenium and its components
Selenium is an open-source tool used for automating web browser interactions. It is mainly used for
functional and regression testing of web applications. Selenium supports multiple Bowsers, OS &
languages including (Java, Python, C#, Ruby, JavaScript (Node.js), Kotlin).
Components:
• Selenium WebDriver – Directly interacts with web browsers.
• Selenium IDE – Record-and-playback tool for quick tests.
• Selenium Grid – Enables parallel execution across different machines and browsers.
• Selenium RC (Remote Control) – Now deprecated; used to support older browsers and was
replaced by WebDriver.
Limitations of Selenium:
• Only tests web applications (not desktop/mobile apps).
• Cannot handle CAPTCHA or barcode scanning.
• Limited ability to interact with OS-level features like file uploads.
• No built-in reporting or test management.
• Cannot perform visual verification testing unless integrated with tools like Sikuli or Applitools.
Java:
• Install Java & eclipse IDE latest version
• Create maven Project (quick start = 1.4)
• In POM.xml add Selenium & webDriverManager api dependencies.
Import org.openqa.selenium.webdriver
import org.openqa.selenium.chrome.ChromeDriver;
driver.get("https://example.com");
Python:
• Install python and PyCharm community edition latest versions
• Run pip command (pip install selenium and pip install webdriver-manager)
• In PyCharm project File >> settings >> Project Interceptor >> Install Selenium & webdriver-
manager packages.
chrome_obj = Service(r"C:\Drivers\chromedriver-win64\chromedriver.exe")
driver = webdriver.Chrome(service=chrome_obj)
OR
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
driver.get(“url”)
We can launch any browser in the same manner by changing the browser name.
pg. 1
Headless Browsing using Selenium
A headless browser is a web browser that runs without a graphical user interface (GUI). It
behaves like a regular browser—loading pages, taking screenshots, executing JavaScript,
clicking buttons—but it does so in the background.
Benefits:
• Faster test execution
• Suitable for automation on servers or CI environments
• No need for display, less resource usage
Drawbacks:
• Difficult to debug visually
• Some UI interactions (like hover menus, modals) may behave differently
• Timing issues may be more common
• Cannot report errors related to images.
How to launch headless browser: There are several headless browsers available some are:
• Chrome
• Firefox
• htmlUnitDriver
# Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
# Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_obj = Service("C:/Drivers/chromedriver.exe")
options = Options()
options.add_argument("--headless")
driver = webdriver.Chrome(options=options, service=chrome_obj)
driver.get("https://example.com")
pg. 2
HtmlUnitDriver: is a headless browser driver in Selenium for Java that uses HtmlUnit, a Java-
based headless web browser. It does not open a real browser window. it’s lightweight and fast.
Note If you're using Maven, you need to add this htmlunit-driver dependency in POM.xml
manually since it's not bundled with Selenium 4.
# Java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
driver.get("https://example.com");
}
}
Quick Notes:
• Even though there's no visible UI, we can still capture screenshots using selenium
methods like:
Java:
TakeScreenshot ts = (TakesScreenshot)driver;
File src = ts.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(src, new File(path))
Python:
driver.save_screenshot(path + “name.png”)
• If a test passes in headed mode but fails in headless, then this usually points to timing
or rendering issues. We can troubleshoot it by:
o Adding explicit waits
o Take screenshots or pint HTML to debug.
• Common issues in headless mode include: (these can be debugged using above step)
o Elements not found due to timing issues or lazy loading
o JavaScript execution delays
o UI differences causing layout-dependent actions (like clicks) to fail
• It is possible to simulate user interactions like mouse hover or drag-and-drop using
ActionChains in headless mode, but behaviour may vary. If hover effects rely on pixel
rendering, they might not trigger correctly.
pg. 3
Locators in Java & Python:
In Selenium, locators are used to identify elements on a web page.
There are several types of locators available in Selenium for finding web elements.
# Java
driver.findElement(By.id("submit_button"))
# Java
driver.findElement(By.name("element_name"))
Class Name: The Class Name locator is used to find elements by their class attribute.
# python
driver.find_element(By.CLASS_NAME,"input-field")
# Java
driver.findElement(By.className("input-field"))
TagName: The Tag Name locator is used to find elements by their HTML tag name.
# python
driver.find_element(By.TAG_NAME,"button")
# Java
driver.findElement(By.tagName("button"))
Link Text: The Link Text locator is used to find links (anchor tags) by their exact text.
# python
driver.find_element(By.LINK_TEXT,”full text of the link”)
# Java
driver.findElement(By.linkText(“full text of the link”))
Partial Link Text: The Partial Link Text locator finds links by a part of their text.
# python
driver.find_element(By.PARTIAL_LINK_TEXT,” some text of the link”)
# Java
driver.findElement(By.partialLinkText("some text of the link"))
pg. 1
CSS Selector: The CSS Selector locator is used to find elements using CSS selectors.
• Tag and ID → #
• Tag and Class → .
• Tag and Attribute → [attribute=value]
• Tag, class and Attribute → .[attribute=value] Note! Tagname is optional in syntax.
Tag and ID selector: Uses TagName and value of ID, to find element.
# Python
driver.find_element(By.CSS_SELECTOR,”tagname#valueofID”) or (By.CSS_SELECTOR,”#valueofID”)
# Java
driver.findElement(By.cssSelector("#submit_button"))
Class selector: The Class selector selects elements with a specific class attribute.
# python
driver.find_element(By.CSS_SELECTOR,”.valueofclass”)
# Java
driver.findElement(By.cssSelector(".input-field"))
Attribute:
# python
driver.find_element(By.CSS_SELECTOR,”[attributre=value]”)
# Java
driver.findElement(By.cssSelector("[attributre=value]"))
# Java
driver.findElement(By.cssSelector(".valueofClass[attributre=value]"))
# Java
driver.findElement(By.xpath("//input[@name='username']"))
Absolute XPath: Absolute XPath is the full path from the root element (or html tag) to the target
element. It begins from the root node (/) and follows the entire path through each node until the
desired element is reached.
• Absolute XPath starts with a single / and includes the full path.
pg. 2
o /html/body/div[1]/div[2]/button
Advantages:
• Easy to write if you have a small or simple page structure.
• Works when the element’s position in the hierarchy is static.
Disadvantages:
• Brittle: It is highly sensitive to changes in the page structure (e.g., adding/removing elements
may break the XPath because it's fully dependent on the exact structure).
• Longer: Since it specifies the complete path, it can be long and cumbersome to write.
# python
driver.find_element(By.Xpath,” /html/body/div[2]/div[3]/input[1]”)
# Java
driver.findElement(By.xpath("/html/body/div[2]/div[3]/input[1]"))
Relative XPath: Relative XPath starts from any point in the document and can be used to find an
element more flexibly.
• Relative XPath begins with //, which allows searching anywhere in the document, not
necessarily from the root.
o //button[@id='submit']
Advantages:
• More flexible: Can start from any element and navigate to the desired one, works even if the
structure of the page changes, as long as the relative element is still present.
• Shorter and easier to write: You don’t need to specify the full path to the element.
• Can be more robust: Easier to maintain since it’s less dependent on a strict document
hierarchy.
Disadvantages:
• Can be less specific: If not written carefully, it can match multiple elements, which might
lead to ambiguity.
• May require you to ensure uniqueness by using attributes like @id or @name.
# python
driver.find_element(By.XPATH,"//input[@name='username']")
# Java
driver.findElement(By.xpath("//input[@name='username']"))
pg. 3
XPath Options / Operators
Logical Operators (AND, OR, NOT ())
Contains ()
Starts-with ()
Text ()
# Python
driver.find_element(By.XPATH, “//input[@type='text' and @name='username']”)
# Python
driver.find_element(By.XPATH, “//button[@id='login' or @class='submit-btn']”)
# Python
driver.find_element(By.XPATH, “//input[not(@disabled)]”)
Contains ():
# Java
driver.findElement(By.xpath("//div[contains(@class, 'item')]"));
# Python
driver.find_element(By.XPATH, “//div[contains(@class, 'item')]”)
Text ():
# Java
driver.findElement(By.xpath("//a[text()='Submit’]"));
# Python
driver.find_element(By.XPATH, “//a[text()='Submit']”)
Starts-with ():
# Java
driver.findElement(By.xpath("//input[starts-with(@id, 'user')]"));
# Python
driver.find_element(By.XPATH, “//a[text()='Submit']”)
1
Waits: in Java & Python
In Selenium, there are three main types of waits that help manage dynamic elements that take time
to load or change on a webpage.
Implicit Wait:
• Purpose: Tells Selenium to wait for a certain amount of time before throwing a
NoSuchElementException when trying to find an element.
# Java
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
# Python
driver.implicitly_wait(10)
Explicit Wait
• Purpose: Waits for a certain condition to be true before proceeding. It's more flexible than
implicit waits because you can define different wait conditions for different elements.
• Behaviour: Explicit waits are applied only to specific elements and are used when waiting for
specific conditions like element visibility, presence, or click ability.
# Java
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
# Python
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Page 1 of 2
Fluent Wait
• Purpose: It’s a more advanced version of explicit wait where you can specify the frequency
with which the condition should be checked.
• Behaviour: You can customize both the timeout and the polling interval (how often it checks
the condition).
# Java
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import java.time.Duration;
import java.util.function.Function;
In python we don’t have fluent wait, but we can achieve similar functionality by using the
WebDriverWait in combination with the expected_conditions module and by specifying polling
intervals for checking the condition.
Implicit Wait Sets a global wait time for all Simple cases where all elements might take time to appear.
elements.
Explicit Wait Waits for specific conditions for a Use when a specific condition needs to be met (visibility,
given element. clickable, etc.).
Fluent Wait Advanced explicit wait with custom Advanced cases requiring frequent checks (polling) or
polling interval and timeout exceptions to be ignored.
Page 2 of 2
Actions Class: in Java & Python
Actions class is used for simulating advanced user interactions like mouse movements, keyboard
actions, and drag-and-drop operations.
In Java: We need to Initialize the Actions class and type cast it to driver
• We can do so by writing: Actions action = new Actions(driver)
• After initializing we can class all the action methods available in Actions class
In Python: We need to initialize the Actions class and type cast it to driver
• We can do so by writing: actions = ActionChains (driver)
• After initializing we can class all the action methods available in Actions class
Below are some of the common methods available in the Actions class in both Java and Python:
moveToElement (): Moves the mouse to the middle of the specified element.
Syntax:
# Java
# Python
actions = ActionChains(driver)
actions.move_to_element(element).perform()
# Java
actions.click(element).perform();
# Python
actions.click(element).perform()
# Java
actions.doubleClick(element).perform();
# Python
actions.double_click(element).perform()
Page | 1
contextClick () (Right-click): Performs a right-click (context click) on an element.
# Java
actions.contextClick(element).perform();
# Python
actions.context_click(element).perform()
# Java
actions.dragAndDrop(sourceElement, targetElement).perform();
# Python
actions.drag_and_drop(source_element, target_element).perform()
# Java
actions.sendKeys(element, "text").perform(); actions.sendKeys(Keys.ENTER).perform();
# Python
actions.send_keys(element, "text").perform() actions.send_keys(Keys.ENTER).perform()
Multiple Keys keyDown () and keyUp (): Used for pressing and releasing modifier keys (like Shift, Ctrl, or Alt).
# Java
actions.keyDown(Keys.CONTROL).sendKeys("A").keyUp(Keys.CONTROL).perform();
# Python
actions.key_down(Keys.CONTROL).send_keys("A").key_up(Keys.CONTROL).perform()
Build (): Builds the sequence of actions but doesn’t execute them until perform () is called. (This
method is only in java)
actions.moveToElement(element).click().build().perform();
# Java
actions.moveByOffset(50, 100).perform();
& Python
actions.move_by_offset(50, 100).perform()
Page | 2
How to Scroll to the element: using Java & Python
If you want to click or perform any action on UI but the element is not interactable / visible at the
bottom, so we need to scroll to that element we can do so by using JavaScript / Actions call:
# Java
WebElement element = driver.findElement(By.id("bottom-element-id"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView(true);", element);
window.scrollTo(): This method allows you to scroll to a specific set of coordinates (x, y) on the page.
syntax:
# Python
driver.execute_script("window.scrollTo(0, 1000);") # scroll till the 1000px in Y coordinate
X: value (usually 0), Y: value (how far down you want to scroll).
pg. 1
Scrolling to the Bottom of the Page (fixed page):
Syntax:
# Python
driver.execute_script(“Window.scrollTo(0, “document.body.scrollHeight);”)
# Java
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollTo(0, document.body.scrollHeight);")
Scrolling to the Bottom of the Page (Infinite Scroll): For pages with infinite scrolling (like social media
feeds), you can use a loop to keep scrolling until the end is reached.
Syntax:
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
Using Keys to Scroll (e.g., Arrow Keys or Page Up/Down): You can simulate pressing the Page Down,
Page Up, Arrow Down, or Arrow Up keys to scroll.
Syntax:
Scrolling with Actions Class (move_to_element): The Actions class provides a way to move the mouse
to an element. While it doesn't technically "scroll" in the traditional sense, it can be used to bring an
element into view by moving the mouse pointer to it.
Syntax:
from selenium.webdriver.common.action_chains import ActionChains
pg. 2
Handling Alerts: in Java & Python
In Selenium, there are three primary types of alerts that can be encountered when interacting with
web pages. These alerts are part of the JavaScript Dialogs that pop up on the page, and Selenium
provides different methods for handling them:
Alert: A simple message box that displays a message to the user and requires acknowledgment (like
clicking "OK"). This is the most basic type of alert.
# Python
alert = driver.switch_to.alert
print(alert.text)
alert.accept()
# Java
Confirm: This alert typically asks the user to confirm an action with "OK" and "Cancel" buttons.
# Python
# Java
Prompt: A prompt dialog allows the user to enter some input before clicking "OK" or "Cancel". It
typically has a text box along with "OK" and "Cancel" buttons.
# Python
prompt = driver.switch_to.alert
prompt.sendKeys("Test input")
prompt.accept()
# Java
Summary:
1|Page
When you encounter alerts that ask for a username and password (often seen as basic
authentication prompts in browsers), Selenium doesn't handle them, these types of authentication
prompts are typically handled by the browser itself.
One of the easiest ways to handle basic authentication prompts is to include the username and
password directly in the URL. The format for this is: “http://username:[email protected]”.
# Python
driver.get(“http://username:[email protected]”)
# Java
You can also bypass the basic authentication dialogs in Chrome and Firefox by using browser
options or profiles.
Chrome:
# python
from selenium Import webdriver
from selenium.webdriver. chrome.options import Options
chrome_options = Options ()
chrome_options.add_argument("--disable-notifications")
or
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
driver.get("http://yourwebsite.com")
# Java
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
profile = webdriver.FirefoxProfile()
profile.set_preference("dom.webnotifications.enabled", False)
profile.set_preference("dom.push.enabled", False)
options = Options ()
driver = webdriver.Firefox(firefox_profile=profile, options=options)
driver.get("http://yourwebsite.com")
# Java
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.FirefoxOptions;
# python
driver.get(url)
get(url): This method is used to load a web page specified by the URL.
• It will open the page and wait for the page to completely load before the script continues
executing.
• Clears browser history stack.
• It is a one-way navigation (i.e., after using get(), you can't use browser history like back() or
forward() to go back to the previous page)
navigate().to(url): This method is part of the navigate() interface in Selenium, which is used for
navigating within the current browser session, without resetting the history.
• Loads a new page, but it doesn't necessarily wait for the page to fully load before moving to
the next command.
• It does not clear the browser history.
• You can use the back() and forward() methods to navigate through the browser’s history
after using navigate().to(url).
Back ():
# Java
driver.navigate().back()
# python
driver.back()
# python
driver.forward()
# python
driver.refresh()
1
Select a value from DropDown uSing Java & python
To select a value from a dropdown in Selenium, you can use the Select class, which is provided by
Selenium WebDriver. This class allows you to interact with <select> elements (dropdowns) on a web
page.
Create an instance of the Select class: Pass the dropdown element to the Select constructor.
# Java
WebElement element = driver.findElement(By.Id(“value”));
Select obj = new Select(elemenet);
# python
element = driver.find_element(By.ID,“value”)
select = Select(element)
• SelectbyVisibleText
• SelectByValue
• SelectByIndex
# Java
Select obj = new Select(elemenet);
select.selectByVisibleText("Option 1");
# python
select = Select(element)
select.select_by_visible_text("Option 1")
# Java
Select obj = new Select(elemenet);
select.selectByValue("Option 1");
# python
select = Select(element)
select.select_by_value("Option 1")
# Java
Select obj = new Select(elemenet);
select.selectByIndex(0);
# python
select = Select(element)
select.select_by_index(0)
Page | 1
In Selenium, you can deselect values from a dropdown list by using the Select class. However,
deselecting options is only possible for multi-select dropdowns. For single-select dropdowns,
deselection is not supported, as you can only select one option at a time.
• Ensure the dropdown element has the multiple attribute (Tag). This allows selecting multiple
options.
• deselectByValue(String value): Deselects the option with the given value attribute.
• deselectByVisibleText(String text): Deselects the option with the given visible text.
# Java
Select select = new Select(dropdown);
// Deselect options
select.deselectByVisibleText("Option 1"); // Deselect by visible text
select.deselectByValue("option2-value"); // Deselect by value
select.deselectByIndex(1); // Deselect by index
select.deselectAll(); // Deselects all selected options
# python
select = Select(dropdown)
Page | 2
Frames: in Java & Python
Frames (like <iframe> or <frame>) are HTML elements that embed another HTML document within
the main page. This creates a kind of "page within a page."
There are two main types:
• <iframe> – inline frame (most common today)
• <frame> – older, used in <frameset> (mostly obsolete)
Both Java and Python Selenium bindings provide methods to switch into frames, interact with their
elements, and then switch back to the main content.
Using Index: we can switch to the frames using their index number, mostly preferred when there are
a smaller number of frames.
# Java
driver.switchTo().frame(0);
# Python
driver.switch_to.frame(0)
# Java
driver.switchTo().frame(“Value of ID attribute”);
# Python
driver.switch_to.frame((“Value of Name attribute”)
Using Element: We can switch to the frames using the web element (Locators)
# Java
WebElement ele = driver.findElement(By.Xpath(“//frame[@class = ‘value’]”));
driver.switchTo().frame(ele);
# Python
Ele = driver.find_element(By.XPATH, “//frame[@id = ‘value’]”)
driver.switch_to.frame(Ele)
Default frame: If user wants to perform an action inside a frame, they first need to switch to that frame
and perform the action, Once the action is performed, they can directly come out of the frames using
.default_content() to interact with other elements in the UI.
# Java
driver.switchTo().frame(“Value of ID attribute”);
driver.switchTo().defaultContent(); // Switch back to main content
# Python
driver.switch_to.frame((“Value of Name attribute”)
driver.switch_to.default_content()
Nested Frames: are just frames inside other frames. To interact with a child frame, the user must first
switch to the parent frame, then to the child. After performing actions inside the child frame, they can
either use .default_content() to go back to the main page, or
[1]
use .parentFrame() to continue working in the parent frame.
# Java
driver.switchTo().frame(“Value of ID attribute”);
driver.switchT0().parentFrame(); // Switch to parent frame
driver.switchTo().defaultContent();
# Python
driver.switch_to.frame((“Value of Name attribute”)
driver.swicth_to.parent_frame()
driver.switch_to.default_content()
# Python
Handle = driver.current_window_handle
print (Handle)
All window handles: We use this to get all windows handles ID, which are opened.
# Java
Set<String> handles = driver.getWindowHandles(); Return type of getWindowHandles() is set<string>
# Python
driver.swicth_to.window(handle)
To switch between multiple windows, first get the Id’s of all the windows and run a loop:
Java Python
Set<String> handles = driver.getWindowHandles(); all_handles = driver.window_handles
for (String handle : allHandles) {
if (!handle.equals(currentHandle)) { for handle in all_handles:
driver.switchTo().window(handle); if handle != current_handle:
} driver.switch_to.window(handle)
}
[2]
Cookies using Java and Python
Cookies are small pieces of data that websites store on a user's browser. They are used to:
• Maintain user sessions (e.g., stay logged in)
• Track user activity (e.g., analytics, ads)
• Save user preferences.
In Selenium, you can access, add, or delete cookies while automating browser tasks.
Access:
Single Cookie
# Java
driver.manage.getCookieNamed(“attribute”);
# Python
driver.get_Cookie(“attribute”)
Multiple cookies
# Java
Set<Cookie> cookies = driver.manage.getCookies();
# Python
Cookies = driver.get_Cookies()
Add:
we can add cookies only in dictionary format (key: value) pair
# Java
Cookie new = new Cookie ("myCookie", "cookieValue123");
driver.manage().addCookie(new);
# Python
driver.add_cookie({"name”:"--GUI_", "value":"123"})
Delete:
# Java
driver.manage().deleteCookieNamed("myCookie"); // Specific cookie
driver.manage().deleteAllCookies(); // All Cookies
# Python
driver.delete_cookie("myCookie") // Specific cookie
driver.delete_all_cookies() // All Cookies
1
Date Picker: Using Python & Java
A date picker is a user interface element that allows users to select a date from a calendar-style popup,
rather than typing it manually. It typically consists of a text input and a pop-up calendar that can
include month/year navigation and sometimes time selection. interacting with a date picker requires
more than just entering text — because it's often made with JavaScript and responds to clicks or UI
events.
In Python, when we want to compare two dates (displayed_date_obj and target_date_obj) to decide
whether to click Next or Previous buttons in the calendar. It's much more reliable to compare datetime
objects than raw strings. We use strptime() method from the datetime module to do that. It stands for
"string parse time" and allows us to tell Python exactly how to interpret the structure of a date string
using format codes.
# Python
from datetime import datetime
while True:
year = driver.find_element(By.XPATH,"//div[contains(@class,'hasYearDropdown')]").text
displayed_date_obj = datetime.strptime(year, "%B %Y")
if displayed_date_obj == target_date_obj:
break
elif displayed_date_obj < target_date_obj:
driver.find_element(By.XPATH, "(//div[@class='react-datepicker']//button)[2]").click()
else:
driver.find_element(By.XPATH, "(//div[@class='react-datepicker']//button)[1]").click()
In Java, I use ofPattern() method from the DateTimeFormatter module from the java.time package to
parse strings into date objects. It's part of the modern Date-Time API introduced in Java 8.
For example, I can parse a string like "June 2026" with the format "MMMM yyyy" to get a LocalDate
object.
# Java
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
This is helpful for comparing dates, scheduling tasks, or parsing user input from forms or calendars.
1
Here are some of the most useful format codes for strptime() and ofPattern():
Python Java
Code Meaning Example Pattern Meaning Example
%d Day of the month (01 to 31) "05" dd Day of month (2 digits) 01, 12
Month (2-digit
%m Month as a number (01 to 12) "06" MM 06
number)
%p AM or PM "PM" mm Minutes 30
%S Seconds "59"
If the format string doesn't match the input, Python will throw a Value Error, so accuracy is important.
Interviewer: "Can you tell me how you've worked with date pickers in test automation?"
You: Sure, date picker is a user interface element that allows users to select a date from a calendar-
style popup, rather than typing it manually. It typically consists of a text input and a pop-up calendar
that can include month/year navigation and sometimes time selection. In my project, I had to interact
with a dynamic date picker where I have to select both Date and time. Instead of entering values
directly, I opened the calendar, used logic to loop through months by comparing the displayed month-
year with the target date using Python's datetime.strptime() function. and then clicked either the next
or previous buttons to reach the right month and then selected the desired day and time.
2
Screenshots Using Java & Python
Screenshots are like visual proof of your automation results. We take screenshots for:
• Debugging Failures: If a test fails, a screenshot shows you exactly what the user would
see. Super helpful when tracking down issues.
• Reporting: You can attach screenshots to test reports (e.g., Allure, ExtentReports) to
make them more visual and useful for QA teams or clients.
• Visual Validation: Check that a certain element is visible, aligned correctly, or not
broken.
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
Or
# Python
Import os
driver.get_screenshot_as_file("path/to/screenshot.png")
Page | 1
screenshot of a specific element:
# Java
# Python
Driver.quit()
Full Page:
Note Selenium alone doesn’t always capture the full scrollable page, especially in chrome. But
supported in Firefox
# Java
# Python
driver.get_screenshot_as_file("path/to/screenshot.png")
Page | 2
Mischievous Concepts using Java & Python
Get commands (Java) / Application commands (Python)
Conditional commands Browser
commands
find_element() Vs find_elements()
Text vs Attribute
Browser Commands:
Java Python
driver.close(); driver.close Closes only that specific browser where mouse is pointed
driver.quit(); driver.quit Closes all browsers which are opened.
findElement Vs find_elements:
1
Conditional Commands:
Conditions = driver.find_element(By.XPATH, “//*[@attribute = ‘value’]”)
# Java
Conditions.isDisplayed();
Conditions.isEnabled();
Conditions.isSelected(); // is used only for Radio buttons and Checkboxes.
# python
Conditions.is_displayed()
Conditions.is_enabled()
Conditions.is_selected() // is used only for Radio buttons and Checkboxes.
Text Vs Attribute:
Java Python
Text Returns the inner text element.getText(); element.text
of the element
Attribute Returns the value of element.getAttribute(“ID”); element.get_attribute(“ID”)
any attribute of
element
Example:
<input name ="abc" id="email"> [email protected] </input>
getAttribute(id) = email
getText() = [email protected]
# Python
Inputbox = driver.find_element(By.XPATH, “//div[@box=’Value’]”)
Inputbox.clear()
Inputbox.sendkeys(“msg”)
# Java
Loc.getLocation().getX(); or Loc.getRect().getX() // gives the location of x-axis.
Loc.getSize().getHeight(); or Loc.getRect().getDimension().getHeight(); // gives the height.
2
Capture tooltip of an element:
# Java
weblement whatever_name = driver.findElement(By.attr("value"));
string tooltip(anyname)= whatever_name.getAttribute("value");
# Python
Ele = driver.find_element(By.XPATH,”//*[@attr=’value’]”)
Str tool = Ele.get_attribute(“attr”)
Slider:
we can handle the slider with Actions class, Drag & Drop method using X & Y dimensions.
# Java
Actions anyname = new Actions(driver);
anyname.dragAndDropBy(source,xoffset,yoffset).perform(); // source = WebElement
# Python
Act = ActionChains(driver)
Act.drag_and_drop_by_offset(source, x, y).perform() // source = Element
3
Page Object Model (POM) in Selenium
Page Object Model is a design pattern in Selenium used to create an object repository for web
UI elements. It helps in separating the test logic from the page-specific code, which improves
maintainability, readability, and reusability of the automation scripts.
Use of POM:
• Changes in the UI only require changes in one place (page class), not in every test.
• Promotes code reuse.
• Reduces code duplication.
Page | 1
Using Page Factory:
package page_class;
public class LoginPage {
WebDriver driver; this is class Variable
Constructor name should be same as class name.
LoginPage (WebDriver driver) this is local variable which we are calling from Test class.
{
this.driver=driver; Assigning the test class driver (class) to page class driver (local)
PageFactory.initElements(driver, this);
}
Locators
@FindBy (xpath= “//Tagname[@attribute=’value’]”)
List<WebElement> links;
OR
@FindBy (xpath= “//Tagname[@attribute=’value’]”) WebElement username;
Action Methods (we make them public because we call them from many places in the project)
public void any_name()
{
links.click();
}
public void can_be_valid_name(String txt) this can be anything int, float, char
{
username.sendKeys(txt);
}
Page | 2
Handle Web Table in Selenium using Java & Python
"Web tables are HTML elements used to display data in a tabular format using <table>, <thead>,
<tbody>, <tr>, <th>, and <td> tags.
In Selenium, to work with a web table, I typically follow these steps:
1. Locate the table using an appropriate locator like id, xpath, or css selector.
2. Find all the rows within the <tbody> using findElements.
3. Loop through each row, and inside that, find all the <td> elements (columns).
4. Extract and process the data as needed.
Sample HTML table:
<table id="exampleTable">
<thead>
<tr>
<th>Name</th> // represents table header
<th>Age</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr> // represents one row
<td>Alice</td> // represents table data in column
<td>30</td>
<td>New York</td>
</tr>
pg. 1
How to retrieve data based on condition?
Java
for (int r=1; r<= row_count; r++)
{
string any = driver.findElement(By.xpath("//*[@class = 'value']//tr["+r+"]/td[index]")).getText();
if (any.equals("value"))
{
string name = driver.findElement(By.xpath("//*[@id= 'value']//tr["+r+"]/td[index]")).getText();
system.out.printn(name);
}
}
Python
while True:
rows = len(driver.find_elements(By.XPATH, "//table[@id='example']//tbody//tr"))
column = len(driver.find_elements(By.XPATH, "//table[@id='ex']//thead//tr//th//span[1]"))
For dynamic tables, I use WebDriverWait to ensure data is loaded. Then I dynamically locate
rows and columns using find_elements. If the table has pagination, I build a loop to extract data
from each page until the 'Next' button is disabled. I also handle sorting or filtering actions by
interacting with headers or input boxes and reloading the data.
pg. 2