add tests
This commit is contained in:
parent
be5b06bd3f
commit
a12e213871
3 changed files with 81 additions and 0 deletions
23
tests/conftest.py
Normal file
23
tests/conftest.py
Normal file
|
|
@ -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()
|
||||
|
||||
39
tests/test_repos.py
Normal file
39
tests/test_repos.py
Normal file
|
|
@ -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'
|
||||
19
tests/test_scroll.py
Normal file
19
tests/test_scroll.py
Normal file
|
|
@ -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]
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue