How to use close_all_applications method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

import_export_map_texts.py

Source:import_export_map_texts.py Github

copy

Full Screen

...39 win.send_keys("%n")40 time.sleep(1)41 win.send_keys_to_input("\"" + fn.replace(" ", "{SPACE}").replace("(", "{(}").replace(")", "{)}").replace(".h3m", ".txt") + "\"", send_delay=1, enter_delay=1)42 time.sleep(3)43 win.close_all_applications()444546 win.open_executable("C:/HoMM3/h3hota_maped.exe", "Map Editor", wildcard=True)47 for dirpath,dirs,files in os.walk("C:/original_maps"):48 for f in files:49 if f.lower().endswith(".h3m"):50 hota = 051 if f.lower().startswith("[hota]") : hota = 15253 fn = os.path.join(dirpath, f).replace("/", "\\")5455 if hota == 1:56 win.menu_select("File->Open...")57 win.send_keys("%n")58 time.sleep(0.2)59 win.send_keys_to_input("\"" + fn.replace(" ", "{SPACE}") + "\"", send_delay=0.2)60 win.menu_select("File->Export Text...")61 win.send_keys("%n")62 time.sleep(0.2)63 win.send_keys_to_input("\"" + fn.replace(" ", "{SPACE}").replace(".h3m", ".txt") + "\"", send_delay=0.2)64 win.close_all_applications()6566if mode == "IMPORT":67 #import68 win = Windows()6970 win.open_executable("C:/HoMM3/h3maped.exe", "Map Editor", wildcard=True)71 for dirpath,dirs,files in os.walk("C:/original_maps"):72 for f in files:73 fn = os.path.join(dirpath, f).replace("/", "\\")74 fn_map = os.path.join(dirpath, f).replace("/", "\\").replace(".translated", ".h3m")75 fn_new = os.path.join(dirpath + "/out", f).replace("/", "\\").replace(".translated", ".h3m")7677 if f.lower().endswith(".translated") and not os.path.isfile(fn_new):78 hota = 079 if f.lower().startswith("[hota]") : hota = 18081 if hota == 0:82 while True:83 try:84 win.menu_select("File->Open...")85 break86 except:87 time.sleep(2)88 win.send_keys("%s")89 win.send_keys("%n")90 time.sleep(1)91 win.send_keys_to_input("\"" + fn_map.replace(" ", "{SPACE}").replace("(", "{(}").replace(")", "{)}") + "\"", send_delay=1, enter_delay=1)92 time.sleep(3)93 while True:94 try:95 win.menu_select("File->Import Text...")96 break97 except:98 time.sleep(2)99 win.send_keys("%f")100 win.send_keys("%n")101 time.sleep(1)102 win.send_keys_to_input("\"" + fn.replace(" ", "{SPACE}").replace("(", "{(}").replace(")", "{)}") + "\"", send_delay=1, enter_delay=1)103 try:104 win.find_element("partial name:Successfully")105 win.send_keys("{ENTER}")106 except:107 print(fn_new)108 win.send_keys("{ENTER}")109 continue110 time.sleep(3)111 while True:112 try:113 win.menu_select("File->Save As...")114 break115 except:116 time.sleep(2)117 win.send_keys("%f")118 win.send_keys("%n")119 time.sleep(1)120 win.send_keys_to_input("\"" + fn_new.replace(" ", "{SPACE}").replace("(", "{(}").replace(")", "{)}") + "\"", send_delay=1, enter_delay=1)121 time.sleep(3)122 win.close_all_applications()123124125 win.open_executable("C:/HoMM3/h3hota_maped.exe", "Map Editor", wildcard=True)126 for dirpath,dirs,files in os.walk("C:/original_maps"):127 for f in files:128 fn = os.path.join(dirpath, f).replace("/", "\\")129 fn_map = os.path.join(dirpath, f).replace("/", "\\").replace(".translated", ".h3m")130 fn_new = os.path.join(dirpath + "/out", f).replace("/", "\\").replace(".translated", ".h3m")131132 if f.lower().endswith(".translated") and not os.path.isfile(fn_new):133 hota = 0134 if f.lower().startswith("[hota]") : hota = 1135136 if hota == 1:137 while True:138 try:139 win.menu_select("File->Open...")140 break141 except:142 time.sleep(2)143 win.send_keys("%s")144 win.send_keys("%n")145 time.sleep(1)146 win.send_keys_to_input("\"" + fn_map.replace(" ", "{SPACE}").replace("(", "{(}").replace(")", "{)}") + "\"", send_delay=1, enter_delay=1)147 time.sleep(3)148 while True:149 try:150 win.menu_select("File->Import Text...")151 break152 except:153 time.sleep(2)154 win.send_keys("%f")155 win.send_keys("%n")156 time.sleep(1)157 win.send_keys_to_input("\"" + fn.replace(" ", "{SPACE}").replace("(", "{(}").replace(")", "{)}") + "\"", send_delay=1, enter_delay=1)158 try:159 win.find_element("partial name:Successfully")160 win.send_keys("{ENTER}")161 except:162 print(fn_new)163 win.send_keys("{ENTER}")164 continue165 time.sleep(3)166 while True:167 try:168 win.menu_select("File->Save As...")169 break170 except:171 time.sleep(2)172 win.send_keys("%f")173 win.send_keys("%n")174 time.sleep(1)175 win.send_keys_to_input("\"" + fn_new.replace(" ", "{SPACE}").replace("(", "{(}").replace(")", "{)}") + "\"", send_delay=1, enter_delay=1)176 time.sleep(3)177 win.close_all_applications()178 ...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...30 robot_order.accept_terms()31 return robot_order32def kill_all_applications( config, robot_order ):33 robot_order.close_browser()34def close_all_applications( config, robot_order ):35 LOGGER.info('Closing all applications')36 robot_order.close_page()37def get_transaction_data( config ):38 LOGGER.info('Fetching transaction data')39 http = HTTP()40 tables = Tables()41 http.download(url = 'https://robotsparebinindustries.com/orders.csv', target_file='data\orders.csv', overwrite=True)42 transaction_data = tables.read_table_from_csv('data\orders.csv', header = True, delimiters=',')43 return transaction_data44def get_transaction_item( config, transaction_data: Tables, transaction_number: int):45 LOGGER.info('Fetching next transaction')46 if transaction_number >= len( transaction_data ):47 return None48 49 return transaction_data[transaction_number]50 51def process( config, transaction_item, transaction_number, robot_order ):52 LOGGER.info(f'Processing transaction number: {transaction_number}')53 #Process variables54 folder_temp = os.path.join(os.getcwd(), 'temp')55 folder_output = os.path.join(os.getcwd(), 'output', 'receipts')56 filename_temp_text = os.path.join(folder_temp, 'text{}.pdf'.format(transaction_number))57 filename_temp_image = os.path.join(folder_temp, 'image{}.png'.format(transaction_number))58 filename_output = os.path.join(folder_output, 'output{}.pdf'.format(transaction_number))59 pdf = PDF()60 file_system = FileSystem()61 #Process steps62 robot_order.new_order(str(transaction_item[1]), 63 str(transaction_item[2]), 64 str(transaction_item[3]), 65 str(transaction_item[4]))66 robot_order.preview()67 robot_order.order()68 receipt = robot_order.get_receipt_as_html()69 pdf.html_to_pdf(content = receipt, output_path= filename_temp_text)70 file_system.wait_until_created(filename_temp_text)71 robot_order.download_robot_preview(filename_temp_image)72 file_system.wait_until_created(filename_temp_image)73 pdf.add_watermark_image_to_pdf(image_path=filename_temp_image,74 output_path=filename_output, 75 source_path=filename_temp_text)76 file_system.wait_until_created(filename_output)77 robot_order.order_another_robot()78 robot_order.accept_terms()79 80 for f in os.listdir(folder_temp):81 file_to_remove = os.path.join(folder_temp, f)82 try:83 file_system.remove_file(file_to_remove)84 file_system.wait_until_removed(file_to_remove)85 except Exception as e:86 LOGGER.warning(f'Failed to remove {f}. Reason: {str(e)}')87 88def init_all_settings():89 LOGGER.info('Initializing settings')90 config = {}91 _secrets = []92 with open("data\config.json", 'r') as f:93 local_config = json.load(f)94 for k,v in local_config['settings'].items():95 config[k] = v96 for k,v in local_config['framework'].items():97 config[k] = v98 try:99 for s in local_config['secrets']:100 secret = Vault().get_secret(s)101 _secrets.append(secret)102 except Exception as e:103 LOGGER.warning(f'Failed to fetch secrets: {str(e)}')104 return config, _secrets105def get_user_input():106 try:107 dialogs = Dialogs()108 dialogs.add_text("What do you want to call the output?")109 dialogs.add_text_input(name='file_name', label='Output name')110 user_input = dialogs.run_dialog(title='Provide a name for the output plz', width=400, height=500)111 except Exception as e:112 LOGGER.warning('Unable to get user input, setting it to default. Reason: ' + str(e))113 user_input = {114 "file_name" : "default"115 }116 finally:117 dialogs.close_all_dialogs()118 return user_input119if __name__ == "__main__":120 config = init_all_settings()121 LOGGER.info('Starting')122 123 # Set global variables124 config = {}125 transaction_number = 0126 transactions_remain = True127 max_retries = 5128 retry_number = 0129 restart_needed = False130 # Declare all windows / Systems in scope.131 robot_order = None132 # GET USER INPUT133 user_input = get_user_input()134 # INIT 135 #config, _secrets = init_all_settings()136 robot_order = init_all_applications( config ) # Returns all application objects137 transaction_data = get_transaction_data( config )138 while transactions_remain:139 140 # GET TRANSACTION ITEMS141 try:142 transaction_item = get_transaction_item(config, transaction_data, transaction_number)143 except Exception as e:144 LOGGER.exception('Failed to get transaction item: ' + str(e))145 transaction_number += 1146 continue147 148 if transaction_item == None:149 break150 if restart_needed:151 robot_order = init_all_applications( config )152 # PROCESS TRANSACTION153 try:154 process( config, transaction_item, transaction_number, robot_order )155 restart_needed = False156 transaction_number += 1157 except Exception as e:158 LOGGER.warning('Transaction Exception: ' + str(e))159 try:160 close_all_applications( config, robot_order )161 except Exception:162 LOGGER.warning('Failed to close all applications: ' + str(e) )163 kill_all_applications( config, robot_order )164 finally:165 restart_needed = True166 retry_number += 1167 if retry_number < max_retries:168 LOGGER.info('Retrying transaction')169 else:170 retry_number = 0171 transaction_number += 1172 173 # WRAP UP / TEARDOWN174 try:175 close_all_applications( config, robot_order )176 except Exception as e:177 LOGGER.exception('Failed to close all applications: ' + str(e) )178 kill_all_applications( config, robot_order )179 try: 180 archive = Archive()181 archive.archive_folder_with_zip(os.path.join(os.getcwd(), 'output', 'receipts'), 182 os.path.join(os.getcwd(), 'output', user_input['file_name'] + '.zip'))183 except Exception as e:184 LOGGER.warning(f'Failed to archive receipts: {str(e)}')185 186 finally:187 try:188 for f in os.listdir(os.path.join(os.getcwd(), 'output', 'receipts')):189 file_to_remove = os.path.join(os.path.join(os.getcwd(), 'output', 'receipts'), f)...

Full Screen

Full Screen

demo_desktop.py

Source:demo_desktop.py Github

copy

Full Screen

...46 open_calculator()47 exp = '5*2='48 result = make_calculations(exp)49 print(f"Calculation result of '{exp}' is '{result}'")50 win.close_all_applications()51def TeamViewer():52 open_teamviewer()53 connect_button()54 #win.close_all_applications()55if __name__ == "__main__":56 #TeamViewer()57 #calcular()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful