def __set_table_name(self, session): SAPGuiElements.set_text(session, TABLENAME_FIELD, self.table_name) SAPGuiElements.press_keyboard_keys(session, "Enter") gui_msg = SAPGuiElements.get_status_message(session) if gui_msg: if gui_msg[1] == "402": msg = "Table '{0}' not found. GUI Message: {1}".format(self.table_name, gui_msg) raise ValueError(msg) elif gui_msg[1] == "419": msg = "Not authorized to view the '{0}' table. GUI Message: {1}".format(self.table_name, gui_msg[2]) raise PermissionError(msg)
def __set_report_and_execute(self, sap_session): SAPGuiElements.set_text(sap_session, PROGRAM_FIELD, self.report_name) SAPGuiElements.press_keyboard_keys(sap_session, "F8") gui_msg = SAPGuiElements.get_status_message(sap_session) if gui_msg: if gui_msg[1] == "017": msg = "Wrong report name '{0}'. GUI Message: {1}".format(self.report_name, gui_msg[2]) raise ValueError(msg) elif gui_msg[1] == "322": msg = "Not authorized to execute '{0}' report. GUI Message: {1}".format(self.report_name, gui_msg[2]) raise PermissionError(msg)
def save_to_file(self, sap_session=None): if not sap_session: sap_session = self.sap_session SAPGuiElements.press_keyboard_keys(sap_session, "Ctrl+Shift+F9") if self.file_format == 'html': SAPGuiElements.select_element(sap_session, HTML_FORMAT) filename = self.__get_filename() SAPGuiElements.press_button(sap_session, CONFIRM_FORMAT_BUTTON) SAPGuiElements.set_text(sap_session, PATH_TEXT_FIELD, self.report_dir) SAPGuiElements.set_text(sap_session, FILENAME_TEXT_FIELD, filename) SAPGuiElements.press_button(sap_session, REPLACE_BUTTON) self.__del_gif_files() return filename
def create_new_session(sid, user, pwd, client=None, langu=None, close_conn=False, change_pwd=True): conn_descr = SAPLogonINI.get_connect_name_by_sid(sid) if not conn_descr: raise ValueError("Connection to '{0}' not found".format(sid)) sap_session = SAPNewSession.get_new_session_by_name(conn_descr) if sap_session: if user: SAPGuiElements.set_text(sap_session, USERNAME_FIELD, user) if pwd: SAPGuiElements.set_text(sap_session, PASSWORD_FIELD, pwd) if client: SAPGuiElements.set_text(sap_session, CLIENT_FIELD, client) if langu: SAPGuiElements.set_text(sap_session, LANGUAGE_FIELD, langu) SAPGuiElements.press_keyboard_keys(sap_session, "Enter") msg = SAPGuiElements.get_status_message(sap_session) if msg and msg[0] == "E": SAPGuiElements.press_keyboard_keys(sap_session, "Shift+F3") raise RuntimeError("Could not log to the SAP server. {0}".format(msg[2])) SAPNewSession.is_already_logon_window(sap_session) return_pwd = SAPLogonPwd.is_change_password_window_while_connect(sap_session, change_pwd=change_pwd) SAPNewSession.close_new_windows_while_connect(sap_session) if close_conn: SAPExistedSession.close_session(sap_session) return return_pwd
def __call_transaction(sap_session, transaction, window_id=pysapgui.sapgui.GUI_MAIN_WINDOW, check_error=True): tcode = TRANSACTION_PREFIX + transaction SAPGuiElements.set_text(sap_session, TRANSACTION_TEXT_FIELD.format(window=window_id), tcode) SAPGuiElements.press_keyboard_keys(sap_session, "Enter") if not check_error: return gui_msg = SAPGuiElements.get_status_message(sap_session) if gui_msg: if gui_msg[1] == "343": msg = "Wrong transaction name '{0}'. GUI Message: {1}".format(transaction, gui_msg[2]) raise ValueError(msg) elif gui_msg[1] == "077": msg = "Not authorized to execute '{0}' transaction. GUI Message: {1}".format(transaction, gui_msg[2]) raise PermissionError(msg) elif gui_msg[1] == "410": msg = "Blocked action in '{0}' transaction. GUI Message: {1}".format(transaction, gui_msg[2]) raise PermissionError(msg)
def change_password_su3(sap_session, old_pwd): SAPTransaction.call(sap_session, CHANGE_PASSWORD_TRANSACTION) new_pwd = SAPLogonPwd.gen_password() SAPGuiElements.press_button(sap_session, CHNAGE_PWD_BUTTON_SU3) msg = SAPGuiElements.get_status_message(sap_session) if msg: if msg[1] in ('190', '180'): raise RuntimeError("Password could not be changed. {0}".format( msg[2])) try: SAPGuiElements.set_text(sap_session, OLD_PWD_FIELD, old_pwd) SAPGuiElements.set_text(sap_session, NEW_PWD_FIELD1, new_pwd) SAPGuiElements.set_text(sap_session, NEW_PWD_FIELD2, new_pwd) SAPGuiElements.press_keyboard_keys( sap_session, "Enter", pysapgui.sapgui.GUI_CHILD_WINDOW1) except AttributeError as error: raise AttributeError( "Could not find GUI elements to change password. {0}".format( str(error))) try: SAPGuiElements.get_element(sap_session, pysapgui.sapgui.GUI_CHILD_WINDOW2) SAPGuiElements.press_keyboard_keys( sap_session, "Enter", pysapgui.sapgui.GUI_CHILD_WINDOW2) SAPGuiElements.press_keyboard_keys( sap_session, "F12", pysapgui.sapgui.GUI_CHILD_WINDOW1) except AttributeError: # All is Ok. Password changed successfully return new_pwd else: raise AttributeError( "Couldn't set new password. Reconfigure password policy")
def __change_password_login(sap_session): new_pwd = SAPLogonPwd.gen_password() try: SAPGuiElements.set_text(sap_session, CHANGE_PWD_FIELD1, new_pwd) SAPGuiElements.set_text(sap_session, CHANGE_PWD_FIELD2, new_pwd) SAPGuiElements.press_keyboard_keys( sap_session, "Enter", pysapgui.sapgui.GUI_CHILD_WINDOW1) except AttributeError as error: raise AttributeError( "Could not find GUI elements to change password. {0}".format( str(error))) try: SAPGuiElements.get_element(sap_session, pysapgui.sapgui.GUI_CHILD_WINDOW2) except AttributeError: # All is Ok. Password changed pass else: raise AttributeError( "Couldn't set new password. Reconfigure password policy") return new_pwd
def __set_param_name_and_execute(self, sap_session): SAPGuiElements.set_text(sap_session, PARAM_NAME_FIELD, self.param_name) SAPGuiElements.press_keyboard_keys(sap_session, "F8")