From 401ee636f5cffc8dcaea21e2f38c8a6da130fc5b Mon Sep 17 00:00:00 2001 From: Ada Werefox Date: Sat, 21 Jan 2023 20:48:07 +0000 Subject: [PATCH] change Dockerfile to use requirements.txt, add Robot Framework files and change command to run test suites in specified dir as well as output in a seperate dir. --- .gitignore | 4 ++- tests/Dockerfile | 3 +- tests/docker-compose.yml | 4 ++- tests/requirements.txt | 1 + tests/test_suite/root_domain_test.py | 50 ++++++++++++++++---------- tests/test_suite/werefox_cafe.resource | 19 ++++++++++ tests/test_suite/werefox_cafe.robot | 16 +++++++++ 7 files changed, 75 insertions(+), 22 deletions(-) create mode 100755 tests/test_suite/werefox_cafe.resource create mode 100755 tests/test_suite/werefox_cafe.robot diff --git a/.gitignore b/.gitignore index dbe9c82..1d45500 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.vscode/ \ No newline at end of file +.vscode/ +output/ +__pycache__/ \ No newline at end of file diff --git a/tests/Dockerfile b/tests/Dockerfile index afd64ed..6231807 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -1,5 +1,6 @@ FROM python:alpine USER root -RUN python3 -m pip install selenium +COPY ./requirements.txt /requirements.txt +RUN python3 -m pip install -r /requirements.txt WORKDIR / diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 25e9e79..e86f95f 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -23,8 +23,10 @@ services: depends_on: selenium-hub: condition: service_healthy + environment: + - PYTHONPYCACHEPREFIX:"${HOME}/" volumes: - ./test_suite:/tests:ro - ./output:/output:rw user: "1000:1000" - command: 'python3 /tests/root_domain_test.py' + command: 'python3 -m robot -d /output /tests' diff --git a/tests/requirements.txt b/tests/requirements.txt index 1b8ec00..5831d39 100755 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1 +1,2 @@ selenium>=4.7.2 +robotframework>=6.0.0 \ No newline at end of file diff --git a/tests/test_suite/root_domain_test.py b/tests/test_suite/root_domain_test.py index c3d395c..700da5a 100644 --- a/tests/test_suite/root_domain_test.py +++ b/tests/test_suite/root_domain_test.py @@ -5,6 +5,8 @@ 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_subdomains(driver): # setup wait and grab original tab/window @@ -13,9 +15,10 @@ 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") + sites = driver.find_element( + By.TAG_NAME, "nav").find_elements(By.XPATH, "./div/div") except: - print("Couldn't find the element.") + error("Couldn't find the element.") driver.close() driver.quit() return False @@ -32,34 +35,43 @@ def check_subdomains(driver): driver.close() driver.switch_to.window(main_tab) except: - print("Couldn't find the element somewhere...") + error("Couldn't find the element somewhere...") driver.close() driver.quit() return False return True -def execute_tests(): + +def setup_webdriver(remote_url): # 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.') + info('Attempting to establish connection to remote webdriver...') + driver = webdriver.Remote( + command_executor=remote_url, options=chrome_options) + info('Connection established.') + return driver - # 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.') +def teardown_webdriver(driver): # Close browser and lean up driver.close() driver.quit() -execute_tests() + +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() diff --git a/tests/test_suite/werefox_cafe.resource b/tests/test_suite/werefox_cafe.resource new file mode 100755 index 0000000..b7faaac --- /dev/null +++ b/tests/test_suite/werefox_cafe.resource @@ -0,0 +1,19 @@ +*** Settings *** +Documentation Import Python functions + +Library ./root_domain_test.py + + +*** Keywords *** +# My Keyword [Arguments] ${path} +# Directory Should Exist ${path} +Werefox Cafe Test Cases + [Arguments] ${remote_url} ${site_url} + + ${driver}= Setup Webdriver ${remote_url} + + ${result}= Execute Tests ${driver} ${site_url} + + Should Be True ${result} + + [Teardown] Teardown Webdriver ${driver} diff --git a/tests/test_suite/werefox_cafe.robot b/tests/test_suite/werefox_cafe.robot new file mode 100755 index 0000000..71e97d8 --- /dev/null +++ b/tests/test_suite/werefox_cafe.robot @@ -0,0 +1,16 @@ +*** Settings *** +Documentation Validate functionality of root domain site. + +Resource werefox_cafe.resource + +Default Tags positive + + +*** Variables *** +${remote_url} http://192.168.0.202:4444 +${site_url} https://werefox.cafe + + +*** Test Cases *** +Test Werefox Cafe [Documentation] Run Werefox Cafe Test Cases. + Werefox Cafe Test Cases ${remote_url} ${site_url}