Slightly modified test runner script to specify test suite for debugging, implemented tests for info.werefox.cafe root page.

This commit is contained in:
Ada Werefox 2023-01-27 21:53:20 +00:00
parent e2e4e9b175
commit fd2a56fac4
6 changed files with 138 additions and 39 deletions

View File

@ -3,6 +3,7 @@
set -xe
MODE=$1
TEST=$2
if [ "$MODE" == "--debug-server" ] || [ "$MODE" == "-s" ]; then
docker run --rm --name selenium-debug-server -p "4444:4444" -p "7900:7900" -e SE_OPTS="--allow-cors true" --shm-size="2g" selenium/standalone-chrome:108.0
@ -12,7 +13,7 @@ elif [ "$MODE" == "--debug-node" ] || [ "$MODE" == "-n" ]; then
-v $(pwd)/tests/test_suite:/tests \
-v $(pwd)/tests/output:/output \
-v $(pwd)/src/info/data:/data \
selenium-node:latest robot -d /output /tests/
selenium-node:latest robot -d /output /tests/$TEST
else
cd tests/

View File

@ -0,0 +1,38 @@
#!/usr/bin/python
# Necessary imports
from robot.api.logger import info
from shared_methods import load_data, check_buttons, standardize_url
import footer_test
def execute_tests(driver, site_url):
filepaths = ['/data/pages.yml', '/data/identities.yml']
data = load_data(filepaths)
for d in data:
temp_url = standardize_url(data[d]['url'])
if ('info.werefox.cafe' not in temp_url):
data[d]['url'] = f'info.werefox.cafe{temp_url}'
else:
data[d]['url'] = temp_url
# Load requested site
info('Attempting to get page...')
driver.get(site_url)
info('Page loaded.')
info('Attempting to click through subdomain buttons...')
# Check all the buttons work
if (not check_buttons(driver, data)):
info('Test failed.')
return False
# A little bit of setup, grabbing the button elements
data = footer_test.load_data()
# Check the footer buttons
if (not check_buttons(driver, data)):
info('Test failed.')
return False
info('Test succeeded.')
return True

View File

@ -0,0 +1,14 @@
*** Settings ***
Documentation Import Python functions
Library info_root_domain_test.py
Library shared_methods.py
*** Keywords ***
Info Werefox Cafe Test Cases
[Arguments] ${site_url}
${result}= Execute Tests ${driver} ${site_url}
Should Be True ${result}

View File

@ -0,0 +1,19 @@
*** Settings ***
Documentation Validate functionality of info.werefox.cafe's root page.
Resource info_werefox_cafe.resource
Library webdriver_methods.py
Variables shared_vars.py ${remote_url}
Default Tags positive
*** Variables ***
${remote_url} http://192.168.0.202:4444
${site_url} https://info.werefox.cafe
*** Test Cases ***
Test Werefox Cafe [Documentation] Run Info Werefox Cafe Test Cases.
Info Werefox Cafe Test Cases ${site_url}
[Teardown] Teardown Webdriver ${driver}

View File

@ -1,29 +1,11 @@
#!/usr/bin/python
# Necessary imports
from selenium.webdriver.common.by import By
from robot.api.logger import info, error
from robot.api.logger import info
from shared_methods import load_data, check_buttons
import footer_test
def grab_button_elements(driver):
# Try to grab button elements of maintained subdomains
try:
site_lists = driver.find_elements(
By.TAG_NAME, "nav")
info(site_lists)
sites = []
for l in site_lists:
sites += l.find_elements(By.XPATH, ".//a")
except:
error("Couldn't find the element.")
return []
return sites
def execute_tests(driver, site_url):
filepaths = ['/data/homepage/subdomains.yml', '/data/homepage/other.yml']
data = load_data(filepaths)
@ -33,20 +15,16 @@ def execute_tests(driver, site_url):
driver.get(site_url)
info('Page loaded.')
# A little bit of setup, grabbing the button elements
button_elements = grab_button_elements(driver)
info('Attempting to click through subdomain buttons...')
# Check all the buttons work
if (not check_buttons(driver, data, button_elements)):
if (not check_buttons(driver, data)):
info('Test failed.')
return False
# A little bit of setup, grabbing the button elements
data = footer_test.load_data()
button_elements = footer_test.grab_button_elements(driver)
# Check the footer buttons
if (not check_buttons(driver, data, button_elements)):
if (not check_buttons(driver, data)):
info('Test failed.')
return False

View File

@ -3,8 +3,10 @@
# Necessary imports
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
from robot.api.logger import info, error
from yaml import load, Loader
import time
def standardize_url(url):
@ -36,38 +38,85 @@ def load_data(filepaths):
return data
def check_buttons(driver, data, button_elements):
def grab_button_elements(driver):
sites = []
# Try to grab button elements of maintained subdomains
try:
site_lists = driver.find_elements(
By.TAG_NAME, "nav")
for l in site_lists:
sites += l.find_elements(By.XPATH, ".//a")
site_lists = driver.find_elements(
By.TAG_NAME, "footer")
for l in site_lists:
sites += l.find_elements(By.XPATH, ".//a")
except:
error("Couldn't find the element.")
return []
return sites
def check_buttons(driver, data):
# Iterate through buttons based on imported data
wait = WebDriverWait(driver, 10)
main_tab = driver.current_window_handle
original_page = standardize_url(driver.current_url)
for d in data:
try:
button_elements = grab_button_elements(driver)
try:
url = standardize_url(data[d]['url'])
except:
error(f'Some error in grabbing the url from: {d}')
return False
if (url == original_page):
info(
f'link does not go anywhere, passing. {url} {original_page}')
pass
try:
element = [e for e in button_elements if e.text == d][0]
info(element.text)
info(f'Trying to open link labeled: "{element.text}"')
except:
error(
f'Button text does not match data file - data: {d} | elements: {[e.text for e in button_elements]}')
return False
try:
target = element.get_attribute('target')
info(f'target: {target}')
except:
error("Couldnt't find attribute 'target'.")
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)
wait.until(
expected_conditions.presence_of_all_elements_located)
if (url != standardize_url(driver.current_url)):
info(
f'Opened URL does not match data file - button_url: #{url}# | current_url: #{standardize_url(driver.current_url)}#')
if (url != original_page):
if (target == '_blank'):
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)
wait.until(
expected_conditions.presence_of_all_elements_located)
if (url != standardize_url(driver.current_url)):
info(
f'Opened URL does not match data file - button_url: #{url}# | current_url: #{standardize_url(driver.current_url)}#')
return False
driver.close()
driver.switch_to.window(main_tab)
else:
try:
wait.until(
expected_conditions.url_changes(url))
driver.back()
wait.until(
expected_conditions.presence_of_all_elements_located)
except:
error('Could not load page before timeout, I assume.')
return False
driver.close()
driver.switch_to.window(main_tab)
except:
error("Couldn't find the element somewhere...")
driver.close()