mirror of
https://github.com/tcsenpai/Zundler.git
synced 2025-06-06 11:35:40 +00:00
128 lines
3.3 KiB
Python
128 lines
3.3 KiB
Python
import time
|
|
from pathlib import Path
|
|
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.common.keys import Keys
|
|
|
|
|
|
TEST_DIR = Path(__file__).resolve().parent
|
|
|
|
|
|
def test_copy_button(selenium_drivers):
|
|
path = Path("//mnt//copy-button//_build//zundler//index.html")
|
|
selenium = selenium_drivers["firefox"]
|
|
selenium.get(path.as_uri())
|
|
|
|
time.sleep(1)
|
|
|
|
assert "copy-button documentation" in selenium.title
|
|
|
|
selenium.switch_to.frame("zundler-iframe")
|
|
|
|
button = selenium.find_element(By.CSS_SELECTOR, "button.copybtn")
|
|
|
|
assert button.get_attribute("data-tooltip") == "Copy"
|
|
assert "success" not in button.get_attribute("class")
|
|
|
|
button.click()
|
|
|
|
assert button.get_attribute("data-tooltip") == "Copied!"
|
|
assert "success" in button.get_attribute("class")
|
|
|
|
# Check layout
|
|
assert button.location["y"] < 55
|
|
assert button.location["y"] > 45
|
|
|
|
|
|
def test_mermaid(selenium_drivers):
|
|
path = Path("//mnt//mermaid//_build//zundler//index.html")
|
|
selenium = selenium_drivers["firefox"]
|
|
selenium.get(path.as_uri())
|
|
|
|
time.sleep(1)
|
|
|
|
assert "mermaid documentation" in selenium.title
|
|
|
|
selenium.switch_to.frame("zundler-iframe")
|
|
|
|
section = selenium.find_element(By.CSS_SELECTOR, "#section")
|
|
svg = selenium.find_element(By.CSS_SELECTOR, "div.mermaid")
|
|
|
|
# Check layout
|
|
assert svg.size["height"] > 500
|
|
assert section.location["y"] > 500
|
|
|
|
|
|
def test_multi_page(selenium_drivers):
|
|
path = Path("//mnt//multi-page//_build//zundler//index.html")
|
|
selenium = selenium_drivers["firefox"]
|
|
selenium.get(path.as_uri())
|
|
|
|
time.sleep(1)
|
|
|
|
assert "multi-page documentation" in selenium.title
|
|
|
|
selenium.switch_to.frame("zundler-iframe")
|
|
|
|
second_link = selenium.find_element(
|
|
By.XPATH, "//a[text() = 'Second' and @class = 'reference internal']"
|
|
)
|
|
|
|
second_link.click()
|
|
|
|
time.sleep(1)
|
|
|
|
assert selenium.title.startswith("Second")
|
|
|
|
|
|
def test_multi_page_search(selenium_drivers):
|
|
path = Path("//mnt//multi-page//_build//zundler//index.html")
|
|
selenium = selenium_drivers["firefox"]
|
|
selenium.get(path.as_uri())
|
|
|
|
time.sleep(1)
|
|
|
|
assert "multi-page documentation" in selenium.title
|
|
|
|
selenium.switch_to.frame("zundler-iframe")
|
|
|
|
# Search for "Lorem"
|
|
searchbox = selenium.find_element(By.CSS_SELECTOR, "#searchbox input[type='text']")
|
|
|
|
searchbox.send_keys("Lorem" + Keys.ENTER)
|
|
|
|
selenium.switch_to.parent_frame()
|
|
time.sleep(1)
|
|
selenium.switch_to.frame("zundler-iframe")
|
|
|
|
assert selenium.title.startswith("Search")
|
|
|
|
span = selenium.find_element(By.CSS_SELECTOR, "span.highlighted")
|
|
|
|
assert span.text == "Lorem"
|
|
|
|
# Click on first result
|
|
link = selenium.find_element(By.CSS_SELECTOR, "#search-results a")
|
|
link.click()
|
|
|
|
selenium.switch_to.parent_frame()
|
|
time.sleep(1)
|
|
selenium.switch_to.frame("zundler-iframe")
|
|
|
|
header = selenium.find_element(By.CSS_SELECTOR, "#first h1")
|
|
|
|
assert header.text.startswith("First")
|
|
|
|
span = selenium.find_element(By.CSS_SELECTOR, "span.highlighted")
|
|
|
|
assert span.text == "Lorem"
|
|
|
|
# Click on "Hide Search Matches"
|
|
hide_link = selenium.find_element(By.CSS_SELECTOR, "#searchbox a")
|
|
|
|
hide_link.click()
|
|
|
|
span = selenium.find_element(By.CSS_SELECTOR, "span.highlighted")
|
|
|
|
assert span == []
|