class HostListPage(BasePageObject): """Host List Page class""" def __init__(self, driver, base_url): super().__init__(driver, base_url, "/host") self.header = PageHeader(self.driver, self.base_url) self.footer = PageFooter(self.driver, self.base_url) self.table = CommonTableObj(self.driver, self.base_url, HostListLocators.HostTable) self.host_popup = HostCreatePopupObj(self.driver, self.base_url) @allure.step('Get host information from row #{row_num}') def get_host_row(self, row_num: int = 0) -> WebElement: """Get host information from row""" def _table_has_enough_rows(): assert_enough_rows(row_num, self.table.row_count) wait_until_step_succeeds(_table_has_enough_rows, timeout=5, period=0.1) rows = self.table.get_all_rows() assert_enough_rows(row_num, len(rows)) return rows[row_num] @allure.step('Get host information from table row #{row_num}') def get_host_info_from_row(self, row_num: int = 0) -> HostRowInfo: """Get host information from table row""" row = self.table.get_row(row_num) row_elements = HostListLocators.HostTable.HostRow cluster_value = self.find_child(row, row_elements.cluster).text return HostRowInfo( fqdn=self.find_child(row, row_elements.fqdn).text, provider=self.find_child(row, row_elements.provider).text, cluster=cluster_value if cluster_value != HostRowInfo.UNASSIGNED_CLUSTER_VALUE else None, state=self.find_child(row, row_elements.state).text, ) @allure.step('Click on cell {child_locator} (row #{row_num})') def click_on_row_child(self, row_num: int, child_locator: Locator): """Click on row child""" row = self.table.get_row(row_num) self.find_child(row, child_locator).click() @allure.step("Create new host") def create_host( self, fqdn: str, cluster: Optional[str] = None, ): """Create host in popup""" self.open_host_creation_popup() self._insert_new_host_info(fqdn, cluster) self.click_create_host_in_popup() self.close_host_creation_popup() @allure.step("Upload bundle from host creation popup") def upload_bundle_from_host_create_popup(self, bundle_path: str): """Upload bundle in host creation popup and close popup""" self.open_host_creation_popup() self._upload_bundle(bundle_path) self.close_host_creation_popup() @allure.step("Create new provider and host") def create_provider_and_host( self, bundle_path: str, fqdn: str, cluster: Optional[str] = None, ) -> str: """ Open host creation popup Upload bundle and create provider Fill in information about new host Create host Close popup :returns: Name of created provider """ self.open_host_creation_popup() self._upload_bundle(bundle_path) provider_name = self._get_hostprovider_name() self._insert_new_host_info(fqdn, cluster) self.click_create_host_in_popup() self.close_host_creation_popup() # because we don't pass provider name return provider_name @allure.step( 'Run action "{action_display_name}" on host in row {host_row_num}') def run_action(self, host_row_num: int, action_display_name: str): """Run action from Host row""" host_row = HostListLocators.HostTable.HostRow self.click_on_row_child(host_row_num, host_row.actions) init_action = self.wait_element_visible( host_row.action_option(action_display_name)) init_action.click() self.wait_element_visible(ActionDialog.body) self.find_and_click(ActionDialog.run) self.wait_element_hide(ActionDialog.body) @allure.step('Delete host in row {host_row_num}') def delete_host(self, host_row_num: int): """Delete host from table row""" self.click_on_row_child(host_row_num, HostListLocators.HostTable.HostRow.delete_btn) self.wait_element_visible(DeleteDialog.body) self.find_and_click(DeleteDialog.yes) self.wait_element_hide(DeleteDialog.body) @allure.step('Bind host in row {host_row_num} to cluster "{cluster_name}"') def bind_host_to_cluster(self, host_row_num: int, cluster_name: str): """Assign host to cluster in host list table""" self.click_on_row_child(host_row_num, HostListLocators.HostTable.HostRow.cluster) self.host_popup.wait_and_click_on_cluster_option( cluster_name, HostListLocators.HostTable.cluster_option) @allure.step( 'Assert host in row {row_num} is assigned to cluster {cluster_name}') def assert_host_bonded_to_cluster(self, row_num: int, cluster_name: str): """Assert host in row is assigned to cluster""" def _check_host_cluster(page: HostListPage, row: WebElement): real_cluster = page.find_child( row, HostListLocators.HostTable.HostRow.cluster).text assert real_cluster == cluster_name host_row = self.table.get_row(row_num) wait_until_step_succeeds(_check_host_cluster, timeout=5, period=0.1, page=self, row=host_row) @allure.step('Assert host in row {row_num} has state "{state}"') def assert_host_state(self, row_num: int, state: str): """Assert host in row has state given state""" def _check_host_state(page: HostListPage, row: WebElement): real_state = page.find_child( row, HostListLocators.HostTable.HostRow.state).text assert real_state == state host_row = self.table.get_row(row_num) wait_until_step_succeeds(_check_host_state, timeout=10, period=0.5, page=self, row=host_row) @allure.step('Open host creation popup') def open_host_creation_popup(self): """Open host creation popup""" self.find_and_click(HostListLocators.Tooltip.host_add_btn) self.wait_element_visible(HostCreationLocators.block) @allure.step('Close host creation popup') def close_host_creation_popup(self): """Close popup with `Cancel` button""" self.find_and_click(HostCreationLocators.cancel_btn) @allure.step('Click "Create host" in popup') def click_create_host_in_popup(self): """Click create host button in popup""" self.find_and_click(HostCreationLocators.create_btn) def _insert_new_host_info(self, fqdn: str, cluster: Optional[str] = None): """Insert new host info in fields of opened popup""" self.wait_element_visible(HostCreationLocators.fqdn_input) self.send_text_to_element(HostCreationLocators.fqdn_input, fqdn) if cluster: self._choose_cluster_in_popup(cluster) def _upload_bundle(self, bundle_path: str): """ Add new host provider Popup should be opened Popup is not closed at the end """ provider_section = HostCreationLocators.Provider self.find_and_click(provider_section.add_btn) self.wait_element_visible(provider_section.new_provider_block) self.find_element( provider_section.upload_bundle_btn).send_keys(bundle_path) self.find_and_click(provider_section.new_provider_add_btn) self.wait_element_hide(provider_section.new_provider_block) def _get_hostprovider_name(self) -> str: """Get chosen provider from opened new host popup""" return self.find_element( HostCreationLocators.Provider.chosen_provider).text def _choose_cluster_in_popup(self, cluster_name: str): self.find_and_click(HostCreationLocators.Cluster.cluster_select) option = HostCreationLocators.Cluster.cluster_option self._wait_and_click_on_cluster_option(cluster_name, option) self.wait_element_hide(option) def _wait_and_click_on_cluster_option(self, cluster_name: str, option_locator: Locator): WDW(self.driver, self.default_loc_timeout).until( EC.presence_of_element_located( [option_locator.by, option_locator.value.format(cluster_name)]), message=f"Can't find cluster with name {cluster_name} " f"in dropdown on page {self.driver.current_url} " f"for {self.default_loc_timeout} seconds", ).click()
class ClusterListPage(BasePageObject): """Cluster List Page class""" def __init__(self, driver, base_url): super().__init__(driver, base_url, "/cluster") self.header = PageHeader(self.driver, self.base_url) self.footer = PageFooter(self.driver, self.base_url) self.table = CommonTableObj(self.driver, self.base_url, ClusterListLocators.ClusterTable) @allure.step("Create cluster") def create_cluster(self, bundle: str, description: str = None, is_license: bool = False): """Create cluster""" self.find_and_click(ClusterListLocators.Tooltip.cluster_add_btn) popup = ClusterListLocators.CreateClusterPopup self.wait_element_visible(popup.block) self.find_element(popup.upload_bundle_btn).send_keys(bundle) if description: self.send_text_to_element(popup.description_input, description) self.find_and_click(popup.create_btn) if is_license: self.wait_element_visible(ClusterListLocators.LicensePopup.block) self.find_and_click(ClusterListLocators.LicensePopup.agree_btn) @allure.step("Upload bundle without creating a cluster") def upload_bundle_from_cluster_create_popup(self, bundle: str): """Upload bundle from cluster list page without creating a cluster""" self.find_and_click(ClusterListLocators.Tooltip.cluster_add_btn) popup = ClusterListLocators.CreateClusterPopup self.wait_element_visible(popup.block) self.find_element(popup.upload_bundle_btn).send_keys(bundle) self.find_and_click(popup.cancel_btn) self.wait_element_hide(popup.block) def get_cluster_info_from_row(self, row: int) -> dict: """Get Cluster info from Cluster List row""" row_elements = ClusterListLocators.ClusterTable.ClusterRow cluster_row = self.table.get_all_rows()[row] return { "name": self.find_child(cluster_row, row_elements.name).text, "bundle": self.find_child(cluster_row, row_elements.bundle).text, "description": self.find_child(cluster_row, row_elements.description).text, "state": self.find_child(cluster_row, row_elements.state).text, } @allure.step("Click on action button from row") def click_action_btn_in_row(self, row: WebElement): """Click on Action button from Cluster List row""" self.find_child(row, self.table.locators.ClusterRow.actions).click() @allure.step("Click on import button from row") def click_import_btn_in_row(self, row: WebElement): """Click on Import button from Cluster List row""" self.find_child(row, self.table.locators.ClusterRow.imports).click() @allure.step("Run action {action_name} for cluster from row") def run_action_in_cluster_row(self, row: WebElement, action_name: str): """Run action for cluster from row""" self.click_action_btn_in_row(row) self.wait_element_visible(self.table.locators.ActionPopup.block) self.find_and_click( self.table.locators.ActionPopup.button(action_name)) self.wait_element_visible(ActionDialog.body) self.find_and_click(ActionDialog.run) self.wait_element_hide(ActionDialog.body) @contextmanager def wait_cluster_state_change(self, row: WebElement): """Wait for cluster state to change""" state_before = self.get_cluster_state_from_row(row) yield def _wait_state(): state_after = self.get_cluster_state_from_row(row) assert state_after != state_before assert state_after != self.table.LOADING_STATE_TEXT wait_until_step_succeeds(_wait_state, period=1, timeout=self.default_loc_timeout) def get_cluster_state_from_row(self, row: WebElement): """Get Cluster state from row""" return self.find_child(row, self.table.locators.ClusterRow.state).text @allure.step("Get row by cluster name '{cluster_name}'") def get_row_by_cluster_name(self, cluster_name: str) -> WebElement: """Get Cluster row by cluster name""" rows = self.table.get_all_rows() for row in rows: if self.find_child( row, self.table.locators.ClusterRow.name).text == cluster_name: return row raise AssertionError( f"Cluster '{cluster_name}' not found in table rows") @allure.step("Click on config button from the row") def click_config_button_in_row(self, row: WebElement): """Click on Config button from the row""" self.find_child(row, self.table.locators.ClusterRow.config).click() @allure.step("Click on cluster name from the row") def click_cluster_name_in_row(self, row: WebElement): """Click on Cluster name from the row""" self.find_child(row, self.table.locators.ClusterRow.name).click() @allure.step("Delete cluster by button from the row") def delete_cluster_by_row(self, row: WebElement): """Delete Cluster by button from the row""" self.find_child(row, self.table.locators.ClusterRow.delete_btn).click() self.wait_element_visible(DeleteDialog.body) self.find_and_click(DeleteDialog.yes) self.wait_element_hide(DeleteDialog.body) @allure.step("Click on cluster concern object name from the row") def click_on_concern_by_object_name(self, row: WebElement, concern_object_name: str): """Click on Cluster Concern object name from the row""" self.hover_element( self.find_child(row, self.table.locators.ClusterRow.actions)) self.wait_element_visible(ListConcernPopupLocators.block) for issue in self.find_elements( ListConcernPopupLocators.link_to_concern_object): if concern_object_name in issue.text: issue.click() return raise AssertionError( f"Issue name '{concern_object_name}' not found in row issues")