2023-01-17 17:16:49 -06:00
|
|
|
#!/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
|
2023-01-21 14:48:07 -06:00
|
|
|
from robot.api.logger import info, debug, trace, console, error
|
|
|
|
|
2023-01-17 17:16:49 -06:00
|
|
|
|
|
|
|
def check_subdomains(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:
|
2023-01-21 14:48:07 -06:00
|
|
|
sites = driver.find_element(
|
|
|
|
By.TAG_NAME, "nav").find_elements(By.XPATH, "./div/div")
|
2023-01-17 17:16:49 -06:00
|
|
|
except:
|
2023-01-21 14:48:07 -06:00
|
|
|
error("Couldn't find the element.")
|
2023-01-17 17:16:49 -06:00
|
|
|
driver.close()
|
|
|
|
driver.quit()
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Iterate through subdomains
|
|
|
|
for e in sites:
|
|
|
|
try:
|
|
|
|
link_element = e.find_element(By.XPATH, "./a")
|
|
|
|
link_element.click()
|
|
|
|
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:
|
2023-01-21 14:48:07 -06:00
|
|
|
error("Couldn't find the element somewhere...")
|
2023-01-17 17:16:49 -06:00
|
|
|
driver.close()
|
|
|
|
driver.quit()
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2023-01-21 14:48:07 -06:00
|
|
|
|
|
|
|
def setup_webdriver(remote_url):
|
2023-01-17 17:16:49 -06:00
|
|
|
# Set up webdriver and necessary variables for later
|
|
|
|
chrome_options = webdriver.ChromeOptions()
|
2023-01-21 14:48:07 -06:00
|
|
|
info('Attempting to establish connection to remote webdriver...')
|
|
|
|
driver = webdriver.Remote(
|
|
|
|
command_executor=remote_url, options=chrome_options)
|
|
|
|
info('Connection established.')
|
|
|
|
return driver
|
2023-01-17 17:16:49 -06:00
|
|
|
|
|
|
|
|
2023-01-21 14:48:07 -06:00
|
|
|
def teardown_webdriver(driver):
|
2023-01-17 17:16:49 -06:00
|
|
|
# Close browser and lean up
|
|
|
|
driver.close()
|
|
|
|
driver.quit()
|
|
|
|
|
2023-01-21 14:48:07 -06:00
|
|
|
|
|
|
|
def execute_tests(driver, site_url):
|
|
|
|
# Load requested site
|
|
|
|
info('Attempting to get page...')
|
|
|
|
driver.get(site_url)
|
|
|
|
info('Page loaded.')
|
|
|
|
|
|
|
|
# Check all the subdomain buttons work
|
|
|
|
info('Attempting to click through subdomain buttons...')
|
|
|
|
if (check_subdomains(driver)):
|
|
|
|
info('Test succeeded.')
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
info('Test failed.')
|
|
|
|
return False
|
|
|
|
|
|
|
|
# execute_tests()
|