Initial commit

This commit is contained in:
Marjorie 2025-05-19 20:13:09 +08:00
commit 7d287aa7b7
30 changed files with 2057 additions and 0 deletions

View File

@ -0,0 +1,75 @@
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
def test_invalid_password_login():
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
# Create 'screenshots' folder if it doesn't exist
if not os.path.exists("screenshots"):
os.makedirs("screenshots")
try:
# Step 1: Open the CMS login page
driver.get("https://stag-cms.unioilapps.com/login")
print("Opened login page")
# Step 2: Enter valid username
username_field = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.NAME, "username"))
)
username_field.send_keys("lbteksupport")
print("Entered valid username")
# Step 3: Click Next
next_button1 = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "button.ant-btn.ant-btn-primary"))
)
next_button1.click()
print("Clicked Next button after username")
# Step 4: Enter invalid password
password_field = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.NAME, "password"))
)
password_field.send_keys("1234")
print("Entered invalid password")
# Step 5: Click Next again
next_button2 = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "button.ant-btn.ant-btn-primary"))
)
next_button2.click()
print("Clicked Next button after password")
# No explicit wait for error message, assume it will show automatically
print("✅ Negative test completed successfully. Password incorrect expected.")
# Take screenshot after test
screenshot_path = os.path.join("screenshots", "password_incorrect.png")
driver.save_screenshot(screenshot_path)
print(f"Screenshot saved as {screenshot_path}")
# Keep the browser open for inspection
print("Test complete. Browser will stay open. Press Ctrl+C to exit.")
time.sleep(10) # Sleep for 10 seconds so you can inspect the browser before closing.
except Exception as e:
print(f"❌ Unexpected error: {e}")
screenshot_path = os.path.join("screenshots", "unexpected_error.png")
driver.save_screenshot(screenshot_path)
print(f"Screenshot saved as {screenshot_path}")
finally:
# You can choose to leave the browser open or close it manually
# driver.quit() # Commented out so you can leave the browser open
print("Browser closed. Test completed.")
if __name__ == "__main__":
test_invalid_password_login()

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 KiB

View File

@ -0,0 +1,67 @@
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
def negative_login_test():
# Set up the Selenium WebDriver
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
# Create 'screenshots' folder if it doesn't exist
if not os.path.exists("screenshots"):
os.makedirs("screenshots")
try:
# Step 1: Open the CMS login page
driver.get("https://stag-cms.unioilapps.com/login")
print("Opened login page")
# Step 2: Enter an invalid username
username_field = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.NAME, "username"))
)
username_field.clear()
username_field.send_keys("lbtek") # Invalid username
print("Entered invalid username: lbtek")
# Step 3: Click the Next button
next_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "button.ant-btn.ant-btn-primary"))
)
next_button.click()
print("Clicked Next button")
# Step 4: Wait for and validate the error message
error_message = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, "//*[contains(text(), 'Username does not exist')]"))
)
print(f"❌ Login failed as expected: {error_message.text}")
# Save screenshot to the 'screenshots' folder
screenshot_path = os.path.join("screenshots", "wrong_username.png")
driver.save_screenshot(screenshot_path)
print(f"Screenshot saved as {screenshot_path}")
# Keep the browser open for inspection
print("Test complete. Browser will stay open. Press Ctrl+C to exit.")
time.sleep(10) # Sleep for 10 seconds so you can inspect the browser before closing.
except Exception as e:
print(f"❌ Test failed with error: {e}")
screenshot_path = os.path.join("screenshots", "wrong_username.png")
driver.save_screenshot(screenshot_path)
print(f"Screenshot saved as {screenshot_path}")
driver.quit()
raise
except KeyboardInterrupt:
print("\n👋 User interrupted the script. Closing the browser.")
driver.quit()
if __name__ == "__main__":
negative_login_test()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

337
about_us_test.py Normal file
View File

@ -0,0 +1,337 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import TimeoutException
import time
import os
import sys
# Import login
try:
from login import login_to_cms
print("✅ Successfully imported login_to_cms from login.py")
except ImportError as e:
print(f"❌ Failed to import login_to_cms: {e}")
sys.exit(1)
def test_about_us_card_type():
driver = None
try:
driver = login_to_cms()
print("✅ Logged in, starting About Us > Card Types test")
wait = WebDriverWait(driver, 20)
# Click the 'About Us' dropdown by targeting the div with exact text
about_us_menu = wait.until(EC.element_to_be_clickable((
By.XPATH, "//div[contains(@class, 'ant-menu-submenu-title')][.//span[text()='About Us']]"
)))
driver.execute_script("arguments[0].click();", about_us_menu)
print("✅ Clicked on 'About Us' to reveal submenu")
# Click "Card Types"
card_types_link = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//a[@href='/about-us/card-types']")))
card_types_link.click()
print("✅ Clicked on 'Card Types'")
# Click "Add Card"
add_card_btn = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//button[.//span[text()='Add Card']]")))
add_card_btn.click()
print("✅ Clicked on 'Add Card'")
# Fill Card Code
card_code_input = wait.until(EC.presence_of_element_located(
(By.NAME, "code")))
card_code_input.send_keys("MARJORIECODE")
print("✅ Inputted Card Code")
# Fill Card Type Description
# Find all inputs with name="type"
type_inputs = wait.until(EC.presence_of_all_elements_located((By.NAME, "type")))
# Input in the first one: Card Type Description
type_inputs[0].send_keys("test card description")
print("✅ Card Type Description input filled")
# Fill in the Card Type Short Description (textarea with name="description")
short_desc_textarea = wait.until(EC.presence_of_element_located((By.NAME, "description")))
short_desc_textarea.send_keys("this is a card type short description")
print("✅ Card Type Short Description input filled")
# Upload Card Type Image
upload_inputs = driver.find_elements(By.CSS_SELECTOR, "input[type='file']")
if upload_inputs:
image_path = os.path.abspath(r"C:\\Users\\MARJORIE ANITO\\unioil_testing\\image\\image.jpg")
upload_inputs[0].send_keys(image_path)
print("✅ Card Type Image uploaded")
time.sleep(3) # wait for upload preview to show
else:
print("❌ File input for Card Type Image not found")
# Select Black radio button
try:
black_radio = driver.find_element(By.CSS_SELECTOR, "input[type='radio'][value='2']")
driver.execute_script("arguments[0].click();", black_radio)
print("✅ Selected 'Black' radio button")
time.sleep(1)
except Exception as e:
print(f"❌ Failed to select 'Black' radio button: {e}")
# Upload Card Type Cover
upload_inputs = driver.find_elements(By.CSS_SELECTOR, "input[type='file']")
if len(upload_inputs) > 1:
cover_path = os.path.abspath(r"C:\\Users\\MARJORIE ANITO\\unioil_testing\\image\\image.jpg")
upload_inputs[1].send_keys(cover_path)
print("✅ Card Type Cover uploaded")
time.sleep(3)
else:
print("❌ File input for Card Type Cover not found")
# Add Terms and Conditions
try:
terms_textarea = driver.find_element(By.NAME, "terms_and_conditions")
terms_textarea.clear()
terms_textarea.send_keys("TESTING")
print("✅ Terms and Conditions entered")
except Exception as e:
print(f"❌ Failed to enter Terms and Conditions: {e}")
# Add FAQs
try:
faqs_textarea = driver.find_element(By.NAME, "faqs")
faqs_textarea.clear()
faqs_textarea.send_keys("TESTING")
print("✅ FAQs entered")
except Exception as e:
print(f"❌ Failed to enter FAQs: {e}")
# Click Submit
try:
submit_btn = driver.find_element(By.XPATH, "//button[.//span[text()='Submit']]")
driver.execute_script("arguments[0].click();", submit_btn)
print("✅ Submit button clicked")
except Exception as e:
print(f"❌ Failed to click Submit button: {e}")
# After clicking Submit, handle error modal if it appears
try:
close_error_icon = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH, "//i[contains(@class, 'ant-notification-close-icon')]"))
)
close_error_icon.click()
print("🟡 Error/notification modal appeared and was closed")
# Click Cancel to exit the form
cancel_btn = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Cancel']]"))
)
cancel_btn.click()
print("✅ Cancel button clicked after closing error modal")
# Click Yes on the confirmation modal
yes_btn = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Yes']]"))
)
yes_btn.click()
print("✅ Clicked Yes on cancel confirmation after error modal")
time.sleep(2)
except TimeoutException:
print(" No error modal appeared, proceeding normally...")
# Search for PRIVATEB
try:
search_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "input[placeholder='Search']"))
)
search_input.clear()
search_input.send_keys("PRIVATEB")
search_input.send_keys(Keys.ENTER)
print("✅ Searched for PRIVATEB")
time.sleep(3) # wait for search results
except Exception as e:
print(f"❌ Search input error: {e}")
# Click View icon
try:
view_icon = driver.find_element(By.CSS_SELECTOR, "i.anticon-right-circle-o")
driver.execute_script("arguments[0].click();", view_icon)
print("✅ View icon clicked")
time.sleep(2)
except Exception as e:
print(f"❌ Failed to click View icon: {e}")
# Click Delete and then No
try:
delete_btn = driver.find_element(By.XPATH, "//button[.//span[text()='Delete']]")
driver.execute_script("arguments[0].click();", delete_btn)
print("✅ Delete button clicked")
no_btn = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='No']]"))
)
no_btn.click()
print("✅ Clicked No on confirmation")
time.sleep(1)
except Exception as e:
print(f"❌ Delete/No click failed: {e}")
# Click Update and then Cancel
try:
update_btn = driver.find_element(By.XPATH, "//button[.//span[text()='Update']]")
driver.execute_script("arguments[0].click();", update_btn)
print("✅ Update button clicked")
time.sleep(2)
cancel_btn = driver.find_element(By.XPATH, "//button[.//span[text()='Cancel']]")
cancel_btn.click()
print("✅ Cancel button clicked")
yes_btn = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Yes']]"))
)
yes_btn.click()
print("✅ Clicked Yes on cancel confirmation")
except Exception as e:
print(f"❌ Update/Cancel sequence failed: {e}")
# Click Terms & Privacy
try:
terms_privacy_link = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//a[@href='/about-us/term-privacy']")))
terms_privacy_link.click()
print("✅ Clicked on 'Terms & Privacy'")
time.sleep(2)
except Exception as e:
print(f"❌ Failed to click 'Terms & Privacy': {e}")
# Click Add button (dropdown trigger)
try:
add_dropdown_btn = wait.until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, "button.terms-management")))
add_dropdown_btn.click()
print("✅ Clicked on 'Add' dropdown")
time.sleep(1)
except Exception as e:
print(f"❌ Failed to click 'Add' dropdown: {e}")
# Click 'Terms & Condition' option
try:
terms_option = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//li[contains(text(), 'Terms & Condition')]")))
terms_option.click()
print("✅ Clicked on 'Terms & Condition'")
time.sleep(1)
except Exception as e:
print(f"❌ Failed to select 'Terms & Condition': {e}")
# Fill in Title
try:
title_input = wait.until(EC.presence_of_element_located(
(By.XPATH, "//input[@name='title']")))
title_input.clear()
title_input.send_keys("T&C Title")
print("✅ Entered T&C Title")
time.sleep(1)
except Exception as e:
print(f"❌ Failed to enter T&C Title: {e}")
# Fill in Details
try:
details_textarea = wait.until(EC.presence_of_element_located(
(By.XPATH, "//textarea[@name='details']")))
details_textarea.clear()
details_textarea.send_keys("T&C Details")
print("✅ Entered T&C Details")
time.sleep(1)
except Exception as e:
print(f"❌ Failed to enter T&C Details: {e}")
# Submit the form
try:
submit_btn = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//button[.//span[text()='Submit']]")))
submit_btn.click()
print("✅ Submitted T&C form")
time.sleep(2)
except TimeoutException as e:
print(f"❌ Failed to submit T&C form: {e}")
# Click Add button (dropdown trigger) again
try:
add_dropdown_btn = wait.until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, "button.terms-management")))
add_dropdown_btn.click()
print("✅ Clicked on 'Add' dropdown")
time.sleep(1)
except Exception as e:
print(f"❌ Failed to click 'Add' dropdown: {e}")
# Select Privacy Policy from the dropdown
try:
privacy_policy_option = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[.//text()='Privacy Policy']"))
)
privacy_policy_option.click()
print("✅ Selected 'Privacy Policy' from dropdown")
time.sleep(1)
except Exception as e:
print(f"❌ Failed to select 'Privacy Policy' from dropdown: {e}")
# Add Title for Privacy Policy
try:
title_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.NAME, "title"))
)
title_input.clear()
title_input.send_keys("PP Title")
print("✅ Inputted Privacy Policy Title")
time.sleep(1)
except Exception as e:
print(f"❌ Failed to input Privacy Policy Title: {e}")
# Add Details for Privacy Policy
try:
details_textarea = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.NAME, "details"))
)
details_textarea.clear()
details_textarea.send_keys("PP Details")
print("✅ Inputted Privacy Policy Details")
time.sleep(1)
except Exception as e:
print(f"❌ Failed to input Privacy Policy Details: {e}")
# Submit the form for Privacy Policy
try:
submit_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Submit']]"))
)
submit_btn.click()
print("✅ Submitted Privacy Policy form")
time.sleep(2)
except TimeoutException as e:
print(f"❌ Failed to submit Privacy Policy form: {e}")
print("🎉 Test completed successfully")
except Exception as e:
print(f"❌ Test failed: {e}")
finally:
if driver:
print("🔒 Closing the browser in 10 seconds...")
time.sleep(10)
driver.quit()
if __name__ == "__main__":
test_about_us_card_type()

142
home_page_mobile_test.py Normal file
View File

@ -0,0 +1,142 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import sys
import os
# Debug: Print the current working directory and list files
print(f"Current working directory: {os.getcwd()}")
print(f"Files in directory: {os.listdir(os.getcwd())}")
try:
from login import login_to_cms
print("✅ Successfully imported login_to_cms from login.py")
except ImportError as e:
print(f"❌ Failed to import login_to_cms: {e}")
sys.exit(1)
def test_home_page_mobile():
driver = None
try:
# Initialize the driver explicitly if test_member_management doesn't
try:
driver = login_to_cms()
print("Driver obtained")
except Exception as e:
print(f"Failed to get driver from login to cms: {e}")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
print("Initialized new Chrome driver")
print("Proceeding to Home Page (Mobile) test")
# Debug: Log all sidebar menu items to find the correct label
sidebar_items = WebDriverWait(driver, 20).until(
EC.presence_of_all_elements_located((By.XPATH, "//div[contains(@class, 'ant-menu-submenu-title')]"))
)
print("Sidebar submenu items found:")
for item in sidebar_items:
item_text = item.text.strip()
item_classes = driver.execute_script("return arguments[0].getAttribute('class');", item)
print(f" - Text: '{item_text}', Classes: {item_classes}")
# Navigate to Home dropdown and click to expand
home_link = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//div[contains(@class, 'ant-menu-submenu-title') and contains(normalize-space(), 'Home')]"))
)
driver.execute_script("arguments[0].scrollIntoView(true);", home_link)
max_attempts = 3
for attempt in range(max_attempts):
try:
home_link.click()
print("Clicked Home to expand dropdown")
break
except Exception as e:
print(f"Attempt {attempt + 1}/{max_attempts} to click Home failed: {e}")
time.sleep(1)
if attempt == max_attempts - 1:
raise Exception("Failed to click Home dropdown after multiple attempts")
# Navigate directly to Photo Slider page
driver.get("https://stag-cms.unioilapps.com/home-page/")
print("Navigated to Photo Slider page directly via URL")
# Locate the search input field
search_input = WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.XPATH, "//input[contains(@class, 'ant-input')]"))
)
time.sleep(1)
print("Search input field is visible")
search_input.clear()
search_input.send_keys("S&R")
search_input.send_keys(Keys.RETURN)
print("Typed 'S&R' into the search field and pressed Enter")
# Wait for the "S&R" row to appear
loyalty_row = WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.XPATH, "//td[contains(text(), 'S&R')]"))
)
time.sleep(1)
print("S&R row is visible")
print(f"Found row text: {loyalty_row.text}")
# Locate the checkbox input for the "S&R" row
checkbox_input = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, "//td[contains(text(), 'S&R')]/preceding-sibling::td//input[@type='checkbox']"))
)
# Scroll into view
driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", checkbox_input)
time.sleep(1)
# Try checking via JS click on its <label> (if it exists)
try:
label = checkbox_input.find_element(By.XPATH, "./ancestor::label")
driver.execute_script("arguments[0].click();", label)
print("Clicked checkbox label using JS")
except:
# If no label, click the checkbox directly
driver.execute_script("arguments[0].click();", checkbox_input)
print("Clicked checkbox input using JS")
# Confirm its checked
time.sleep(1)
checked = driver.execute_script("return arguments[0].checked;", checkbox_input)
print(f"Checkbox is checked: {checked}")
if not checked:
raise Exception("Checkbox is not checked after click.")
# Wait for table to update (with or without results)
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//div[contains(@class, 'ant-table')]"))
)
time.sleep(1) # Small buffer for any animation
# Test completes here, no more actions after this point.
print("✅ Test completed successfully. Browser will remain open. Press Ctrl+C to close the browser.")
while True:
time.sleep(1)
except Exception as e:
print(f"❌ Test failed: {e}")
if driver is not None:
driver.save_screenshot("error.png")
print("Screenshot saved as error.png for debugging")
if driver is not None:
driver.quit()
raise
except KeyboardInterrupt:
print("\n👋 User interrupted the script. Closing the browser.")
if driver is not None:
driver.quit()
if __name__ == "__main__":
test_home_page_mobile()

BIN
image/cover.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 KiB

BIN
image/image.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

71
login.py Normal file
View File

@ -0,0 +1,71 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
def login_to_cms():
# Set up the Selenium WebDriver
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
try:
# Step 1: Open the CMS login page
driver.get("https://stag-cms.unioilapps.com/login")
print("Opened login page")
# Step 2: Locate and fill username field
username_field = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.NAME, "username"))
)
username_field.send_keys("lbteksupport")
print("Entered username")
# Step 3: Locate and click the first Next button
next_button1 = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "button.ant-btn.ant-btn-primary"))
)
next_button1.click()
print("Clicked Next button")
# Step 4: Locate and fill password field on the new page
password_field = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.NAME, "password"))
)
password_field.send_keys("7q$!jAv9!I8HNX")
print("Entered password")
# Step 5: Locate and click the second Next button
next_button2 = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "button.ant-btn.ant-btn-primary"))
)
next_button2.click()
print("Clicked second Next button")
# Step 6: Verify successful login (check for My Profile)
profile_title = WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.XPATH, "//h1[contains(text(), 'Profile')]"))
).text
assert "Profile" in profile_title, f"Login failed: Expected 'Profile', got '{profile_title}'"
print("Login test passed! Landed on My Profile")
return driver
except Exception as e:
print(f"Login failed: {e}")
driver.save_screenshot("error.png")
print("Screenshot saved as error.png for debugging")
driver.quit()
raise
if __name__ == "__main__":
try:
driver = login_to_cms()
print("Login successful, keeping browser open. Press Ctrl+C to close.")
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nUser interrupted the script. Closing the browser.")
driver.quit()

173
member_management_test.py Normal file
View File

@ -0,0 +1,173 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import os
import sys
import time
try:
from login import login_to_cms
print("✅ Successfully imported login_to_cms from login.py")
except ImportError as e:
print(f"❌ Failed to import login_to_cms: {e}")
sys.exit(1)
def test_card_member(driver):
screenshot_dir = os.path.join("screenshots", "card_member_test")
os.makedirs(screenshot_dir, exist_ok=True)
try:
# Step 2: Expand Member Management dropdown
member_management_link = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//div[contains(@class, 'ant-menu-submenu-title') and normalize-space()='Member Management']"))
)
driver.execute_script("arguments[0].scrollIntoView(true);", member_management_link)
member_management_link.click()
print("✅ Clicked Member Management to expand dropdown")
# Step 3: Navigate directly to Card Member page
driver.get("https://stag-cms.unioilapps.com/member-management/card-member")
print("✅ Navigated directly to Card Member page")
# Step 4: Wait for the search input and enter card number
search_input = WebDriverWait(driver, 15).until(
EC.presence_of_element_located((By.XPATH, "//input[@type='text' and @placeholder='Search' and contains(@class, 'ant-input')]"))
)
search_input.clear()
search_input.send_keys("1113168608851474")
print("🔍 Entered card number in search bar")
# Step 5: Wait for results to load
time.sleep(3) # Let results render
# Step 6: Click the View icon
view_icon = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//i[contains(@class, 'anticon-right-circle-o')]"))
)
view_icon.click()
print("👁️ Clicked the View icon")
# Step 7: Wait for 5 seconds to allow viewing the details
time.sleep(5)
print("⏳ Waited for 5 seconds after viewing card details")
# Step 8: Go back to Card Member page
card_member_link = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[@href='/member-management/card-member']"))
)
card_member_link.click()
print("🔙 Clicked 'Card Member' link to go back")
# Step 9: Wait for the page to reload
time.sleep(3)
# Step 10: Take a final screenshot after returning
screenshot_path = os.path.join(screenshot_dir, "returned_to_card_member.png")
driver.save_screenshot(screenshot_path)
print(f"📸 Screenshot saved at: {screenshot_path}")
print("✅ Card Member test completed.")
except Exception as e:
print(f"❌ Test failed: {e}")
driver.save_screenshot(os.path.join(screenshot_dir, "error_card_member.png"))
print("📸 Error screenshot saved.")
raise
except KeyboardInterrupt:
print("\n👋 User interrupted the script. Closing the browser.")
driver.quit()
def test_locked_accounts(driver):
screenshot_dir = os.path.join("screenshots", "locked_accounts_test")
os.makedirs(screenshot_dir, exist_ok=True)
try:
# Step 1: Navigate directly to Locked Accounts
locked_accounts_url = "https://stag-cms.unioilapps.com/member-management/lock-account"
driver.get(locked_accounts_url)
print(f"🔐 Navigated to Locked Accounts page: {locked_accounts_url}")
# Step 2: Take screenshot of the Locked Accounts page
screenshot_path = os.path.join(screenshot_dir, "locked_accounts_page.png")
driver.save_screenshot(screenshot_path)
print(f"📸 Screenshot saved at: {screenshot_path}")
# Step 11: Search for another card number
search_input = WebDriverWait(driver, 15).until(
EC.presence_of_element_located((By.XPATH, "//input[@type='text' and @placeholder='Search' and contains(@class, 'ant-input')]"))
)
search_input.clear()
search_input.send_keys("1100768101171208")
print("🔍 Entered card number in search bar")
time.sleep(3) # Let results render
# Step 12: Click the View icon
second_view_icon = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//i[contains(@class, 'anticon-right-circle-o')]"))
)
second_view_icon.click()
print("👁️ Clicked View icon for the card")
# Step 13: Wait for 3 seconds
time.sleep(3)
# Step 14: Click the Activate Account button
activate_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[span[text()='Activate Account']]"))
)
activate_button.click()
print("✅ Clicked 'Activate Account' button")
print("✅ Locked Accounts test completed. Keeping browser open for 10 seconds...")
time.sleep(10)
except Exception as e:
# Do not raise error, just print and continue
print(f"⚠️ Test failed while accessing Locked Accounts: {e}")
driver.save_screenshot(os.path.join(screenshot_dir, "error_locked_accounts.png"))
print("📸 Error screenshot saved.")
except KeyboardInterrupt:
print("\n👋 User interrupted the script. Closing the browser.")
driver.quit()
def main():
driver = None
try:
# Step 1: Get driver from login module
try:
driver = login_to_cms()
print("✅ Driver obtained from login_to_cms")
except Exception as e:
print(f"⚠️ Failed to get driver from login_to_cms: {e}")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
print("✅ Initialized new Chrome driver")
# First, run the Card Member test
test_card_member(driver)
# Then, run the Locked Accounts test
test_locked_accounts(driver)
except Exception as e:
print(f"❌ Test failed: {e}")
if driver:
driver.quit()
raise
except KeyboardInterrupt:
print("\n👋 User interrupted the script. Closing the browser.")
if driver:
driver.quit()
if __name__ == "__main__":
main()

164
notifications_test.py Normal file
View File

@ -0,0 +1,164 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import sys
import os
# Debug: Print the current working directory and list files
print(f"Current working directory: {os.getcwd()}")
print(f"Files in directory: {os.listdir(os.getcwd())}")
try:
from login import login_to_cms
print("✅ Successfully imported login_to_cms from login.py")
except ImportError as e:
print(f"❌ Failed to import login_to_cms: {e}")
sys.exit(1)
def test_notifications():
driver = None
try:
driver = login_to_cms()
print("Logged in, proceeding to Notifications test")
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "li.ant-menu-item"))
)
print("Sidebar loaded")
notifications_link = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(@class, 'ant-menu-item') and normalize-space()='Notifications']"))
)
driver.execute_script("arguments[0].scrollIntoView(true);", notifications_link)
notifications_link.click()
print("Clicked Notifications tab")
time.sleep(1)
WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.XPATH, "//h1[contains(text(), 'Notifications')]"))
)
print("Successfully navigated to Notifications page")
time.sleep(1)
# Click Add Notification button
add_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Add Notification']]"))
)
add_button.click()
print("Clicked Add Notification button")
time.sleep(1)
# Fill in Subject
subject_field = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "subject"))
)
subject_field.send_keys("Test")
print("Entered Subject: Test")
time.sleep(1)
# Fill in Content
content_field = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "content"))
)
content_field.send_keys("This is a testing notification")
print("Entered Content: This is a testing notification")
time.sleep(1)
# Click "Yes" radio button
yes_radio = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[@name='isScheduled' and @value='true']/.."))
)
yes_radio.click()
print("Selected 'Yes' for scheduling")
time.sleep(1)
# Click Schedule Date input
schedule_input = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Schedule']"))
)
schedule_input.click()
print("Clicked Schedule Date input")
time.sleep(1)
# Click "Now" button
now_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[contains(@class, 'ant-calendar-today-btn')]"))
)
now_button.click()
print("Selected 'Now' as schedule")
time.sleep(1)
# Click Expiration Date input
expiration_input = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Expiration']"))
)
expiration_input.click()
print("Clicked Expiration Date input")
time.sleep(1)
# Select day 13
day_13 = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@class='ant-calendar-date' and text()='13']"))
)
day_13.click()
print("Selected expiration date: 13")
time.sleep(1)
# Click Ok
ok_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[@class='ant-calendar-ok-btn']"))
)
ok_button.click()
print("Clicked OK to confirm expiration date")
time.sleep(1)
# Click Submit
submit_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Submit']]"))
)
submit_button.click()
print("Clicked Submit button")
time.sleep(3) # Wait a bit for potential error/toast to appear
# Try to detect error or toast message
try:
# Example: Ant Design error/toast uses ant-message or ant-notification
error_element = WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.XPATH, "//*[contains(@class, 'ant-message') or contains(@class, 'ant-notification')]"))
)
print("⚠️ Error/Toast message detected:")
print(error_element.text)
except:
print("✅ No visible error/toast message detected after submission.")
# Take screenshot after submission attempt
driver.save_screenshot("notification_submitted.png")
print("📸 Screenshot saved as notification_submitted.png")
# Wait 10 seconds before closing
print("Waiting 10 seconds before closing browser...")
time.sleep(10)
return driver
except Exception as e:
print(f"Test failed: {e}")
if driver is not None:
driver.save_screenshot("error.png")
print("Screenshot saved as error.png for debugging")
if driver is not None:
driver.quit()
raise
except KeyboardInterrupt:
print("\nUser interrupted the script. Closing the browser.")
if driver is not None:
driver.quit()
if __name__ == "__main__":
test_notifications()

103
promotions_test.py Normal file
View File

@ -0,0 +1,103 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import sys
import os
try:
from login import login_to_cms
print("✅ Successfully imported login_to_cms from login.py")
except ImportError as e:
print(f"❌ Failed to import login_to_cms: {e}")
sys.exit(1)
def test_promotions():
driver = None
try:
driver = login_to_cms()
print("Logged in, proceeding to User Management test")
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "li.ant-menu-item"))
)
print("Sidebar loaded")
# Click Promotions tab
promotions_tab = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//a[span[text()='Promotions']]"))
)
driver.execute_script("arguments[0].scrollIntoView(true);", promotions_tab)
time.sleep(1)
promotions_tab.click()
print("✅ Clicked Promotions tab")
# Search for Title 'Advisory'
search_input = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, "//input[@placeholder='Search']"))
)
search_input.send_keys("Advisory")
print("Typed 'Advisory' in search")
time.sleep(2)
# Click View icon (first occurrence assumed)
view_icon = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//i[contains(@class, 'anticon-right-circle-o')]"))
)
view_icon.click()
print("Clicked View icon")
time.sleep(2)
# Click Update icon (same icon class, assuming second one)
update_button = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//button[span[text()='Update']]"))
)
driver.execute_script("arguments[0].scrollIntoView(true);", update_button)
time.sleep(1)
update_button.click()
print("✅ Clicked Update button")
# Click the Cancel button
cancel_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[span[text()='Cancel']]"))
)
driver.execute_script("arguments[0].scrollIntoView(true);", cancel_button)
time.sleep(1)
cancel_button.click()
print("✅ Clicked Cancel button")
# Wait for and click the Yes button in the confirmation dialog
yes_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'ant-btn-primary') and span[text()='Yes']]"))
)
time.sleep(1)
yes_button.click()
print("✅ Clicked Yes on confirmation dialog")
time.sleep(2)
# Final screenshot inside 'screenshot' folder
screenshot_path = os.path.join("screenshot", "promotions_test_result.png")
driver.save_screenshot(screenshot_path)
print(f"📸 Screenshot saved as {screenshot_path}")
print("🕒 Waiting 10 seconds before closing the browser...")
time.sleep(10)
driver.quit()
except Exception as e:
print(f"❌ Test failed: {e}")
screenshot_path = os.path.join("screenshot", "promotions_test_error.png")
driver.save_screenshot(screenshot_path)
print(f"📸 Error screenshot saved as {screenshot_path}")
raise
finally:
driver.quit()
print("🚪 Browser closed")
if __name__ == "__main__":
test_promotions()

167
reports_test.py Normal file
View File

@ -0,0 +1,167 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import sys
import os
try:
from login import login_to_cms
print("✅ Successfully imported login_to_cms from login.py")
except ImportError as e:
print(f"❌ Failed to import login_to_cms: {e}")
sys.exit(1)
def test_registration_report_export():
driver = None
try:
driver = login_to_cms()
print("✅ Logged in, proceeding to Reports test")
# Wait for sidebar
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "li.ant-menu-item"))
)
print("✅ Sidebar loaded")
time.sleep(1)
# Open 'Reports' dropdown
reports_menu = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//span[text()='Reports']/ancestor::li"))
)
reports_menu.click()
print("✅ Opened 'Reports' dropdown")
time.sleep(1)
# === 1. Registration Report ===
registration_report_link = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[contains(@href, '/reports/registration-report')]"))
)
registration_report_link.click()
print("✅ Clicked 'Registration Report'")
time.sleep(1)
# Start date input
date_input = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Start date']"))
)
date_input.click()
print("✅ Clicked date input")
time.sleep(1)
# Select 13th
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@class='ant-calendar-date' and text()='13']"))
).click()
print("✅ Selected 13th as start")
time.sleep(1)
# Select 30th
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@class='ant-calendar-date' and text()='30']"))
).click()
print("✅ Selected 30th as end")
time.sleep(1)
# Export CSV
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Export CSV']]"))
).click()
print("✅ Exported 'Registration Report' CSV")
time.sleep(2)
# === 2. Top-Up Usage Report ===
top_up_link = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[contains(@href, '/reports/top-up')]"))
)
top_up_link.click()
print("✅ Clicked 'Top-Up Usage Report'")
time.sleep(2)
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Export CSV']]"))
).click()
print("✅ Exported 'Top-Up Usage Report' CSV")
time.sleep(2)
# === 3. Mobile Usage Report ===
mobile_report_link = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[contains(@href, '/reports/mobile-report')]"))
)
mobile_report_link.click()
print("✅ Clicked 'Mobile Usage Report'")
time.sleep(2)
# Click date input
mobile_date_input = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Start date']"))
)
mobile_date_input.click()
print("✅ Clicked date input for Mobile Usage")
time.sleep(1)
# Click previous month (to go to April)
prev_month_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CLASS_NAME, "ant-calendar-prev-month-btn"))
)
prev_month_btn.click()
print("✅ Clicked previous month (to April)")
time.sleep(1)
# Select April 1
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//div[@class='ant-calendar-date' and text()='1']"))
).click()
print("✅ Selected April 1 as start date")
time.sleep(1)
# Select ةشغ 1 (second occurrence of 1)
may_1 = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "(//div[@class='ant-calendar-date' and text()='1'])[2]"))
)
may_1.click()
print("✅ Selected May 1 as end date")
# Export Mobile Report CSV
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Export CSV']]"))
).click()
print("✅ Exported 'Mobile Usage Report' CSV")
time.sleep(1)
# === 4. Station Rating Report ===
station_rating_link = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[contains(@href, '/reports/station-rating')]"))
)
station_rating_link.click()
print("✅ Clicked 'Station Rating Report'")
time.sleep(2)
# Export Station Rating CSV
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Export CSV']]"))
).click()
print("✅ Exported 'Station Rating Report' CSV")
time.sleep(1)
print("⏳ Waiting 10 seconds before closing browser to observe result...")
time.sleep(10)
except Exception as e:
print(f"❌ Test failed: {e}")
finally:
if driver:
driver.quit()
if __name__ == "__main__":
test_registration_report_export()

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

261
station_locator_test.py Normal file
View File

@ -0,0 +1,261 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import sys
try:
from login import login_to_cms
except ImportError as e:
print(f"❌ Failed to import login_to_cms: {e}")
sys.exit(1)
def test_station_locator():
driver = None
try:
driver = login_to_cms()
wait = WebDriverWait(driver, 10)
actions = ActionChains(driver)
print("✅ Logged in")
# Wait for the menu to load
time.sleep(3)
# Find the Station Locator menu item by its visible text
station_locator = wait.until(
EC.presence_of_element_located(
(By.XPATH, '//span[normalize-space()="Station Locator"]/ancestor::div[contains(@class,"ant-menu-submenu-title")]')
)
)
# Hover over the menu item to reveal submenu
actions.move_to_element(station_locator).perform()
time.sleep(1)
# Click Station Locator (fallback to JS if necessary)
try:
station_locator.click()
print("✅ Clicked Station Locator (regular click)")
except:
driver.execute_script("arguments[0].click();", station_locator)
print("✅ Clicked Station Locator (JS fallback)")
# Wait for Branches to appear
branches_link = wait.until(
EC.element_to_be_clickable((By.XPATH, '//a[normalize-space()="Branches"]'))
)
branches_link.click()
print("✅ Clicked on Branches")
# 3. Click Add Branch
add_branch_button = wait.until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Add branch"]]'))
)
add_branch_button.click()
print("✅ Clicked on 'Add branch'")
# 4. Enter branch code
branch_code_input = wait.until(
EC.presence_of_element_located((By.XPATH, '//input[@name="code"]'))
)
branch_code_input.send_keys("Marjorie Branch Code")
print("✅ Entered branch code")
# 5. Enter branch name
branch_name_input = driver.find_element(By.XPATH, '//input[@name="name"]')
branch_name_input.send_keys("Marjorie Branch Name")
print("✅ Entered branch name")
# 6. Enter details
details_input = driver.find_element(By.XPATH, '//input[@name="details"]')
details_input.send_keys("Marjorie Details")
print("✅ Entered branch details")
# 7. Click Save button
save_button = wait.until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Save"]]'))
)
save_button.click()
print("✅ Clicked on 'Save'")
# 8. Handle error modal if branch already exists
try:
error_icon = WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.XPATH, '//i[@aria-label="icon: close" and contains(@class, "ant-notification-close-icon")]'))
)
driver.execute_script("arguments[0].click();", error_icon)
print("✅ Closed the error notification")
except:
print(" No error modal appeared")
# 9. Click Cancel button
cancel_button = wait.until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Cancel"]]'))
)
cancel_button.click()
print("✅ Clicked on 'Cancel'")
# 10. Click Yes on confirmation dialog
confirmation_button = wait.until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Yes"]]'))
)
confirmation_button.click()
print("✅ Clicked on 'Yes' in confirmation")
# Re-open "Station Locator" submenu if collapsed (after navigating to Branches)
station_locator = WebDriverWait(driver, 10).until(
EC.presence_of_element_located(
(By.XPATH, '//span[normalize-space()="Station Locator"]/ancestor::div[contains(@class,"ant-menu-submenu-title")]')
)
)
actions.move_to_element(station_locator).perform()
time.sleep(1)
try:
station_locator.click()
print("🔄 Re-clicked Station Locator (regular click)")
except:
driver.execute_script("arguments[0].click();", station_locator)
print("🔄 Re-clicked Station Locator (JS fallback)")
# Now click "Stations"
stations_link = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//a[@href="/stations" and contains(text(), "Stations")]'))
)
stations_link.click()
print("✅ Clicked on 'Stations'")
# Click "Upload Prices"
upload_prices_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Upload Prices"]]'))
)
upload_prices_btn.click()
print("✅ Clicked 'Upload Prices'")
# Click "Close" on the modal
close_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Close"]]'))
)
close_button.click()
print("✅ Closed the upload modal")
# Click "Next Page"
next_page = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//li[@title="Next Page" and @aria-disabled="false"]'))
)
next_page.click()
print("➡️ Moved to next page")
# Wait a bit for content to update
time.sleep(2)
# Click "Previous Page"
prev_page = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//li[@title="Previous Page" and @aria-disabled="false"]'))
)
prev_page.click()
print("⬅️ Moved back to previous page")
# Wait and click the green plus-circle icon (add station)
plus_icon = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//span[@role="img" and @aria-label="plus-circle"]'))
)
plus_icon.click()
print("✅ Clicked the green plus-circle icon")
# Wait and click Cancel button in the modal/form
cancel_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Cancel"]]'))
)
cancel_button.click()
print("✅ Clicked 'Cancel'")
# Wait and click Yes on confirmation
yes_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Yes"]]'))
)
yes_button.click()
print("✅ Clicked 'Yes' on confirmation")
# Re-open Station Locator dropdown (if collapsed)
station_locator_menu = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//span[normalize-space()="Station Locator"]/ancestor::div[contains(@class,"ant-menu-submenu-title")]'))
)
driver.execute_script("arguments[0].scrollIntoView(true);", station_locator_menu)
station_locator_menu.click()
print("✅ Re-opened Station Locator dropdown")
# Click Fuels
fuels_link = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//a[normalize-space()="Fuels"]'))
)
fuels_link.click()
print("✅ Clicked 'Fuels'")
# Click Add Fuel
add_fuel_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Add fuel"]]'))
)
add_fuel_button.click()
print("✅ Clicked 'Add fuel'")
# Enter fuel name
fuel_name_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//input[@placeholder="Enter" and @name="name"]'))
)
fuel_name_input.send_keys("FUEL MARJORIE")
print("✅ Entered fuel name")
# Click Save
save_button = driver.find_element(By.XPATH, '//button[.//span[text()="Save"]]')
save_button.click()
print("✅ Clicked 'Save'")
# Handle duplicate name error modal (optional)
try:
close_icon = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH, '//i[contains(@class,"ant-notification-close-icon")]'))
)
close_icon.click()
print("⚠️ Fuel name already exists. Closed error notification.")
except:
print("✅ Fuel created successfully or no error appeared.")
# Click Cancel
cancel_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Cancel"]]'))
)
cancel_button.click()
print("✅ Clicked 'Cancel'")
# Confirm Cancel with Yes
yes_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//button[.//span[text()="Yes"]]'))
)
yes_button.click()
print("✅ Confirmed cancel with 'Yes'")
# 11. Wait before closing
print("⏳ Waiting 10 seconds before closing browser...")
time.sleep(10)
except Exception as e:
print(f"❌ Test failed: {e}")
finally:
if driver:
driver.quit()
print("🧹 Browser closed")
if __name__ == "__main__":
test_station_locator()

58
system_parameters_test.py Normal file
View File

@ -0,0 +1,58 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import sys
import os
try:
from login import login_to_cms
print("✅ Successfully imported login_to_cms from login.py")
except ImportError as e:
print(f"❌ Failed to import login_to_cms: {e}")
sys.exit(1)
def test_system_parameters():
driver = None
try:
driver = login_to_cms()
print("✅ Logged in to CMS")
# Wait for sidebar to load
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "li.ant-menu-item, li.ant-menu-submenu"))
)
print("✅ Sidebar loaded")
time.sleep(1)
# Click System Parameters menu item
system_parameters_link = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[@href='/system-parameters']"))
)
system_parameters_link.click()
print("✅ Clicked 'System Parameters'")
time.sleep(2)
# Click Sync Data button
sync_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Sync Data']]"))
)
sync_button.click()
print("✅ Clicked 'Sync Data' button")
time.sleep(2)
except Exception as e:
print(f"❌ Test failed: {e}")
finally:
if driver:
print("⏳ Waiting 10 seconds before closing browser...")
time.sleep(10)
driver.quit()
print("🧹 Browser closed")
if __name__ == "__main__":
test_system_parameters()

169
topup_test.py Normal file
View File

@ -0,0 +1,169 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time
import sys
import os
try:
from login import login_to_cms
print("✅ Successfully imported login_to_cms from login.py")
except ImportError as e:
print(f"❌ Failed to import login_to_cms: {e}")
sys.exit(1)
def test_top_up():
driver = None
try:
driver = login_to_cms()
print("Logged in, proceeding to Top-Up test")
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "li.ant-menu-item"))
)
print("Sidebar loaded")
# Click the "Top-Up" link in the sidebar
topup_link = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[.//span[text()='Top-Up']]"))
)
topup_link.click()
print("✔️ Clicked on 'Top-Up' in sidebar")
time.sleep(2)
# Click View icon for one data
view_icon = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//i[contains(@class, 'anticon-right-circle-o')]"))
)
view_icon.click()
print("✔️ Clicked on View icon of one data")
time.sleep(2)
# Click Update button
update_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Update']]"))
)
update_btn.click()
print("✔️ Clicked Update button")
time.sleep(2)
# Add a value: First clear any existing value, then input 10
value_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "input[placeholder='Value']"))
)
# Clear the input field before entering the new value
value_input.send_keys(Keys.CONTROL + "a") # Select all text in the field
value_input.send_keys(Keys.BACKSPACE) # Delete the selected text
time.sleep(1)
# Ensure the field is empty before entering the new value
assert value_input.get_attribute('value') == "", "The input field was not cleared!"
value_input.send_keys("10") # Enter the new value "10"
print("✔️ Value input set to 10")
time.sleep(1)
# Click Submit button
submit_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Submit']]"))
)
submit_btn.click()
print("✔️ Submit button clicked")
time.sleep(1)
# Click Yes in confirmation
confirm_yes_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'ant-btn-primary') and .//span[text()='Yes']]"))
)
confirm_yes_btn.click()
print("✔️ Confirmed Submit by clicking Yes")
time.sleep(2)
# Click another View icon (for a second data entry)
view_icon = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "(//i[contains(@class, 'anticon-right-circle-o')])[2]"))
)
view_icon.click()
print("✔️ Clicked on View icon of another data")
time.sleep(2)
# Click Update for the second entry
update_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Update']]"))
)
update_btn.click()
print("✔️ Clicked Update button")
time.sleep(2)
# Click Cancel for the second entry
cancel_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Cancel']]"))
)
cancel_btn.click()
print("✔️ Clicked Cancel button")
time.sleep(2)
# Confirm Cancel by clicking Yes
confirm_yes_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'ant-btn-primary') and .//span[text()='Yes']]"))
)
confirm_yes_btn.click()
print("✔️ Confirmed Cancel by clicking Yes")
time.sleep(2)
# ------------------- Add New Top-Up Data -------------------
# Click the Add button
add_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Add']]"))
)
add_btn.click()
print("✔️ Clicked Add button")
time.sleep(2)
# Input Name ("Marjorie")
name_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//input[@name='name']"))
)
name_input.send_keys("Marjorie")
print("✔️ Entered Name: Marjorie")
time.sleep(1)
# Input Value ("500")
value_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//input[@placeholder='Value']"))
)
value_input.send_keys("500")
print("✔️ Entered Value: 500")
time.sleep(1)
# Click Submit to add the data
submit_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Submit']]"))
)
submit_btn.click()
print("✔️ Clicked Submit button to add data")
time.sleep(1)
# Click Yes in confirmation
confirm_yes_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'ant-btn-primary') and .//span[text()='Yes']]"))
)
confirm_yes_btn.click()
print("✔️ Confirmed Submit by clicking Yes")
time.sleep(2)
finally:
# Close the browser after a brief wait
if driver:
print("Test completed. Closing the browser in 10 seconds...")
time.sleep(10)
driver.quit()
if __name__ == "__main__":
test_top_up()

270
user_management_test.py Normal file
View File

@ -0,0 +1,270 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
import sys
import os
try:
from login import login_to_cms
print("Successfully imported login_to_cms from login.py")
except ImportError as e:
print(f"Failed to import login.py: {e}")
sys.exit(1)
def test_user_management():
driver = None
try:
driver = login_to_cms()
print("Logged in, proceeding to User Management test")
WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "li.ant-menu-item"))
)
user_management_link = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "li.ant-menu-item a[href='/user-management']"))
)
driver.execute_script("arguments[0].scrollIntoView(true);", user_management_link)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(user_management_link))
user_management_link.click()
print("Clicked User Management link")
user_management_title = WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.XPATH, "//h1[contains(text(), 'User Management')]"))
).text
assert "User Management" in user_management_title
time.sleep(1)
add_user_button = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'ant-btn') and .//span[contains(text(), 'Add User')]]"))
)
add_user_button.click()
print("Clicked Add User button")
time.sleep(1)
WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.XPATH, "//h1[contains(text(), 'Add User')]"))
)
username_field = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "username"))
)
username_field.clear()
driver.execute_script("arguments[0].focus();", username_field)
username_field.send_keys("m.marjorie")
driver.execute_script("arguments[0].dispatchEvent(new Event('input'));", username_field)
driver.execute_script("arguments[0].dispatchEvent(new Event('blur'));", username_field)
time.sleep(1)
first_name_field = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "firstname"))
)
first_name_field.clear()
driver.execute_script("arguments[0].focus();", first_name_field)
first_name_field.send_keys("Marjorie")
driver.execute_script("arguments[0].dispatchEvent(new Event('input'));", first_name_field)
driver.execute_script("arguments[0].dispatchEvent(new Event('blur'));", first_name_field)
time.sleep(1)
last_name_field = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "lastname"))
)
last_name_field.clear()
driver.execute_script("arguments[0].focus();", last_name_field)
last_name_field.send_keys("Magluyan")
driver.execute_script("arguments[0].dispatchEvent(new Event('input'));", last_name_field)
driver.execute_script("arguments[0].dispatchEvent(new Event('blur'));", last_name_field)
time.sleep(1)
email_field = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "email"))
)
email_field.clear()
driver.execute_script("arguments[0].focus();", email_field)
email_field.send_keys("example@gmail.com")
driver.execute_script("arguments[0].dispatchEvent(new Event('input'));", email_field)
driver.execute_script("arguments[0].dispatchEvent(new Event('blur'));", email_field)
time.sleep(1)
WebDriverWait(driver, 15).until(EC.invisibility_of_element_located((By.CLASS_NAME, "ant-spin")))
inactive_radio_label = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//label[contains(@class, 'ant-radio-wrapper') and normalize-space(.)='Inactive']"))
)
driver.execute_script("arguments[0].scrollIntoView(true);", inactive_radio_label)
inactive_radio_label.click()
time.sleep(1)
marketing_personnel_label = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//label[contains(@class, 'ant-radio-wrapper') and normalize-space(.)='Marketing Personnel']"))
)
driver.execute_script("arguments[0].scrollIntoView(true);", marketing_personnel_label)
marketing_personnel_label.click()
time.sleep(1)
generate_button = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//button[normalize-space()='Generate']"))
)
driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", generate_button)
ActionChains(driver).move_to_element(generate_button).click().perform()
time.sleep(1)
password_field = WebDriverWait(driver, 15).until(
EC.presence_of_element_located((By.XPATH, "//button[normalize-space()='Generate']/following-sibling::input[1] | //input[contains(@class, 'ant-input')]"))
)
password_value = password_field.get_attribute("value")
print("Default password generated:", password_value)
submit_button = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Submit'] and contains(@style, 'background: rgb(231, 70, 16)')]"))
)
submit_button.click()
print("Submitted Add User form")
time.sleep(2)
# ✅ Check if alert modal appears
try:
WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.CLASS_NAME, "ant-notification-notice"))
)
print("⚠️ Notification alert appeared")
# 1. Click the X icon to close notification
close_icon = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "i.ant-notification-close-icon"))
)
close_icon.click()
print("Closed alert notification")
# 2. Click Cancel
cancel_button = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH, "//button[span[text()='Cancel']]"))
)
cancel_button.click()
print("Clicked Cancel on modal")
# 3. Confirm Cancel by clicking Yes
yes_button = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'ant-btn-primary') and .//span[text()='Yes']]"))
)
yes_button.click()
print("Confirmed Cancel by clicking Yes")
except Exception:
print("No alert notification appeared; continuing test flow...")
# Step 1: Search for "graxia"
search_input = WebDriverWait(driver, 15).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "input[placeholder='Search']"))
)
search_input.clear()
search_input.send_keys("graxia")
print("Searched for username: graxia")
# Wait for the result to show up
time.sleep(3) # Adjust if necessary depending on API delay
# Step 2: Click the View icon next to the search result
try:
view_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//i[contains(@class, 'anticon-right-circle-o')]"))
)
driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", view_button)
view_button.click()
print("Clicked View icon for graxia")
except Exception as e:
print(f"❌ Failed to click View icon: {e}")
driver.save_screenshot("view_click_failed.png")
raise
# Wait and click the Update button
time.sleep(3)
update_button = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//button[.//span[text()='Update']]"))
)
update_button.click()
print("Clicked Update button")
# Step 3: Change First Name after clicking View
# Wait for the First Name input field to appear
first_name_field = WebDriverWait(driver, 15).until(
EC.visibility_of_element_located((By.NAME, "firstname"))
)
# Use JavaScript to clear the field properly
driver.execute_script("arguments[0].value = '';", first_name_field) # Clear the field using JS
# Enter the new First Name
first_name_field.send_keys("Graxi") # Enter the new name
print("Updated First Name to: Graxi")
# After updating the first name, click the Submit button
submit_button = WebDriverWait(driver, 15).until(
EC.element_to_be_clickable((By.XPATH, "//button[normalize-space()='Submit']"))
)
submit_button.click()
print("Clicked Submit button to save changes")
# Step 1: Search for the graxia username again
search_input = WebDriverWait(driver, 15).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "input.ant-input[placeholder='Search']"))
)
search_input.clear() # Clear any existing value
search_input.send_keys("graxia") # Enter the username "graxia"
print("Searched for username: graxia")
# Step 2: Wait for and click the View button (same as before)
view_button = WebDriverWait(driver, 15).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "i.anticon.anticon-right-circle-o"))
)
view_button.click()
print("Clicked View button for graxia")
# Step 3: Wait for the Active button to be clickable
active_button = WebDriverWait(driver, 15).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "a.ant-dropdown-link.ant-dropdown-trigger"))
)
active_button.click() # Click the Active dropdown
print("Clicked Active dropdown")
# Step 4: Wait for and select the Inactive option
inactive_option = WebDriverWait(driver, 15).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(@class, 'ant-dropdown-menu-item') and normalize-space(text())='Inactive']"))
)
inactive_option.click() # Click the Inactive option
print("Selected Inactive from the dropdown")
time.sleep(1)
print("Waiting for 10 seconds before closing the browser...")
time.sleep(10) # Wait for 10 seconds
# Close the browser
driver.quit()
print("Browser closed successfully.")
return driver
except Exception as e:
print(f"Test failed: {e}")
if driver is not None:
driver.save_screenshot("error.png")
print("Screenshot saved as error.png for debugging")
if driver is not None:
driver.quit()
raise
except KeyboardInterrupt:
print("\nUser interrupted the script. Closing the browser.")
if driver is not None:
driver.quit()
if __name__ == "__main__":
test_user_management()