use python unittest for selenium tests
This commit is contained in:
parent
a1a2fe40f6
commit
d2424b9e4b
|
@ -1,44 +1,67 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import unittest
|
||||||
import traceback
|
|
||||||
|
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.common.by import By
|
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")
|
class SeleniumTest(unittest.TestCase):
|
||||||
SELENIUM_GRID_ENDPOINT = os.getenv("SELENIUM_GRID_ENDPOINT")
|
def setUp(self):
|
||||||
K8S_NAMESPACE = os.getenv("K8S_NAMESPACE")
|
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:
|
def tearDown(self):
|
||||||
base_url = f"http://tt-rss-{CI_COMMIT_SHORT_SHA}-app.{K8S_NAMESPACE}.svc.cluster.local/tt-rss"
|
self.driver.quit()
|
||||||
print(f"requesting base url: {base_url}")
|
|
||||||
driver.get(base_url)
|
|
||||||
|
|
||||||
print("filling in login information...")
|
def test_login(self):
|
||||||
|
self.driver.get(self.base_url)
|
||||||
|
|
||||||
|
assert self.driver.find_element(by=By.CSS_SELECTOR, value="body.ttrss_login")
|
||||||
|
|
||||||
for name in ["login", "password"]:
|
for name in ["login", "password"]:
|
||||||
field = driver.find_element(by=By.CSS_SELECTOR, value=f"input[name='{name}']")
|
field = self.driver.find_element(by=By.CSS_SELECTOR, value=f"input[name='{name}']")
|
||||||
field.clear()
|
field.clear()
|
||||||
field.send_keys("test")
|
field.send_keys("test")
|
||||||
|
|
||||||
print("logging in...")
|
login_button = self.driver.find_element(by=By.CSS_SELECTOR, value="#dijit_form_Button_0_label")
|
||||||
|
|
||||||
login_button = driver.find_element(by=By.CSS_SELECTOR, value="#dijit_form_Button_0_label")
|
|
||||||
login_button.click()
|
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:
|
assert self.driver.find_element(by=By.CSS_SELECTOR, value="#feedTree").is_displayed()
|
||||||
traceback.print_exc()
|
|
||||||
sys.exit(1)
|
|
||||||
finally:
|
|
||||||
driver.quit()
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
Loading…
Reference in New Issue