Skip to content

Commit

Permalink
Test render should wait for elements to appear
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekeldeeb committed Sep 12, 2023
1 parent 178f21d commit f8dae43
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"madina",
"Mus'haf",
"Mushaf",
"Prefs",
"pylance",
"pytest",
"Tanzil",
Expand Down
32 changes: 24 additions & 8 deletions test/render_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

class BasicRenderTest(unittest.TestCase):
"""Testing the Render of all Quran data
Expand All @@ -24,9 +26,8 @@ class BasicRenderTest(unittest.TestCase):
for option in options:
chrome_options.add_argument(option)
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
capabilities = DesiredCapabilities.CHROME
capabilities['loggingPrefs'] = { 'browser':'ALL' } # type: ignore
web_driver = webdriver.Chrome(options=chrome_options, desired_capabilities=capabilities)
chrome_options.set_capability("loggingPrefs", {'performance': 'ALL'})
web_driver = webdriver.Chrome(options=chrome_options)
test_file = os.path.join("template", "render_test.html")
test_url = "http://localhost:8000/" + test_file
web_driver.get(test_url)
Expand All @@ -46,17 +47,32 @@ def set_page(self, page):
soup.find("quran-madina-html")["page"] = page #type: ignore
with open(self.test_file, 'w', encoding="utf8") as file:
file.write(str(soup))

self.web_driver.refresh()
try:
WebDriverWait(self.web_driver, 10).until(
EC.presence_of_element_located((By.TAG_NAME, "quran-madina-html-line")) )
except TimeoutException:
print(f"Timeout Exception at page {page}")

def test_0_lines_exists(self):
"""Check if all 15 lines exist in all pages
"""
for page in range(3, 604):
for page in range(3, 605):
self.set_page(page)
self.web_driver.refresh()
lines = self.web_driver.execute_script('return document.getElementsByTagName'
'("quran-madina-html-line").length')
self.assertEqual(lines, 15, f'Page {page} should have 15 lines, found {lines}!'
f'\n::Console::\n{self.dump_log()}')

def test_1_lines_exists_short_pages(self):
"""Check if all 15 lines exist in all pages
"""
for page in range(1, 3):
self.set_page(page)
lines = self.web_driver.execute_script('return document.getElementsByTagName'
'("quran-madina-html-line").length')
self.assertEqual(lines, 8, f'Page {page} should have 8 lines, found {lines}!'
f'\n::Console::\n{self.dump_log()}')

if __name__ == '__main__':
unittest.main()

0 comments on commit f8dae43

Please sign in to comment.