Added test code for the root domain and debug mode for test script. TODO: Implement RobotFramework and switch Dockerfile to use requirement.txt
parent
08150e8d96
commit
6799730a99
@ -1,5 +1,13 @@
|
||||
#/bin/bash
|
||||
#!/bin/bash
|
||||
|
||||
cd tests/
|
||||
docker compose build --no-cache --pull && docker compose up --remove-orphans --abort-on-container-exit --exit-code-from selenium-node
|
||||
docker compose rm -sf
|
||||
set -xe
|
||||
|
||||
MODE=$1
|
||||
|
||||
if [ "$MODE" == "debug" ]; then
|
||||
docker run --rm --name selenium-debug -p "4444:4444" -p "7900:7900" -e SE_OPTS="--allow-cors true" --shm-size="2g" selenium/standalone-chrome:108.0
|
||||
else
|
||||
cd tests/
|
||||
docker compose build --no-cache --pull && docker compose up --remove-orphans --abort-on-container-exit --exit-code-from selenium-node
|
||||
docker compose rm -sf
|
||||
fi
|
||||
|
@ -0,0 +1 @@
|
||||
selenium>=4.7.2
|
@ -0,0 +1,65 @@
|
||||
#!/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
|
||||
|
||||
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:
|
||||
sites = driver.find_element(By.TAG_NAME, "nav").find_elements(By.XPATH, "./div/div")
|
||||
except:
|
||||
print("Couldn't find the element.")
|
||||
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:
|
||||
print("Couldn't find the element somewhere...")
|
||||
driver.close()
|
||||
driver.quit()
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def execute_tests():
|
||||
# Set up webdriver and necessary variables for later
|
||||
chrome_options = webdriver.ChromeOptions()
|
||||
print('Attempting to establish connection to remote webdriver...')
|
||||
driver = webdriver.Remote(command_executor='http://192.168.0.202:4444', options=chrome_options)
|
||||
print('Connection established.')
|
||||
|
||||
# Load requested site
|
||||
print('Attempting to get page...')
|
||||
driver.get("https://werefox.cafe")
|
||||
print('Page loaded.')
|
||||
|
||||
# Check all the subdomain buttons work
|
||||
print('Attempting to click through subdomain buttons...')
|
||||
if(check_subdomains(driver)):
|
||||
print('Test succeeded.')
|
||||
else:
|
||||
print('Test failed.')
|
||||
|
||||
# Close browser and lean up
|
||||
driver.close()
|
||||
driver.quit()
|
||||
|
||||
execute_tests()
|
@ -1,12 +0,0 @@
|
||||
from selenium import webdriver
|
||||
from time import sleep
|
||||
chrome_options = webdriver.ChromeOptions()
|
||||
print('Attempting to establish connection to remote webdriver...')
|
||||
driver = webdriver.Remote(command_executor='http://selenium-hub:4444', options=chrome_options)
|
||||
print('Connection established.')
|
||||
print('Attempting to get page...')
|
||||
driver.get("https://werefox.cafe")
|
||||
print('Page loaded.')
|
||||
sleep(10)
|
||||
driver.close()
|
||||
driver.quit()
|
Loading…
Reference in new issue