DEPARTMENT OF INFORMATION SCIENCE AND ENGINEERING
Academic Year: 2023-2024 Odd Semester
Course Code – 20ISE71A
Course Name – Software Testing & Automation
Case Study
SET - 05
Submitted By
Name: LOKESH PRASAD
USN: 1NH20IS078
Semester: 7
Section: B
Date of Submission: 05/12/2023
Marks Obtained : Faculty Sign:
Introduction:
In the dynamic landscape of software development, ensuring the reliability and
functionality of graphical user interfaces (GUIs) is paramount. GUI testing plays a
pivotal role in validating that an application's visual elements and interactive
components meet user expectations and adhere to specified requirements. As the
demand for robust and user-friendly software continues to rise, testers are
exploring innovative tools to streamline the testing process and enhance
efficiency. One such tool gaining prominence in the realm of GUI testing is
PyAutoGUI.
PyAutoGUI, a cross-platform Python library, empowers testers to automate GUI
interactions with ease. Whether navigating through applications, simulating
mouse clicks, or validating visual elements, PyAutoGUI provides a versatile
framework for GUI testing. This case study delves into the application of
PyAutoGUI in the context of GUI testing, exploring its capabilities, benefits, and
challenges. Through real-world scenarios and practical insights, we aim to shed
light on how PyAutoGUI contributes to the overall effectiveness of software
testing, enabling testers to ensure a seamless and error-free user experience.
This is how the User Interfaces of softwares are tested for nuances and
breakdowns. This makes the software robust and bug free.
PyautoGUI: Introduction:
Using PyAutoGUI for GUI testing involves a series of steps to automate mouse and keyboard
interactions with graphical user interfaces. Below is a brief overview of the key concepts and
steps:
1. Installation:
Ensure that PyAutoGUI is installed in your Python environment. You can install it using the
following command:
pip install pyautogui
2. Import the Library:
Import the PyAutoGUI library in your Python script or interactive environment.
import pyautogui
3. Basic Functions:
- Mouse Movements:
- pyautogui.moveTo(x, y): Moves the mouse to the specified coordinates (x, y) on the screen.
- pyautogui.move(x_offset, y_offset): Moves the mouse by the specified offsets from its
current position.
- pyautogui.click(): Simulates a mouse click at the current mouse position.
- pyautogui.doubleClick(): Simulates a double click at the current mouse position.
- Keyboard Inputs:
- pyautogui.typewrite('text'): Types the specified text at the current cursor position.
- pyautogui.press('key'): Simulates a key press for the specified key.
- pyautogui.hotkey('key1', 'key2'): Simulates a combination of key presses.
- Screen Information:
- pyautogui.size(): Returns the screen width and height.
- pyautogui.position(): Returns the current mouse coordinates.
4. Image Recognition:
PyAutoGUI can also perform GUI testing based on visual elements. You can use functions
like pyautogui.locateOnScreen() to find the position of an image on the screen.
image_location = pyautogui.locateOnScreen('image.png')
5. Example Script:
Here's a simple example script that moves the mouse to a specific location, clicks, and types
text:
import pyautogui
# Move the mouse to coordinates (x, y)
pyautogui.moveTo(100, 100)
# Click the mouse
pyautogui.click()
# Type the text 'Hello, PyAutoGUI!'
pyautogui.typewrite('Hello, PyAutoGUI!')
```
6. Error Handling:
It's crucial to implement error handling in your scripts, considering factors like delays
(`pyautogui.sleep()`) to allow GUI elements to load and appear.
7. Testing and Iteration:
Test your script on the target application, and iterate as needed. Adjust coordinates, delays, or
incorporate image recognition as required to ensure accurate and reliable automation.
Remember that PyAutoGUI is a powerful tool, but it may have limitations in certain scenarios.
It's essential to thoroughly test and validate your scripts on different systems and applications to
ensure robust GUI testing automation.
Testing for User Interfaces:
In the intricate tapestry of software development, the graphical user interface (GUI)
stands as the gateway between users and the functionality embedded within an
application. As the digital landscape evolves, the need for seamless and user-friendly
interfaces becomes increasingly imperative. GUI software testing emerges as a critical
practice, ensuring that visual elements and interactive components harmonize to deliver
an optimal user experience. In this exploration, we delve into the realm of GUI software
testing, spotlighting techniques, tools, and best practices, with a focus on the Python-
based PyAutoGUI library.
Understanding GUI Software Testing
The Essence of GUI Testing
GUI testing goes beyond mere functionality checks; it scrutinizes how users interact
with an application's visual elements. From buttons and menus to data input fields and
navigation paths, GUI testing ensures that every pixel aligns with user expectations and
system requirements.
Key Challenges in GUI Testing
Diverse Environments: GUIs must function seamlessly across various devices, operating
systems, and screen resolutions, posing a challenge for testers to validate compatibility
comprehensively.
Dynamic Content: Web applications often feature dynamic content, necessitating GUI
tests that adapt to changing elements and respond to user-triggered events.
Localization: GUIs tailored for different languages and regions require thorough testing
to guarantee linguistic accuracy and cultural appropriateness.
Program
import pyautogui import time import webbrowser
# URL of the login page login_page_url =
"file:///C:/Users/soura/Desktop/ST%20Case%20Study/login.html"
# Open the web browser and navigate to the login page webbrowser.open(login_page_url)
# Wait for the browser to open and load the page (adjust as needed) time.sleep(2)
# Display a message to instruct the user to hover over the username field and wait for 5 seconds
print("Hover over the username field...") time.sleep(5)
username_field = pyautogui.position()
print(f"Username Field Coordinates: {username_field}")
# Display a message to instruct the user to hover over the password field and wait for 5 seconds
print("\nHover over the password field...") time.sleep(5)
password_field = pyautogui.position()
print(f"Password Field Coordinates: {password_field}")
# Display a message to instruct the user to hover over the login button and wait for 5 seconds
print("\nHover over the login button...") time.sleep(5)
login_button = pyautogui.position()
print(f"Login Button Coordinates: {login_button}")
# Perform GUI automation to fill in the username and password
pyautogui.click(username_field) pyautogui.write('user') pyautogui.click(password_field)
pyautogui.write('pass123')
# Click the login button pyautogui.click(login_button)
# Add a delay to allow time for the login process to complete
(adjust as needed)
time.sleep(2)
login.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Login Page</title>
</head>
<body>
<div class="login-container">
<h2>Login</h2>
<form id="loginForm">
<div class="input-group">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
</div>
<div class="input-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<button type="button" onclick="submitForm()">Login</button>
</form>
</div>
<script src="script.js"></script>
</body>
</html>
Script.js
function submitForm() { var username = document.getElementById('username').value; var
password = document.getElementById('password').value;
// Example validation (you should implement server-side validation in a real scenario) if
(username === 'user' && password === 'pass123') { alert('Login successful!');
} else {
alert('Invalid username or password');
}
}
Style.css body {
display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0;
background-color: #f4f4f4;
}
.login-container { text-align: center; padding: 20px; border: 1px solid #ccc; border-
radius: 8px; background-color: #fff; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
h2 { color: #333;
}
.input-group { margin-bottom: 20px;
}
label { display: block; margin-bottom: 8px; color: #666;
}
input { width: 100%; padding: 10px; box-sizing: border-box; border: 1px solid #ccc;
border-radius: 4px;
}
button { padding: 10px; cursor: pointer; background-color: #4caf50;
color: #fff; border: none; border-radius: 4px; }
button:hover { background-color: #45a049;
}
Environment Setup
Installing PyAutoGui
Execution of the GUI testing
Figure 1: Hovering over the Username field
Figure 2: Hovering over the password field
Output Screenshots