Finish up root domain tests, add seperate file for footer tests to allow import later.

main
Ada Werefox 6 days ago
parent 401ee636f5
commit 901d37a7a8

@ -0,0 +1,44 @@
#!/usr/bin/python
# Necessary imports
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from robot.api.logger import info, debug, trace, console, error
def check_footer_links(driver):
# setup wait and grab original tab/window
wait = WebDriverWait(driver, 10)
main_tab = driver.current_window_handle
# Try to grab button elements of maintained subdomains
try:
footer_element = driver.find_element(By.TAG_NAME, "footer")
sites = footer_element.find_elements(
By.XPATH, ".//a")
except:
error("Couldn't find the element.")
driver.close()
driver.quit()
return False
# Iterate through subdomains
for e in sites:
try:
e.click()
info(e.text)
wait.until(expected_conditions.number_of_windows_to_be(2))
for window_handle in driver.window_handles:
if window_handle != main_tab:
driver.switch_to.window(window_handle)
driver.close()
driver.switch_to.window(main_tab)
except:
error("Couldn't find the element somewhere...")
driver.close()
driver.quit()
return False
return True

@ -6,6 +6,7 @@ from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from robot.api.logger import info, debug, trace, console, error
from footer_test import check_footer_links
def check_subdomains(driver):
@ -15,8 +16,11 @@ def check_subdomains(driver):
# Try to grab button elements of maintained subdomains
try:
sites = driver.find_element(
By.TAG_NAME, "nav").find_elements(By.XPATH, "./div/div")
site_lists = driver.find_elements(
By.TAG_NAME, "nav")
sites = []
for l in site_lists:
sites += l.find_elements(By.XPATH, ".//a")
except:
error("Couldn't find the element.")
driver.close()
@ -26,8 +30,9 @@ def check_subdomains(driver):
# Iterate through subdomains
for e in sites:
try:
link_element = e.find_element(By.XPATH, "./a")
link_element.click()
# link_element = e.find_element(By.XPATH, "./a")
e.click()
info(e.text)
wait.until(expected_conditions.number_of_windows_to_be(2))
for window_handle in driver.window_handles:
if window_handle != main_tab:
@ -65,13 +70,16 @@ def execute_tests(driver, site_url):
driver.get(site_url)
info('Page loaded.')
# Check all the subdomain buttons work
# Check all the buttons work
info('Attempting to click through subdomain buttons...')
if (check_subdomains(driver)):
info('Test succeeded.')
return True
else:
# Check the subdomain buttons
if (not check_subdomains(driver)):
info('Test failed.')
return False
# execute_tests()
# Check the footer buttons
elif (not check_footer_links(driver)):
info('Test failed.')
return False
else:
info('Test succeeded.')
return True

Loading…
Cancel
Save