diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..1022f36 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,23 @@ +import time +import pytest +from src.testproject.sdk.drivers import webdriver + +def get_driver(wait_time=0): + "creates a webdriver and loads the homepage" + driver = webdriver.Chrome() + driver.get("https://waylonwalker.com/") + time.sleep(wait_time) # wait for the GitHub api to load on the page + return driver + +@pytest.fixture +def driver(): + driver = get_driver() + yield driver + driver.quit() + +@pytest.fixture +def slow_driver(): + driver = get_driver(10) + yield driver + driver.quit() + diff --git a/tests/test_repos.py b/tests/test_repos.py new file mode 100644 index 0000000..46b86fa --- /dev/null +++ b/tests/test_repos.py @@ -0,0 +1,39 @@ +""" +Test that GitHub repo data dynamically loads client side. +""" + +REPOS = [ + "find-kedro", + "kedro-static-viz", + "kedro-action", + "steel-toes", +] +RSS = "https://waylonwalker.com/rss" + +def test_repos_loaded(slow_driver): + """ + Test that GitHub repo cards are loaded client side. + """ + repos = slow_driver.find_elements_by_class_name("repo-name") + header_text = [ + header.text for header in repos + ] + for repo in REPOS: + assert repo in header_text + + +def test_repo_description_loaded(slow_driver): + "Test that each repo has a description longer than 10 characters" + repo_elements = slow_driver.find_elements_by_class_name("repo") + for el in repo_elements: + desc = el.find_element_by_class_name("repo-description") + assert len(desc.text) > 10 + + +def test_repo_stars_loaded(slow_driver): + repo_elements = slow_driver.find_elements_by_class_name("repo") + for el in repo_elements: + stars = el.find_element_by_class_name("repo-stars") + num_stars, label = stars.text.split() + assert int(num_stars) > 0 + assert label == 'stars' diff --git a/tests/test_scroll.py b/tests/test_scroll.py new file mode 100644 index 0000000..903c3a9 --- /dev/null +++ b/tests/test_scroll.py @@ -0,0 +1,19 @@ +"Test that more cards load after scrolling" +from src.testproject.sdk.drivers import webdriver +import time + +def test_cards_load(driver): + "test that cards load on the page, and more load as we scroll" + num_cards = [] + num_cards.append(len(driver.find_elements_by_class_name('post-wrapper'))) + + driver = webdriver.Chrome() + driver.execute_script("window.scrollTo(0, 100000)") + # time.sleep(3) + num_cards.append(len(driver.find_elements_by_class_name('post-wrapper'))) + + # test that cards are loaded + assert num_cards[0] >= 3 + # test that more cards are loaded after scrolling + assert num_cards[0] > num_cards[1] +