use python unittest for selenium tests

This commit is contained in:
Andrew Dolgov 2023-10-28 11:11:13 +03:00
parent a1a2fe40f6
commit d2424b9e4b
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A
1 changed files with 49 additions and 26 deletions

View File

@ -1,44 +1,67 @@
#!/usr/bin/python3
import os
import sys
import traceback
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
CI_COMMIT_SHORT_SHA = os.getenv("CI_COMMIT_SHORT_SHA")
SELENIUM_GRID_ENDPOINT = os.getenv("SELENIUM_GRID_ENDPOINT")
K8S_NAMESPACE = os.getenv("K8S_NAMESPACE")
class SeleniumTest(unittest.TestCase):
def setUp(self):
CI_COMMIT_SHORT_SHA = os.getenv("CI_COMMIT_SHORT_SHA")
SELENIUM_GRID_ENDPOINT = os.getenv("SELENIUM_GRID_ENDPOINT")
K8S_NAMESPACE = os.getenv("K8S_NAMESPACE")
driver = webdriver.Remote(command_executor=SELENIUM_GRID_ENDPOINT, options=webdriver.ChromeOptions())
self.driver = webdriver.Remote(command_executor=SELENIUM_GRID_ENDPOINT, options=webdriver.ChromeOptions())
self.base_url = f"http://tt-rss-{CI_COMMIT_SHORT_SHA}-app.{K8S_NAMESPACE}.svc.cluster.local/tt-rss"
try:
base_url = f"http://tt-rss-{CI_COMMIT_SHORT_SHA}-app.{K8S_NAMESPACE}.svc.cluster.local/tt-rss"
print(f"requesting base url: {base_url}")
driver.get(base_url)
def tearDown(self):
self.driver.quit()
print("filling in login information...")
def test_login(self):
self.driver.get(self.base_url)
for name in ["login", "password"]:
field = driver.find_element(by=By.CSS_SELECTOR, value=f"input[name='{name}']")
field.clear()
field.send_keys("test")
assert self.driver.find_element(by=By.CSS_SELECTOR, value="body.ttrss_login")
print("logging in...")
for name in ["login", "password"]:
field = self.driver.find_element(by=By.CSS_SELECTOR, value=f"input[name='{name}']")
field.clear()
field.send_keys("test")
login_button = driver.find_element(by=By.CSS_SELECTOR, value="#dijit_form_Button_0_label")
login_button.click()
login_button = self.driver.find_element(by=By.CSS_SELECTOR, value="#dijit_form_Button_0_label")
login_button.click()
print("checking for feedTree...")
def test_index(self):
self.test_login()
assert driver.find_element(by=By.CSS_SELECTOR, value="#feedTree")
assert self.driver.find_element(by=By.CSS_SELECTOR, value="body.ttrss_main")
print("all done.")
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#feedTree")))
except Exception:
traceback.print_exc()
sys.exit(1)
finally:
driver.quit()
assert self.driver.find_element(by=By.CSS_SELECTOR, value="#feedTree").is_displayed()
self.driver.execute_script("Feeds.open({feed:-4})")
assert self.driver.find_element(by=By.CSS_SELECTOR, value="#headlines-frame").is_displayed()
self.driver.execute_script("Filters.edit()")
assert self.driver.find_element(by=By.CSS_SELECTOR, value="#filterEditDlg").is_displayed()
def test_prefs(self):
self.test_login()
self.driver.get(self.base_url + "/prefs.php")
assert self.driver.find_element(by=By.CSS_SELECTOR, value="body.ttrss_prefs")
assert self.driver.find_element(by=By.CSS_SELECTOR, value="#dijit_layout_AccordionPane_1_wrapper").is_displayed()
self.driver.execute_script("dijit.byId('pref-tabs').selectChild('feedsTab')")
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#feedTree")))
assert self.driver.find_element(by=By.CSS_SELECTOR, value="#feedTree").is_displayed()
unittest.main()