1"""Account pages associated with Fitbit Companion App testing.""" 2from typing import List 3 4from blueberry.utils.ui_pages import ui_core 5from blueberry.utils.ui_pages import ui_node 6from blueberry.utils.ui_pages.fitbit_companion import constants 7 8 9class AccountPage(ui_core.UIPage): 10 """Fitbit Companion App's account page.""" 11 12 ACTIVITY = f'{constants.PKG_NAME}/com.fitbit.settings.ui.AccountActivity' 13 PAGE_RID = f'{constants.PKG_NAME_ID}/account_recycler' 14 NODE_UER_AVATOR_RID = f'{constants.PKG_NAME_ID}/userAvatar' 15 NODE_BACK_CONTENT_DESC = 'Navigate up' 16 NODE_ADD_DEV_RID = f'{constants.PKG_NAME_ID}/add_device_img' 17 NODE_DEVICE_RID = f'{constants.PKG_NAME_ID}/device_name' 18 19 def add_device(self) -> ui_core.UIPage: 20 """Goes to page to add new device. 21 22 Returns: 23 The transformed page. 24 25 Raises: 26 errors.UIError: Fail to get the target node. 27 """ 28 return self.click_node_by_rid(self.NODE_ADD_DEV_RID) 29 30 def back(self) -> ui_core.UIPage: 31 """Goes back to Fitbit Companion App's home page. 32 33 Returns: 34 The transformed page. 35 36 Raises: 37 errors.UIError: Fail to get target node. 38 """ 39 return self.click_node_by_content_desc(self.NODE_BACK_CONTENT_DESC) 40 41 def get_paired_devices(self) -> List[ui_node.UINode]: 42 """Gets all paired devices. 43 44 Returns: 45 The list of node representing the paired device. 46 """ 47 return self.get_all_nodes_by_rid(self.NODE_DEVICE_RID) 48 49 50class PairedDeviceDetailPage(ui_core.UIPage): 51 """Fitbit Companion App's page of paired device.""" 52 53 PAGE_RID = f'{constants.PKG_NAME_ID}/unpair' 54 55 def unpair(self) -> ui_core.UIPage: 56 """Unpairs device. 57 58 Returns: 59 The transformed page. 60 61 Raises: 62 errors.UIError: Fail to find the target node. 63 """ 64 # TODO(user): We need to consider the situation while device 65 # sync now which cause unpair to fail. 66 return self.click_node_by_rid(self.PAGE_RID) 67 68 69class UnpairConfirmPage(ui_core.UIPage): 70 """Fitbit Companion App's page to confirm the action of unpairing.""" 71 72 PAGE_TEXT = 'UNPAIR' 73 74 def confirm(self) -> ui_core.UIPage: 75 """Confirms the action of unpairing. 76 77 Returns: 78 The transformed page. 79 """ 80 self.click_node_by_text(self.PAGE_TEXT) 81 self.ctx.expect_page(AccountPage) 82 return self.ctx.page 83