Skip to content

Commit

Permalink
Merge pull request #187 from openstax/valid_selects
Browse files Browse the repository at this point in the history
adjusted poet ui tests as per gitpod changes + simplified some selectors
  • Loading branch information
omehes authored Dec 11, 2023
2 parents eb1e67e + e3a88d8 commit bc449da
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 119 deletions.
10 changes: 2 additions & 8 deletions tests/ui/content/test_content_validation_all_book_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ def test_content_validation_all_book_repos(
home = HomePoet(chrome_page)

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

else:
if home.gitpod_user_dropdown.inner_text() != "0 openstax":
home.click_gitpod_user_dropdown()
home.click_gitpod_user_selector()

Expand Down Expand Up @@ -94,10 +91,7 @@ def test_content_validation_all_book_repos(

github_login_window.click(sign_in_button_selector)

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

else:
if home.gitpod_user_dropdown.inner_text() != "0 openstax":
home.click_gitpod_user_dropdown()
home.click_gitpod_user_selector()

Expand Down
125 changes: 32 additions & 93 deletions tests/ui/pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,19 @@ class HomePoet:
def __init__(self, page):
self.page = page

@property
def github_login_button_locator(self):
return self.page.locator("input.btn.btn-primary.btn-block.js-sign-in-button")

@property
def github_login_button_is_visible(self):
return self.page.is_visible("input.btn.btn-primary.btn-block.js-sign-in-button")

def click_github_login_button(self):
self.github_login_button_locator.click()

@property
def workspace_continue_button(self):
return self.page.locator(
"div.w-full.flex.justify-end.mt-3.space-x-2.px-6 > button"
)
return self.page.locator("button").get_by_text("Continue")

def click_workspace_continue_button(self):
self.workspace_continue_button.click()

@property
def openstax_icon_is_visible(self):
return self.page.wait_for_selector(
"div.composite-bar > div > ul > li:nth-child(7)", timeout=210000
)

@property
def openstax_icon(self):
return self.page.wait_for_selector(
"div.composite-bar > div > ul > li:nth-child(7)", timeout=90000
)
return self.page.wait_for_selector("ul > li:nth-child(7)", timeout=90000)

def click_openstax_icon(self):
self.openstax_icon.click()
self.openstax_icon_is_visible.click()

@property
def parent_frame(self):
Expand All @@ -50,27 +29,17 @@ def child_frame(self):

@property
def open_toc_editor_button_is_visible(self):
return self.page.wait_for_selector(
"div.welcome-view-content > div:nth-child(1)", timeout=90000
)

@property
def open_toc_editor_button_locator(self):
return self.page.locator("div.welcome-view-content > div:nth-child(1)")
return self.page.get_by_text("Open ToC Editor", exact=True)

def click_open_toc_editor_button(self):
return self.open_toc_editor_button_locator.click()
return self.open_toc_editor_button_is_visible.click()

@property
def push_content_button_is_visible(self):
return self.page.is_visible("div.welcome-view-content > div:nth-child(2)")

@property
def push_content_button(self):
return self.page.locator("div.welcome-view-content > div:nth-child(2)")
return self.page.get_by_text("Push Content", exact=True)

def click_push_content_button(self):
return self.push_content_button.click()
return self.push_content_button_is_visible.click()

@property
def push_message_input_field_is_visible(self):
Expand All @@ -86,25 +55,21 @@ def push_content_dialog_box(self):

@property
def push_content_dialog_box_cancel_button(self):
return self.page.locator("div.notification-list-item-buttons-container > a")
return self.page.locator("div.notification-list-item-buttons-container")

def click_push_content_dialog_box_cancel_button(self):
return self.push_content_dialog_box_cancel_button.click()

@property
def generate_readme_button_is_visible(self):
return self.page.is_visible("div.welcome-view-content > div:nth-child(3)")

@property
def generate_readme_button(self):
return self.page.locator("div.welcome-view-content > div:nth-child(3)")
return self.page.get_by_text("Generate README", exact=True)

def click_generate_readme_button(self):
return self.generate_readme_button.click()
return self.generate_readme_button_is_visible.click()

@property
def generate_readme_dialog_box_is_visible(self):
return self.page.wait_for_selector("div.notifications-toasts.visible > div")
return self.page.wait_for_selector("div.notifications-toasts.visible")

@property
def generate_readme_dialog_box_text(self):
Expand All @@ -114,24 +79,20 @@ def generate_readme_dialog_box_text(self):

@property
def validate_content_button_is_visible(self):
return self.page.is_visible("div.welcome-view-content > div:nth-child(4)")
return self.page.get_by_text("Validate Content", exact=True)

@property
def validate_content_popup_dialog_is_visible(self):
return self.page.is_visible("div > div.monaco-dialog-modal-block.dimmed > div")
return self.page.is_visible("div > div.monaco-dialog-modal-block.dimmed")

@property
def toc_tree_dropdown_list_is_visible(self):
return self.page.locator(
"div.split-view-container > div:nth-child(2) > div > div.pane-header.expanded > h3"
"div.split-view-container > div:nth-child(2) > div > div.pane-header.expanded"
)

@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()
return self.validate_content_button_is_visible.click()

@property
def validate_content_all_content_option(self):
Expand All @@ -153,7 +114,7 @@ def validation_notification_dialog_box_is_visible(self):
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"
"div.notification-list-item-main-row > div.notification-list-item-message"
).all_inner_texts()
)

Expand Down Expand Up @@ -198,19 +159,11 @@ def fill_add_module_input_box(self, value):

@property
def chapter_box_title_locator(self):
return self.child_frame.locator(
"div.panel-editable > div:nth-child(2) > div > div > div > div:nth-child(1) > "
"div > div > div:nth-child(1) > div.rst__nodeContent > div > div > div > div.rst__rowContents > "
"div.rst__rowLabel > span.rst__rowTitle.rst__rowTitleWithSubtitle"
)
return self.child_frame.locator("span.node-title").first

@property
def chapter_box_title_input(self):
return self.child_frame.locator(
"div.panel-editable > div:nth-child(2) > div > div > div > div:nth-child(1) > "
"div > div > div:nth-child(1) > div.rst__nodeContent > div > div > div > div.rst__rowContents > "
"div.rst__rowLabel > span.rst__rowTitle.rst__rowTitleWithSubtitle > input"
)
return self.child_frame.locator("input.node-title-rename").first

def click_chapter_box_title(self):
self.chapter_box_title_locator.click()
Expand All @@ -233,7 +186,10 @@ def add_subcollection_input_box_locator(self):

@property
def add_subcollection_input_box_is_visible(self):
return self.page.locator("div.quick-input-widget.show-file-icons")
return self.page.get_by_text(
"Title of new Book Section (Press 'Enter' to confirm or 'Escape' to cancel)",
exact=True,
)

def fill_add_subcollection_input_box(self, value):
self.add_subcollection_input_box_locator.fill(value)
Expand All @@ -256,20 +212,12 @@ def subcollection_locator_new_box(self):
@property
def subcollection_locator_new_box_title(self):
# Title of the last newly added item in the chapter list (left panel)
return self.child_frame.locator(
"div.panel-editable > div:nth-child(2) > div > div > div > div:nth-child(1) > "
"div > div > div:nth-child(1) > div.rst__nodeContent > div > div > div > div.rst__rowContents > "
"div.rst__rowLabel"
)
return self.child_frame.locator("span.node-title").first

@property
def subcollection_locator_new_box_title_input(self):
# Title of the last newly added item in the chapter list (left panel)
return self.child_frame.locator(
"div.panel-editable > div:nth-child(2) > div > div > div > div:nth-child(1) > "
"div > div > div:nth-child(1) > div.rst__nodeContent > div > div > div > div.rst__rowContents > "
"div.rst__rowLabel > span > input"
)
return self.child_frame.locator("input.node-title-rename").first

def click_new_subcollection_box_title(self):
self.subcollection_locator_new_box_title.click()
Expand All @@ -290,14 +238,14 @@ def fill_search_field(self, value):
def search_item_amount_indicator_is_visible(self):
# Search info (how many items search shows)
return self.child_frame.locator(
"div.panel-editable > div.controls > div:nth-child(3) > p"
"div.panel-editable > div.controls > div:nth-child(3)"
)

# TOC Editor right panel ------

@property
def toc_editor_all_modules_dropdown_is_visible(self):
return self.page.locator("div[class='controls']")
return self.page.locator("div.controls")

@property
def toc_editor_deleted_modules_list_is_visible(self):
Expand All @@ -309,16 +257,14 @@ def toc_editor_deleted_modules_list_is_visible(self):

@property
def gitpod_menubar_locator(self):
return self.page.locator('div[class="menubar-menu-button"]')
return self.page.locator("div.menubar-menu-button")

def click_gitpod_menubar(self):
self.gitpod_menubar_locator.click()

@property
def stop_workspace_button_locator(self):
return self.page.locator(
"div.monaco-menu > div > ul > li:nth-child(15) > a > span.action-label"
)
return self.page.get_by_text("Gitpod: Stop Workspace", exact=True)

def click_stop_workspace_button(self):
self.stop_workspace_button_locator.click()
Expand All @@ -337,7 +283,7 @@ def click_explorer_button(self):
@property
def explorer_modules_locator(self):
return self.page.wait_for_selector(
"div[class='monaco-list-row'] :text('modules')", timeout=90000
"div.monaco-list-row :text('modules')", timeout=90000
)

def click_explorer_modules(self):
Expand All @@ -357,15 +303,8 @@ def explorer_index_file_locator(self):
def click_explorer_index_file(self):
self.explorer_index_file_locator.click()

@property
def problems_tab_locator(self):
return self.page.wait_for_selector(
"div.composite-bar-container > div > div > ul > li:nth-child(2)",
timeout=90000,
)

def click_problems_tab(self):
self.problems_tab_locator.click()
return self.page.get_by_text("Problems", exact=True).click()

@property
def problems_tab_message(self):
Expand Down Expand Up @@ -403,8 +342,8 @@ def continue_with_github_is_visible(self):

@property
def continue_with_github_button(self):
return self.page.locator(
"div > div.w-56.mx-auto.flex.flex-col.space-y-3.items-center > button"
return self.page.locator("button").get_by_text(
"Continue with GitHub", exact=True
)

def click_continue_with_github_button(self):
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/test_home_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ def test_home_ui(chrome_page, github_user, github_password, gitpod_repo_url):
# GIVEN: Playwright, chromium and a gitpod repo url
# (https://gitpod.io/#https://github.com/openstax/osbooks-otto-book)

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

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

home.click_github_login_button()
if home.continue_with_github_is_visible:
home.click_continue_with_github_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("input.btn.btn-primary.btn-block.js-sign-in-button")

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

else:
if home.gitpod_user_dropdown.inner_text() != "0 openstax":
home.click_gitpod_user_dropdown()
home.click_gitpod_user_selector()

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/test_readme_validate_other_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ def test_readme_validate_other_features(
# GIVEN: Playwright, chromium and a gitpod repo url
# (https://gitpod.io/#https://github.com/openstax/osbooks-otto-book)

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

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

home.click_github_login_button()
if home.continue_with_github_is_visible:
home.click_continue_with_github_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("input.btn.btn-primary.btn-block.js-sign-in-button")

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

else:
if home.gitpod_user_dropdown.inner_text() != "0 openstax":
home.click_gitpod_user_dropdown()
home.click_gitpod_user_selector()

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/test_toc_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ def test_toc_editor(chrome_page, github_user, github_password, gitpod_repo_url):
# GIVEN: Playwright, chromium and a gitpod repo url
# (https://gitpod.io/#https://github.com/openstax/osbooks-otto-book)

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

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

# WHEN: login into openstax/osbooks-otto-book repo
home.click_github_login_button()
if home.continue_with_github_is_visible:
home.click_continue_with_github_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("input.btn.btn-primary.btn-block.js-sign-in-button")

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

else:
if home.gitpod_user_dropdown.inner_text() != "0 openstax":
home.click_gitpod_user_dropdown()
home.click_gitpod_user_selector()

Expand Down

0 comments on commit bc449da

Please sign in to comment.