6. TESTING & DEBUGGING
6.1 FUNCTIONAL TESTING :
A. Email Alerts
Objective: Ensure email alerts are sent successfully for all events.
Steps:
1. Replace sensitive variables with test credentials:
Python CODE :
EMAIL_ADDRESS = "test_email@gmail.com"
EMAIL_PASSWORD = "test_password"
TO_EMAIL = "recipient_email@gmail.com"
2. Run the send_email function with various test cases:
Python CODE:
send_email(
"Test Subject",
"This is a test email.",
screenshot_path="screenshot.png" # Optional
)
3. Verify:
§ Email is received in the recipient inbox.
§ Attachments (if any) are intact.
§ Subject and body contain expected content.
B. Clipboard Monitoring
Objective: Ensure clipboard changes trigger email alerts.
Steps:
1. Copy text to the clipboard using Ctrl+C or Right-click → Copy.
2. Check if the text is printed in the console and logged in the email alert.
3. Debug unexpected errors:
§ Error: Clipboard cannot be accessed.
§ Solution: Check for permissions or use an alternative library like pyperclip with administrator privileges.
C. AI Tool Detection
Objective: Detect running processes related to AI tools.
Steps:
1. Open a test application like a browser running ChatGPT.
2. Verify detection and email alert are triggered.
3. Debugging:
§ Error: AI process is not detected.
§ Solution: Add more process names in the ai_tools list or confirm the correct process name using a tool like Task Manager.
D. Keylogging
Objective: Verify keypress detection and alert functionality.
Steps:
1. Press monitored keys (e.g., Tab or any other suspicious key).
2. Check for:
§ Console message indicating key detection.
§ Email alert for the key press.
3. Debugging:
§ Error: Key presses are not logged. Solution: Ensure the script has permission to monitor input (e.g., run as administrator).
E. Active Window Monitoring
Objective: Ensure active window changes are logged and trigger alerts.
Steps:
1. Switch between different applications.
2. Verify:
§ Console logs display the correct active window name.
§ Email alerts contain the correct window details.
3. Debugging:
§ Error: No alerts for window changes. Solution: Test using simplified versions of the win32gui and psutil integration to isolate the issue.
6.2 Debugging Common Errors
Error 1: Failed to send email
Cause:
Incorrect credentials (e.g., email or app password).
SMTP configuration issues.
Solution:
1. Verify EMAIL_ADDRESS and EMAIL_PASSWORD.
2. Confirm that Google App Passwords are enabled.
3. Ensure SMTP settings are correct:
§ Host: smtp.gmail.com
§ Port: 587
4. Log SMTP exceptions for further diagnosis.
Error 2: Clipboard access denied
Cause:
Clipboard locked by another process.
Solution:
Increase the delay in the monitor_clipboard function.
Use exception handling to retry after a short delay.
Error 3: AI process detection failure
Cause:
AI tool process name not included in the detection list.
Solution:
Use Task Manager or psutil to log all running processes and identify the exact process name.
Error 4: Keylogger doesn’t detect keys
Cause:
Insufficient permissions or the pynput library not functioning as intended.
Solution:
Run the script as an administrator.
Add debugging statements in the on_key_press function to ensure the listener is active.
6.3 Integration Testing
Goal: Verify the interaction between modules (email alerts, monitoring tools, etc.).
Steps:
1. Start the script and simulate a sequence of monitored actions:
§ Clipboard change
§ AI tool usage
§ Key press
§ Active window change
2. Ensure all actions trigger appropriate responses and email alerts.
3. Validate:
§ Alerts are not duplicated.
§ System performance is stable during monitoring
6.4 Performance Testing
Test the script under load by opening multiple monitored applications and performing rapid clipboard changes.
Measure:
CPU and memory usage using psutil.
Email response time.
Optimize by reducing monitoring frequency (e.g., increase time.sleep intervals).