Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
34 changes: 34 additions & 0 deletions .github/workflows/selenium_test.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 12 additions & 4 deletions guideframe_selenium.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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
155 changes: 82 additions & 73 deletions selenium_demos/selenium_automation_tests.py
Original file line number Diff line number Diff line change
@@ -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__":
Expand Down