Week 5.a.
Bitmap checkpoint for object/window
Aim
To perform a bitmap checkpoint for object/window using Selenium WebDriver by capturing and
verifying screenshots to ensure the visual appearance of the GUI remains unchanged.
Software/Hardware Requirements:
Hardware Requirements
Processor: Intel Core i3+
RAM: 4 GB (8 GB recommended)
Hard Disk: 10 GB free space
System Type: 64-bit architecture preferred
Internet Connection: Required
Software Requirements
Operating System: Windows 10 / 11
JDK-8+, Eclipse IDE
Web Browser – Google Chrome
ChromeDriver – Compatible with browser version
Selenium WebDriver Libraries – selenium4-java JAR files
Environment Setup Steps to Run Selenium Scripts
Step 1: Install Java Development Kit (JDK)
Step 2: Install Java IDE (Eclipse)
Step 3: Create a Java Project
1. Open Eclipse.
2. Go to File → New → Java Project.
3. Provide a project name.
4. Click Finish.
Step 4: Add Selenium version4 WebDriver Libraries
1. Download Selenium WebDriver (selenium-java).
2. Right-click the project → Build Path → Configure Build Path.
3. Go to Libraries tab.
4. Click Add External JARs.
5. Add:
o All JARs inside selenium-java folder
Step 5: Download and Configure ChromeDriver
1. Download ChromeDriver matching the installed Chrome browser version.
2. Place [Link] in a known directory.
3. Set the path in the Selenium script using:
4. [Link]("[Link]", "path_to_chromedriver");
Step 6: Write Selenium Script
1. Create a package inside the project.
2. Create a Java class.
3. Write Selenium WebDriver code using WebDriver and ChromeDriver.
Step 7: Execute the Script
1. Right-click the Java file.
2. Select Run As → Java Application.
Theory
A bitmap checkpoint is used to verify the visual appearance of a GUI object or an entire window
by comparing its bitmap (image) with a previously stored baseline image. Unlike property-based
checkpoints, bitmap checkpoints focus on the look and feel of the application, such as layout,
alignment, colors, and icons.
In Selenium, there is no built-in bitmap checkpoint feature. Therefore, bitmap checkpoints are
implemented by capturing screenshots of GUI objects or windows and comparing them manually
or using image comparison techniques.
Types of bitmap checkpoints:
1. Bitmap checkpoint for an object – verifies the appearance of a single GUI element.
2. Bitmap checkpoint for a window – verifies the appearance of the entire web page or
application window.
package week5;
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];
public class BitmapCheckpointObject {
// Method to compare two images pixel by pixel
public static boolean compareImages(File img1, File img2) throws
Exception {
BufferedImage image1 = [Link](img1);
BufferedImage image2 = [Link](img2);
if ([Link]() != [Link]() || [Link]() !=
[Link]()) {
return false;
}
for (int x = 0; x < [Link](); x++) {
for (int y = 0; y < [Link](); y++) {
if ([Link](x, y) != [Link](x, y)) {
return false;
}
}
}
return true;
}
public static void main(String[] args) throws Exception {
WebDriver driver = new ChromeDriver();
[Link]().window().maximize();
[Link]("[Link]
WebElement heading = [Link]([Link]("login"));
// Capture actual object screenshot
File actual = [Link]([Link]);
File actualImg = new File("actual_object.png");
[Link](actual, actualImg);
// Baseline image (captured earlier)
File baselineImg = new File("C:\\images\\[Link]");
if (compareImages(baselineImg, actualImg)) {
[Link]("Bitmap checkpoint PASSED for object");
} else {
[Link]("Bitmap checkpoint FAILED for object");
}
[Link]();
}
}
Week5. b. Bitmap Checkpoint for Screen Area
Aim
To perform a bitmap checkpoint for screen area using Selenium WebDriver by capturing and
verifying screenshots to ensure the visual appearance of the GUI remains unchanged.
package week5;
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];
public class BitmapCheckpoint {
// Method to compare two images pixel by pixel
public static boolean compareImages(File img1, File img2) throws
Exception {
BufferedImage image1 = [Link](img1);
BufferedImage image2 = [Link](img2);
if ([Link]() != [Link]() || [Link]() !=
[Link]()) {
return false;
}
for (int x = 0; x < [Link](); x++) {
for (int y = 0; y < [Link](); y++) {
if ([Link](x, y) != [Link](x, y)) {
return false;
}
}
}
return true;
}
public static void main(String[] args) throws Exception {
WebDriver driver = new ChromeDriver();
[Link]().window().maximize();
[Link]("[Link]
// Capture actual window screenshot
TakesScreenshot ts = (TakesScreenshot) driver;
File actual = [Link]([Link]);
File actualImg = new File("actual_window.png");
[Link](actual, actualImg);
// Baseline image (captured earlier)
File baselineImg = new File("C:\\images\\[Link]");
if (compareImages(baselineImg, actualImg)) {
[Link]("Bitmap checkpoint PASSED for window");
} else {
[Link]("Bitmap checkpoint FAILED for window");
}
[Link]();
}
}