From 169506f28c669b7f7970da31b0acee0bedd6920e Mon Sep 17 00:00:00 2001 From: Pat O'Connor Date: Sun, 2 Mar 2025 16:35:20 +0000 Subject: [PATCH] task(GUIDEFRAME-38): Reconfigure test into workflow Signed-off-by: Pat O'Connor --- .DS_Store | Bin 12292 -> 8196 bytes .github/workflows/selenium_test.yaml | 34 +++++ guideframe_selenium.py | 16 +- selenium_demos/selenium_automation_tests.py | 155 +++++++++++--------- 4 files changed, 128 insertions(+), 77 deletions(-) create mode 100644 .github/workflows/selenium_test.yaml diff --git a/.DS_Store b/.DS_Store index 31cc7d64f1eab7ea679a92f1026e75ad34ba15af..a11574ac4227cc30722be7b63ce31bc058595f1d 100644 GIT binary patch delta 171 zcmZokXmOBWU|?W$DortDU;r^WfEYvza8E20o2Vx_*+7Ry63Ax|17b#?I0Hi_LkUAX z5b7}$Y!+nv#x_}jaqVVy4i*kZvB^9N`I8?iL`|+%lGx0sRL4A-U#MvEO(C1j`qEsC zo5dKPFbXn*OaofN4J2Ga76A?U4pgXP$O<%{p<%M4j`HMqo~e_63dz8@=V# zC^w`c@e%qF!j(_aBOil17vT41cks;fjCaMK9@-sgcgE}ay*KllH*e<6E)fL>C;cs= z8$?vW#d-Zj++!xFR-wV{gMCt8mFR0+TC(F4@)P{*zn{Eq)N|E@(;qb}Mu zLER!13=|9$3=|9$3_PC<@Y;)15$k>Ow73@x6bwAq46uJ_;NrZM<`+q>TnBEvh3Efy z3$GH&ygBD*jWlni`9+fBAEY3GB2S<}8e#+q9M2nRy;hoEBzXd-Kxu}YRCACx3j_kw|ffq4e@@u=>Jy|>+wcknvq`*kCx_ThIt_#boPcRhH-^ttrE?Zz+N z&xzl2( zsnan|P`<&5%}|v__!Z&YX9Dz;zNM+aW5j|rgR$4t2~4O^Lr59nb1%zFX+w@yWypJ&Nl~&-iE`FZ8fom$EQIkK)aT(QARw zqj<~0NIlG(iJ8r8k5w=59vb1$5tzPkro&^=JTe&wp+ouG-;8mY=~!UR!D58ap?sPf zvA~i&Iy6G+;MLKsV}TWCAcPL)YUv9nR|_mS10i%US02Oy>&-w&9qg0c{m{D|F+-F` zUW^br6jx6SuC8MJ=eJrh_Bs=~iBhsBxk*PT_3)0$`G$)5uyz>hUO8W3&lAzM_gxpf ziP-0uEt>6;9J>-Vuhxv-tXZuvvCdtC)q`suY=@fIB@L)gd!*;LV3pfp$*Ryp?DBX& z6+3qa)%d+R=3<14-`#hd^HIiH2?{;~Gr#)}-oKCFIYXcw z(Tc-YaCF#LQK6&0TBS{2QG#sr$Bt;&uUk>_`gR6ewFTngT!MVq0L=HwS)N{T0Zld z3j^)?8;AvCz&lvWU%%{?wP0k_NNyUv@U@7)$S}_X9HY!*VXcC`7V%omW8{v6Vez@7 zWUfvYJ1fx0Ck3IhQ#mforOAS*-8-F((=S_o>5aqTWZG>08Z4E{%P*`{Rw}j1=j{ja zX?xn8o=gt9$Di`AkK;J(>2kOC$#8JmsbBpdj;7sVG&oj(VSj)spWPis{rL1CK8gAh zg>5H)RH~I~r~b;>+4lb4Mq}sJ*7-)`Y=67C(b(PDJ3p^h*57#R-8-GH!%-AJLJyFF zAj#=Un(GYSfkdw!wvVGQj(FW?R0-S+sb^cP+9R3Fq_v(AM$+C0CVc0mo_!?G#PW4x z4*9>8(x)t9@5Nt1Stove37$6aJkBY>6A|+4E&q|L7oHuY;vt^|9sfxlF!yt|!56E+ z&T~r8v72lIk43&-=*Ub+P-9_8uvQuK{7gq(0?*b^y2OlJ#)WjFhTCnt2Jn3Urz#b< zf`Nj8XOn@TeAqrbK;QJ@F1yL^+8emO#HADJs_M8|9|7REdKHhnY1D0T8P6_~93`Zu f{t-aB@p)=HqGJ8GzSqvV?iK5Q@?P$LUH|_AAqrIn diff --git a/.github/workflows/selenium_test.yaml b/.github/workflows/selenium_test.yaml new file mode 100644 index 0000000..96eddb8 --- /dev/null +++ b/.github/workflows/selenium_test.yaml @@ -0,0 +1,34 @@ +name: GuideFrame Tests +# Trigger the workflow on push +on: [push] +# All jobs in the workflow +jobs: + selenium-function-test: + runs-on: ubuntu-latest + # steps to run + steps: + # Checkout the code + - name: Checkout code + uses: actions/checkout@v4 + # Set up environment + - name: Set up environment + run: | + sudo apt-get update + sudo apt-get install -y \ + ffmpeg \ + xvfb \ + chromium-driver \ + chromium-browser + pip install selenium \ + ffmpeg-python \ + mutagen \ + gTTS + # Run the main automation script + - name: Run Automation Test with Virtual Display + run: | + # Start virtual display + export DISPLAY=:99 + nohup Xvfb :99 -screen 0 1920x1080x24 & + + # Run the Selenium script + python3 -m selenium_demos.selenium_automation_tests github diff --git a/guideframe_selenium.py b/guideframe_selenium.py index dd81d29..eec2ac4 100644 --- a/guideframe_selenium.py +++ b/guideframe_selenium.py @@ -1,4 +1,5 @@ from selenium import webdriver # Importing the webdriver module from selenium and other modules +from selenium.webdriver.support.ui import Select from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options @@ -61,7 +62,7 @@ def find_element(driver, id): return element except Exception as e: print(f"Error finding element with ID '{id}': {e}") - return None + raise # Function to scroll to an element using a href @@ -75,6 +76,7 @@ def scroll_to_element(driver, href): except Exception as e: print(f"Error in scroll_to_element for href '{href}': {e}") + raise # Function to hover over a href element and click it (ideal for link buttons) @@ -92,6 +94,7 @@ def hover_and_click(driver, href): element.click() except Exception as e: print(f"Error in hover_and_click for href '{href}': {e}") + raise # Function to hover over an href element (ideal for link buttons) @@ -106,6 +109,7 @@ def hover_over_element(driver, href): except Exception as e: print(f"Error in hover_over_element for href '{href}': {e}") + raise # Function to click an element using a CSS selector @@ -117,6 +121,7 @@ def click_element(driver, css_selector): element.click() except Exception as e: print(f"Error clicking element with selector '{css_selector}': {e}") + raise # Function to type into an input field using an ID @@ -128,6 +133,7 @@ def type_into_field(driver, element_id, text): input_field.send_keys(text) except Exception as e: print(f"Error typing into field with ID '{element_id}': {e}") + raise # Function to open a link in a new tab @@ -140,6 +146,7 @@ def open_link_in_new_tab(driver, href): driver.switch_to.window(driver.window_handles[-1]) except Exception as e: print(f"Error opening link '{href}' in a new tab: {e}") + raise # Function to switch between browser tabs using index as an arg @@ -151,6 +158,7 @@ def switch_to_tab(driver, tab_index): print(f"Invalid tab index: {tab_index}") except Exception as e: print(f"Error switching to tab {tab_index}: {e}") + raise # Function to take a screenshot (mainly for testing but could be useful) @@ -159,9 +167,7 @@ def take_screenshot(driver, file_name="screenshot.png"): driver.save_screenshot(file_name) except Exception as e: print(f"Error taking screenshot: {e}") - -from selenium.webdriver.support.ui import Select - + raise # Function to select a dropdown option by visible text def select_dropdown_option(driver, dropdown_id, visible_text): @@ -173,6 +179,7 @@ def select_dropdown_option(driver, dropdown_id, visible_text): print(f"Selected dropdown option: {visible_text}") except Exception as e: print(f"Error selecting dropdown option '{visible_text}': {e}") + raise # Function to click a button by the text of a span element (useful for cookie popups etc) @@ -186,3 +193,4 @@ def click_button_by_span_text(driver, span_text): print(f"Clicked button with span text: '{span_text}'") except Exception as e: print(f"Error clicking button with span text '{span_text}': {e}") + raise diff --git a/selenium_demos/selenium_automation_tests.py b/selenium_demos/selenium_automation_tests.py index 6a88dcd..8e5eec6 100644 --- a/selenium_demos/selenium_automation_tests.py +++ b/selenium_demos/selenium_automation_tests.py @@ -1,81 +1,90 @@ from guideframe_selenium import * -import time from guideframe_utils import get_env_settings # Importing the guide_step and get_env_settings functions from guideframe_utils.py +import time # Setup the driver and perform automation tests def selenium_automation_tests(): - env_settings = get_env_settings() # Getting the environment settings - driver_location = env_settings["driver_location"] # Getting the driver location from the settings - driver = driver_setup(driver_location) # Initializing driver - - set_window_size(driver) - open_url(driver, "https://magento.softwaretestingboard.com/") - - # Clicking the agree button for the privacy policy - click_button_by_span_text(driver, "AGREE") - - # Click on the 'Sign In' link - click_element(driver, ".authorization-link > a") - time.sleep(2) - - # Enter email and password - type_into_field(driver, "email", "test-user@email.com") - type_into_field(driver, "pass", "testuser-1") - - # Click the sign-in button - click_element(driver, "button[name='send']") - time.sleep(3) - - # First, hover over the "Gear" menu - hover_over_element(driver, "https://magento.softwaretestingboard.com/gear.html") - time.sleep(2) - - # Then, click on "Fitness Equipment" - click_element(driver, "a[href='https://magento.softwaretestingboard.com/gear/fitness-equipment.html']") - time.sleep(2) - - # Hover over the yoga straps product - hover_over_element(driver, "https://magento.softwaretestingboard.com/set-of-sprite-yoga-straps.html") - time.sleep(2) - - # Return to the straps product and click on it - hover_and_click(driver, "https://magento.softwaretestingboard.com/harmony-lumaflex-trade-strength-band-kit.html") - time.sleep(2) - - # Hover over the reviews link - hover_over_element(driver, "https://magento.softwaretestingboard.com/harmony-lumaflex-trade-strength-band-kit.html#reviews") - time.sleep(2) - - # Open the reviews link in a new tab - open_link_in_new_tab(driver, "https://magento.softwaretestingboard.com/harmony-lumaflex-trade-strength-band-kit.html#reviews") - time.sleep(2) - - # Fill review fields - type_into_field(driver, "nickname_field", "Test User") - type_into_field(driver, "summary_field", "Great product!") - type_into_field(driver, "review_field", "I love this product!") - time.sleep(2) - - # Submit the review - click_button_by_span_text(driver, "Submit Review") - time.sleep(2) - - # Return to the first tab - switch_to_tab(driver, 0) - time.sleep(2) - - # Click the user dropdown - click_button_by_span_text(driver, "Change") - time.sleep(2) - - # Click the "Sign Out" button - click_element(driver, "a[href='https://magento.softwaretestingboard.com/customer/account/logout/']") - time.sleep(2) - - # Close the browser - driver.quit() - - print("Automation test complete") + try: + # Getting the environment settings + env_settings = get_env_settings() + driver_location = env_settings["driver_location"] # Getting the driver location from the settings + driver = driver_setup(driver_location) # Initializing driver + + # Set window size and navigate to URL + set_window_size(driver) + open_url(driver, "https://magento.softwaretestingboard.com/") + + # Clicking the agree button for the privacy policy + click_button_by_span_text(driver, "AGREE") + + # Click on the 'Sign In' link + click_element(driver, ".authorization-link > a") + time.sleep(2) + + # Enter email and password + type_into_field(driver, "email", "test-user@email.com") + type_into_field(driver, "pass", "testuser-1") + + # Click the sign-in button + click_element(driver, "button[name='send']") + time.sleep(3) + + # First, hover over the "Gear" menu + hover_over_element(driver, "https://magento.softwaretestingboard.com/gear.html") + time.sleep(2) + + # Then, click on "Fitness Equipment" + click_element(driver, "a[href='https://magento.softwaretestingboard.com/gear/fitness-equipment.html']") + time.sleep(2) + + # Hover over the yoga straps product + hover_over_element(driver, "https://magento.softwaretestingboard.com/set-of-sprite-yoga-straps.html") + time.sleep(2) + + # Return to the straps product and click on it + hover_and_click(driver, "https://magento.softwaretestingboard.com/harmony-lumaflex-trade-strength-band-kit.html") + time.sleep(2) + + # Hover over the reviews link + hover_over_element(driver, "https://magento.softwaretestingboard.com/harmony-lumaflex-trade-strength-band-kit.html#reviews") + time.sleep(2) + + # Open the reviews link in a new tab + open_link_in_new_tab(driver, "https://magento.softwaretestingboard.com/harmony-lumaflex-trade-strength-band-kit.html#reviews") + time.sleep(2) + + # Fill review fields + type_into_field(driver, "nickname_field", "Test User") + type_into_field(driver, "summary_field", "Great product!") + type_into_field(driver, "review_field", "I love this product!") + time.sleep(2) + + # Submit the review + click_button_by_span_text(driver, "Submit Review") + time.sleep(2) + + # Return to the first tab + switch_to_tab(driver, 0) + time.sleep(2) + + # Click the user dropdown + click_button_by_span_text(driver, "Change") + time.sleep(2) + + # Click the "Sign Out" button + click_element(driver, "a[href='https://magento.softwaretestingboard.com/customer/account/logout/']") + time.sleep(2) + + # Print the success message + print("Test Passed ✅") + + except Exception as e: + # print the failure message + print(f"Test Failed ❌: {str(e)}") + + finally: + # Close the browser + driver.quit() # Run the automation test if __name__ == "__main__":