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 close_new_windows_while_connect(sap_session): max_windows = 10 try: for i in range(0, max_windows): SAPGuiElements.get_element(sap_session, pysapgui.sapgui.GUI_CHILD_WINDOW1) SAPGuiElements.press_keyboard_keys(sap_session, "Enter", pysapgui.sapgui.GUI_CHILD_WINDOW1) except AttributeError: pass
def is_change_password_window_while_connect(sap_session, change_pwd=True): try: SAPGuiElements.get_element(sap_session, CHANGE_PWD_FIELD1) SAPGuiElements.get_element(sap_session, CHANGE_PWD_FIELD2) except AttributeError: # All is Ok. No need to change password pass else: if change_pwd: SAPLogonPwd.__change_password_login(sap_session) else: SAPGuiElements.press_keyboard_keys( sap_session, "F12", pysapgui.sapgui.GUI_CHILD_WINDOW1) raise RuntimeError('Change password to the SAP user')
def is_already_logon_window(sap_session): try: select = SAPGuiElements.get_element(sap_session, MULTI_USER_DISCONNECT) except AttributeError: pass else: SAPGuiElements.select_element(sap_session, select.id) SAPGuiElements.press_keyboard_keys(sap_session, "Enter", pysapgui.sapgui.GUI_CHILD_WINDOW1)
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