commit 7d287aa7b7da0a31a218a8abd594b041b85a52f1 Author: Marjorie Date: Mon May 19 20:13:09 2025 +0800 Initial commit diff --git a/Negative_Testing/invalid_password.py b/Negative_Testing/invalid_password.py new file mode 100644 index 0000000..968c782 --- /dev/null +++ b/Negative_Testing/invalid_password.py @@ -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() diff --git a/Negative_Testing/screenshots/password_incorrect.png b/Negative_Testing/screenshots/password_incorrect.png new file mode 100644 index 0000000..a41ca46 Binary files /dev/null and b/Negative_Testing/screenshots/password_incorrect.png differ diff --git a/Negative_Testing/screenshots/wrong_username.png b/Negative_Testing/screenshots/wrong_username.png new file mode 100644 index 0000000..e7960b4 Binary files /dev/null and b/Negative_Testing/screenshots/wrong_username.png differ diff --git a/Negative_Testing/wrong_username.py b/Negative_Testing/wrong_username.py new file mode 100644 index 0000000..047fb34 --- /dev/null +++ b/Negative_Testing/wrong_username.py @@ -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() diff --git a/__pycache__/login.cpython-311.pyc b/__pycache__/login.cpython-311.pyc new file mode 100644 index 0000000..8d72644 Binary files /dev/null and b/__pycache__/login.cpython-311.pyc differ diff --git a/__pycache__/member_management_test.cpython-311.pyc b/__pycache__/member_management_test.cpython-311.pyc new file mode 100644 index 0000000..f087707 Binary files /dev/null and b/__pycache__/member_management_test.cpython-311.pyc differ diff --git a/__pycache__/notifications_test.cpython-311.pyc b/__pycache__/notifications_test.cpython-311.pyc new file mode 100644 index 0000000..3d29b4b Binary files /dev/null and b/__pycache__/notifications_test.cpython-311.pyc differ diff --git a/__pycache__/user_management_test.cpython-311.pyc b/__pycache__/user_management_test.cpython-311.pyc new file mode 100644 index 0000000..c856e6d Binary files /dev/null and b/__pycache__/user_management_test.cpython-311.pyc differ diff --git a/about_us_test.py b/about_us_test.py new file mode 100644 index 0000000..7b4eb81 --- /dev/null +++ b/about_us_test.py @@ -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() diff --git a/home_page_mobile_test.py b/home_page_mobile_test.py new file mode 100644 index 0000000..8a17642 --- /dev/null +++ b/home_page_mobile_test.py @@ -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