Skip to content

Commit

Permalink
content validation qa test
Browse files Browse the repository at this point in the history
  • Loading branch information
omehes committed Oct 26, 2023
1 parent 6dac409 commit 1784d30
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 6 deletions.
7 changes: 6 additions & 1 deletion tests/ui/fixtures/git_content_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def git_content_repos(headers_data):

repos = []

# list of excluded test git repos
# list of excluded test and non-valid book repos
dels = [
"osbooks-testing",
"osbooks-otto-book",
Expand All @@ -20,6 +20,11 @@ def git_content_repos(headers_data):
"osbooks-failing-test-book",
"osbooks-test-content",
"osbooks-makroekonomia-test",
"osbooks-mikroekonomia",
"osbooks-life-liberty-and-pursuit-happiness",
"osbooks-fizyka-bundle",
"osbooks-psychologia",
"osbooks-pl-marketing",
]

next_url = "https://api.github.com/orgs/openstax/repos?per_page=50"
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fixtures/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def chrome_page():
"""Return playwright chromium browser page - slow flow"""
playwright_sync = sync_playwright().start()
chrome_browser = playwright_sync.chromium.launch(
headless=True, slow_mo=1400, timeout=120000
headless=True, slow_mo=1600, timeout=120000
)
context = chrome_browser.new_context()

Expand Down
50 changes: 46 additions & 4 deletions tests/ui/pages/home.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import time


class HomePoet:
def __init__(self, page):
self.page = page
Expand Down Expand Up @@ -72,6 +75,35 @@ def toc_tree_dropdown_list_is_visible(self):
"div.split-view-container > div:nth-child(2) > div > div.pane-header.expanded > h3"
)

@property
def validate_content_button(self):
return self.page.locator("div.welcome-view-content > div:nth-child(4)")

def click_validate_content_button(self):
return self.validate_content_button.click()

@property
def validate_content_all_content_option(self):
return self.page.locator("div.dialog-buttons-row > div > a:nth-child(1)")

def click_validate_content_all_content_option(self):
return self.validate_content_all_content_option.click()

@property
def validation_notification_dialog_box_is_visible(self):
# Content validation dialog showing the validation progress
return any(
"Opening documents with errors..." in inner_text
for inner_text in self.page.locator(
"div.notification-list-item-main-row > div.notification-list-item-message > span"
).all_inner_texts()
)

@property
def cannot_activate_poet_dialog_box_is_visible(self):
# Dialog for missing gitpod.yml file in book repos
return self.page.is_visible("div > div.notifications-toasts.visible")

# TOC Editor left panel ------

@property
Expand Down Expand Up @@ -287,10 +319,6 @@ def problems_tab_message(self):
def private_repo_warning_is_visible(self):
return self.page.is_visible("span.flex-1.text-left > div:nth-child(1)")

@property
def workspace_limit_warning_is_visible(self):
return self.page.is_visible("div:nth-child(6) > div > div > div:nth-child(2)")

# To change users in gitpod user dropdown

@property
Expand All @@ -308,3 +336,17 @@ def gitpod_user_selector(self):

def click_gitpod_user_selector(self):
self.gitpod_user_selector.click()

def wait_for_validation_end(
self, condition, timeout_seconds=900, interval_seconds=10
):
# Waits for the content validation process to complete (at various times depending on the book repo)
end = time.time() + timeout_seconds
while time.time() < end:
if condition():
time.sleep(interval_seconds)

else:
return True

raise Exception("Timeout")
151 changes: 151 additions & 0 deletions tests/ui/test_content_validation_all_repos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import pytest

from tests.ui.pages.home import HomePoet


@pytest.mark.nondestructive
def test_content_validation_all_repos(
chrome_page, github_user, github_password, git_content_repos, headers_data
):
# GIVEN: Playwright, chromium and gitpod
# repo url as: https://gitpod.io/#https://github.com/openstax/osbooks-content-repo
# run the test: pytest -k test_content_validation_all_repos.py tests/ui --github_user xxx --github_password yyy
# --github_token zzz > validation.log

sign_in_button_selector = "input.btn.btn-primary.btn-block.js-sign-in-button"

for repo in git_content_repos:
gitpod_repo_url = "https://gitpod.io/#https://github.com/openstax/" + repo

print(f"VERIFYING: {gitpod_repo_url}")

# WHEN: gitpod launches
chrome_page.goto(gitpod_repo_url)
home = HomePoet(chrome_page)

if not home.github_login_button_is_visible:
if home.private_repo_warning_is_visible:
print(f"SKIPPING! Book repo is private: {repo}")
continue

else:
if home.gitpod_user_dropdown.inner_text() == "0 openstax":
pass

else:
home.click_gitpod_user_dropdown()
home.click_gitpod_user_selector()

home.click_workspace_continue_button()

# THEN: openstax extension launches and icon appears
if not home.openstax_icon_is_visible:
print("No openstax icon")
else:
home.click_openstax_icon()

# THEN: TOC Editor and book list dropdown is visible
if not home.open_toc_editor_button_is_visible:
print(">>>TOC Editor button not loaded, skipping")
continue

else:
if home.cannot_activate_poet_dialog_box_is_visible:
print(f"POET install issues: {repo}")
continue

# THEN content validation launches
home.click_validate_content_button()
home.click_validate_content_all_content_option()

home.wait_for_validation_end(
lambda: home.validation_notification_dialog_box_is_visible
)

# THEN Problems tab is checked for any validation problems
chrome_page.keyboard.press("Escape")
home.click_problems_tab()

try:
assert (
"No problems have been detected in the workspace."
in home.problems_tab_message.inner_text()
)

except AssertionError:
print(f"!!! Problems detected under Problems tab: {repo}")
print(f"{home.problems_tab_message.inner_text()}")

else:
print(f"NO PROBLEMS IN {repo}")

home.click_gitpod_menubar()
home.click_stop_workspace_button()

else:
if home.private_repo_warning_is_visible:
print(f"SKIPPING! Book repo is private: {repo}")
continue

else:
# WHEN: login into repo
home.click_github_login_button()

with chrome_page.context.pages[1] as github_login_window:
github_login_window.fill("#login_field", github_user)
github_login_window.fill("#password", github_password)

github_login_window.click(sign_in_button_selector)

if home.gitpod_user_dropdown.inner_text() == "0 openstax":
pass

else:
home.click_gitpod_user_dropdown()
home.click_gitpod_user_selector()

home.click_workspace_continue_button()

if not home.openstax_icon_is_visible:
print("No openstax icon")
else:
# THEN: openstax extension launches and icon appears
home.click_openstax_icon()

# THEN: TOC Editor and book list dropdown is visible
if not home.open_toc_editor_button_is_visible:
print(">>> TOC Editor button not loaded, skipping")
continue

else:
if home.cannot_activate_poet_dialog_box_is_visible:
print(f"POET install issues: {repo}")
continue

# THEN content validation launches
home.click_validate_content_button()
home.click_validate_content_all_content_option()

home.wait_for_validation_end(
lambda: home.validation_notification_dialog_box_is_visible
)

# THEN Problems tab is checked for any validation problems
chrome_page.keyboard.press("Escape")
home.click_problems_tab()

try:
assert (
"No problems have been detected in the workspace."
in home.problems_tab_message.inner_text()
)

except AssertionError:
print(f"!!! Problems detected under Problems tab: {repo}")
print(f"{home.problems_tab_message.inner_text()}")

else:
print(f"NO PROBLEMS IN {repo}")

home.click_gitpod_menubar()
home.click_stop_workspace_button()

0 comments on commit 1784d30

Please sign in to comment.