def stem_impl(context, type, property_type, expected_value): AXRole = MacUIUtils.normalize_role(type) AXProperty = MacUIUtils.normalize_property(property_type) kwargs = {} kwargs['AXRole'] = AXRole kwargs[AXProperty] = expected_value obj = MacUIUtils.wait_element(context.current_window, kwargs) (obj is not None).should.be(True)
def get_summary_table(self): summary_table = MacUIUtils.get_table_cells(self.tb_summary) dict = {} for row in summary_table: key = row[0] value = row[1] dict[key] = value return dict
def wait_restore_finished(timeout=300, recheck_time=2): """ wait restore to be finished :param timeout: wait_time :param recheck_time: sleep time :return: Boolean """ LogHelper.info('wait restore to be finished') result = False import atomac app = atomac.getAppRefByBundleId('com.mozy.restoremanager') sa = None try: sa = atomac.getAppRefByBundleId('com.apple.SecurityAgent') except ValueError: LogHelper.info("Security Agent is not found") sa = None is_restore_complete = MacUIUtils.is_element_exist(app, AXRole='AXStaticText', AXValue='Complete:') restore_time = 0 while (not is_restore_complete) and restore_time <= timeout: LogHelper.info("restore is not completed") if sa: sa_exist = MacUIUtils.is_element_exist(sa, AXRole='AXButton', AXTitle='Cancel') else: sa_exist = False if sa_exist: LogHelper.info("Cancel Security Agent") MacUIUtils.click_button(sa_exist) time.sleep(recheck_time) restore_time += recheck_time is_restore_complete = MacUIUtils.is_element_exist(app, AXRole='AXStaticText', AXValue='Complete:') if is_restore_complete: LogHelper.info("Restore completed, retsore take %d" % restore_time) result = True if restore_time >= timeout: LogHelper.error("Restore is not completed in %d second!" % timeout) return result
def enter_passoword(self, password): """ :param username: :param password: :return: """ MacUIUtils.mouse_click_center(self.elements[0].root(wait_time=60)) obj = self.tf_password if obj: obj.activate() MacUIUtils.make_focus(self.tf_password) MacUIUtils.input_text(self.tf_password, password) MacUIUtils.click_button(self.btn_continue) else: print("NO password window show")
def launch_mozy_application(): """ launch app :return: """ bundleId = MacController().spbundleid WindowName = 'MozyPro' try: atomac.launchAppByBundleId(bundleId) except RuntimeError as e: print e.message mozy_window = None app = atomac.getAppRefByBundleId(bundleId) window = MacUIUtils.wait_element(app, AXRole='AXWindow') app.activate() btn_showall = MacUIUtils.wait_element(window, AXRole='AXButton', AXTitle='Show All') MacUIUtils.click_button(btn_showall) window = MacUIUtils.wait_element(app, AXRole='AXWindow') title = window.AXTitle if title == 'MozyPro': # it is already mozy window mozy_window = window elif title == "System Preferences": btn_mozypro = MacUIUtils.wait_element(app, AXRole='AXButton', AXTitle=WindowName) btn_mozypro.Press() mozy_window = MacUIUtils.wait_element(app, AXRole='AXWindow', AXTitle=WindowName) else: raise Exception('Not implemented yet') if mozy_window.AXRole: MacMozyUIBase.mozy_window = mozy_window return mozy_window else: return False
def start_mac_mozy(self): """ launch app :return: """ import atomac from apps.mac.mac_lib.mac_ui_util import MacUIUtils bundleId = MacController().spbundleid WindowName = 'MozyPro' try: atomac.launchAppByBundleId(bundleId) except RuntimeError as e: print e.message app = atomac.getAppRefByBundleId(bundleId) app.activate() window = MacUIUtils.wait_element(app, AXRole='AXWindow') btn_showall = MacUIUtils.wait_element(window, AXRole='AXButton', AXTitle='Show All') MacUIUtils.click_button(btn_showall) title = window.AXTitle if title == 'MozyPro': # it is already mozy window mozy_window = window elif title == "System Preferences": btn_mozypro = MacUIUtils.wait_element(app, AXRole='AXButton', AXTitle=WindowName) btn_mozypro.Press() mozy_window = MacUIUtils.wait_element(app, AXRole='AXWindow', AXTitle=WindowName) return mozy_window
def click_restore_button(self): MacUIUtils.click_button(self.btn_restore)
def add_new_machine(self): MacUIUtils.click_radio_button(self.rd_add) MacUIUtils.click_button(self.rd_next)
def activate_with_pk(self): MacUIUtils.click_radio_button(self.rd_personalkey) MacUIUtils.click_button(self.btn_next)
def click_backup(self): button_handle = self.btn_backupnow MacUIUtils.click_button(button_handle)
def click_macintosh(self): root = MacUIUtils.get_root_volume_name() MacUIUtils.click_popmenu_item_by_value(self.pm_root, root)
def close(self): MacUIUtils.click_button(self.btn_close)
def restore_root(self): root_handle = MacUIUtils.wait_element(self.browser_restore, AXRole='AXStaticText') node_name = root_handle.AXValue self.restore_entity(node_name)
def show_suggested_backup_sets(self): handle = self.btn_menu_add MacUIUtils.click_popmenu_item_by_value(handle, "Suggested File/Folder...")
def show_add_files_browser(self): handle = self.btn_menu_add MacUIUtils.click_popmenu_item_by_value(handle, "File/Folder...")
def click_advance_button(self): MacUIUtils.click_button(self.btn_advanced)
def visit(self): MacUIUtils.click_button(self.tab_files)
def run_mzd_restore(cls, dest, personal_key=None, index=-1): """ select mzd reuqest to restore files :param dest: restore file destination, dertermine to root config and dest :param personal_key: personal key, if not None, input personal key during restore process :param index: mzd list :return: Boolean. if restore complete, true. otherwise false """ output_path = ConfigAdapter.get_output_path() output_path = os.path.join(output_path, dest) if FileHelper.dir_exist(output_path): FileHelper.delete_directory(output_path) FileHelper.create_directory(output_path) cmd = MacFryR_Controller.prefix_for_sudo() + 'sudo -S chmod -R 777 "{path}"'.format(path=output_path) CmdHelper.run(cmd) LogHelper.info('Select %s to generate mzd request' % output_path) try: LogHelper.info("Multiple restore jobs found, automation will select the latest job to do the restore.") MacFryrElement({'AXRole': 'AXRow'}, index, 10).left_click() MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:29'}).click() except: LogHelper.info("Only one restore job found, automation will do restore with the default job.") MacFryrElement({'AXRole': 'AXRadioButton', 'AXDescription': 'selectNewLocationRadio'}, wait_time=5).click() time.sleep(2) root = MacUIUtils.get_root_volume_name() pop_menu = MacFryrElement({'AXRole': 'AXPopUpButton'}, 0, 10).element app = pop_menu.getApplication() MacUIUtils.click_popmenu_item_by_value(pop_menu, root) browser_window = MacUIUtils.wait_element(app, AXRole='AXWindow', AXTitle='Open') browser_handle = MacUIUtils.wait_element(browser_window, AXRole='AXBrowser') MacUIUtils.select_nodes(browser_handle, output_path, node_matcher='AXTextField') # MacFryrElement({'AXTitle': 'New Folder'}).click() # MacFryrElement({'AXIdentifier': '_NS:43'}, 0, 5).send_keys(dest) # MacFryrElement({'AXIdentifier': '_NS:53'}).click() btn_open = MacUIUtils.wait_element(browser_window, AXRole='AXButton', AXTitle='Open') MacUIUtils.click_button(btn_open) MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:29'}).click() if personal_key: LogHelper.info('input personal key %s' % personal_key) el = MacUIUtils.wait_element(app, timeout=120, AXRole='AXTextField', AXDescription='privateKeyField') MacUIUtils.input_text(el, personal_key) LogHelper.info('click next button') btn_next = MacFryrElement({'AXRole': 'AXButton', 'AXTitle': 'Next'}) btn_next.click() MacFryrElement({'AXRole': 'AXButton', 'AXIdentifier': '_NS:29'}).click() time.sleep(3) from apps.mac.mac_gui_installer.mac_gui_installer import AppUIElement try: textbox_psd = AppUIElement.from_bundle('com.apple.SecurityAgent', {'AXRole': 'AXTextField', 'AXSubrole': 'AXSecureTextField'}, 0, 10) except ValueError: LogHelper.info("Security Agent is not found") textbox_psd = None if textbox_psd and textbox_psd.element: password = MAC_CONFIG.get("LOCAL_ADMIN_PASSWORD") textbox_psd.send_keys(password) time.sleep(1) btn_ok = AppUIElement.from_bundle('com.apple.SecurityAgent', {'AXRole': 'AXButton', 'AXTitle': 'OK'}) btn_ok.left_click() time.sleep(1) cls.wait_restore_finished()
def visit(self): MacUIUtils.click_radio_button(self.rd_summary)
def click_browse_button(self): MacUIUtils.click_button(self.btn_browse)
def restore_last_backup(self): MacUIUtils.click_popmenu_item_by_index(self.pm_backupdate, index=2) self.restore_root() self.close()
def select_root_dest(self): rg_buttons = self.rg_buttons MacUIUtils.click_button(self.rg_buttons.AXChildren[2]) MacUIUtils.click_popmenu_item_by_value( self.pb_root, MacUIUtils.get_root_volume_name())
def restore_entity(self, entity_name): MacUIUtils.select_nodes(self.browser_restore, entity_name) self.btn_restore.Press() self.wait_restore_finished()
def activate(self, username, password, **kwargs): """ :param username: :param password: :return: """ self.set_credential_with(username, password) sh_select_encryption = SelectEncryptionTypeSheet() if sh_select_encryption.rd_mozykey: sh_select_encryption.activate_with_mozykey() add_machine_sh = AddReplaceMachineSheet() if add_machine_sh.rd_add: add_machine_sh.add_new_machine() if kwargs.get('keytext'): text = kwargs['keytext'] is_pkey = self.ta_pkey if is_pkey: MacUIUtils.input_text(is_pkey, text) MacUIUtils.wait_enabled(self.btn_pknext, timeout=60) MacUIUtils.click_button(self.btn_pknext) save_dialog = Personal_Key_Dialog() MacUIUtils.click_button(save_dialog.btn_cancel) MacUIUtils.click_checkbox(self.cb_pk, check=True) MacUIUtils.click_button(self.btn_pknext) MacUIUtils.click_button(self.btn_preferences)
def select_destination(self, dest): self.click_macintosh() MacUIUtils.select_nodes(self.browser_open, dest, 'AXTextField') MacUIUtils.click_button(self.btn_choose)
def activate_with_mozykey(self): MacUIUtils.click_radio_button(self.rd_mozykey) MacUIUtils.click_button(self.btn_next)
def select_backupdir(self, tree): MacUIUtils.select_nodes(self.browser_open, tree, 'AXTextField') MacUIUtils.click_button(self.btn_add)
def get_title_btn_backup(self): button = self.btn_backupnow return MacUIUtils.get_element_title(button)
def click_OK_button(self): MacUIUtils.click_button(self.btn_OK)
def set_credential_with(self, username, password): MacUIUtils.mouse_click_center(self.tf_email) MacUIUtils.empty_text(self.tf_email) MacUIUtils.input_text(self.tf_email, username) MacUIUtils.empty_text(self.tf_password) MacUIUtils.input_text(self.tf_password, password) MacUIUtils.click_button(self.btn_next)