How to use start_reboot method in autotest

Best Python code snippet using autotest_python

view.py

Source:view.py Github

copy

Full Screen

1################################################2# File: view.py #3# #4# Author(s): { #5# Hifumi1337 <https://github.com/Hifumi1337> #6# } #7################################################8import tkinter, customtkinter, platform, time, json9from tkinter import PhotoImage, messagebox10from subprocess import getoutput11from os.path import getsize, exists12if platform.system() == 'Darwin':13 adb = "$HOME/Library/Android/sdk/platform-tools/adb"14elif platform.system() == 'Windows':15 adb = "%LOCALAPPDATA%\Android\sdk\platform-tools\\adb"16elif platform.system() == 'Linux':17 whoami = getoutput("whoami")18 adb = f"/home/{whoami}/Android/Sdk/platform-tools/adb"19if platform.system() == 'Darwin':20 import sys, os21 22 def import_resources(relative_path):23 try:24 base_path = sys._MEIPASS25 except Exception:26 base_path = os.path.abspath(".")27 return os.path.join(base_path, relative_path)28INFO_CODE = "[INFO]"29class View(customtkinter.CTk):30 def __init__(self, version):31 super().__init__()32 self.title(f"Droid | v{version}")33 self.geometry("1400x750")34 self.set_appearance_mode("Dark")35 self.grid_columnconfigure(1, weight=1)36 self.grid_rowconfigure(0, weight=1)37 if platform.system() == 'Darwin':38 img = PhotoImage(file=f"{import_resources('assets/droid.png')}")39 self.iconphoto(True, img)40 # Sidebar41 self.frame_left = customtkinter.CTkFrame(master=self, width=200, corner_radius=0)42 self.frame_left.grid(row=0, column=0, sticky="nswe")43 self.frame_middle = customtkinter.CTkFrame(master=self)44 self.frame_middle.grid(row=0, column=1, sticky="nswe", padx=20, pady=20)45 self.frame_right = customtkinter.CTkFrame(master=self)46 self.frame_right.grid(row=0, column=2, sticky="nswe", padx=20, pady=20)47 self.header = customtkinter.CTkLabel(master=self.frame_left, text=f"Droid | v{version}", text_font=("Roboto Medium", -18)) 48 self.header.grid(row=1, column=0, pady=10, padx=10)49 self.connect_ip_addr = customtkinter.CTkButton(master=self.frame_left, text="Connect", command=self.btn_connect)50 self.connect_ip_addr.grid(row=2, column=0, pady=10, padx=20)51 self.disconnect_ip_addr = customtkinter.CTkButton(master=self.frame_left, text="Disconnect", command=self.btn_disconnect)52 self.disconnect_ip_addr.grid(row=3, column=0, pady=10, padx=20)53 self.reboot_android = customtkinter.CTkButton(master=self.frame_left, text="Reboot", command=self.btn_reboot)54 self.reboot_android.grid(row=4, column=0, pady=10, padx=20)55 self.screenshot_android = customtkinter.CTkButton(master=self.frame_left, text="Screenshot", command=self.btn_screenshot)56 self.screenshot_android.grid(row=5, column=0, pady=10, padx=20)57 self.download_android = customtkinter.CTkButton(master=self.frame_left, text="Download File", command=self.btn_download_file)58 self.download_android.grid(row=6, column=0, pady=10, padx=20)59 self.upload_android = customtkinter.CTkButton(master=self.frame_left, text="Upload File", command=self.btn_upload_file)60 self.upload_android.grid(row=7, column=0, pady=10, padx=20)61 self.file_modifier = customtkinter.CTkButton(master=self.frame_left, text="Modify", command=self.btn_modify_file)62 self.file_modifier.grid(row=8, column=0, pady=10, padx=20)63 self.upload_apk = customtkinter.CTkButton(master=self.frame_left, text="Upload APK", command=self.btn_upload_apk)64 self.upload_apk.grid(row=9, column=0, pady=10, padx=20)65 self.remove_apk = customtkinter.CTkButton(master=self.frame_left, text="Remove APK", command=self.btn_remove_apk)66 self.remove_apk.grid(row=10, column=0, pady=10, padx=20)67 self.set_bluetooth_status = customtkinter.CTkButton(master=self.frame_left, text="Bluetooth", command=self.btn_bluetooth)68 self.set_bluetooth_status.grid(row=11, column=0, pady=10, padx=20)69 self.set_wifi_status = customtkinter.CTkButton(master=self.frame_left, text="Wifi", command=self.btn_wifi)70 self.set_wifi_status.grid(row=12, column=0, pady=10, padx=20)71 self.close_app = customtkinter.CTkButton(master=self.frame_left, text="Close Droid", command=self.btn_destroy)72 self.close_app.grid(row=13, column=0, pady=10, padx=20)73 self.help_menu = customtkinter.CTkButton(master=self.frame_left, text="Help", command=self.btn_help)74 self.help_menu.grid(row=14, column=0, pady=10, padx=20)75 self.droid_logs = customtkinter.CTkLabel(master=self.frame_right, text=f"Droid Logs | v{version}")76 self.droid_logs.grid(row=0, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")77 78 self.mainloop()79 def btn_connect(self):80 # Buttons81 try:82 self.start_file_download.destroy()83 except AttributeError:84 pass85 try:86 self.start_file_upload.destroy()87 except AttributeError:88 pass89 try:90 self.start_apk_upload.destroy()91 except AttributeError:92 pass93 try:94 self.start_apk_remove.destroy()95 except AttributeError:96 pass97 try:98 self.start_disconnect.destroy()99 except AttributeError:100 pass101 try:102 self.start_reboot.destroy()103 except AttributeError:104 pass105 try:106 self.start_screenshot.destroy()107 except AttributeError:108 pass109 try:110 self.start_bluetooth.destroy()111 except AttributeError:112 pass113 try:114 self.stop_bluetooth.destroy()115 except AttributeError:116 pass117 try:118 self.start_wifi.destroy()119 except AttributeError:120 pass121 try:122 self.stop_wifi.destroy()123 except AttributeError:124 pass125 try:126 self.start_file_modification.destroy()127 except AttributeError:128 pass129 # Input Fields130 try:131 self.download_file.destroy()132 except AttributeError:133 pass134 try:135 self.upload_file.destroy()136 except AttributeError:137 pass138 try:139 self.filename.destroy()140 except AttributeError:141 pass142 try:143 self.name_of_apk.destroy()144 except AttributeError:145 pass146 try:147 self.apk_package_name.destroy()148 except AttributeError:149 pass150 try:151 self.ip_addr.destroy()152 except AttributeError:153 pass154 try:155 self.screenshot_file.destroy()156 except AttributeError:157 pass158 try:159 self.name_of_file.destroy()160 except AttributeError:161 pass162 try:163 self.new_content.destroy()164 except AttributeError:165 pass166 self.ip_addr = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="IP Address of the Android device")167 self.ip_addr.grid(row=6, column=1, pady=10, padx=20)168 self.json_file_name = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="Location of the JSON file on the local system (ex: ~/Documents/droid_ip_addr.json)")169 self.json_file_name.grid(row=7, column=1, pady=10, padx=20)170 self.ip_addr_json = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="Key assigned in JSON file (ex: localhost)")171 self.ip_addr_json.grid(row=8, column=1, pady=10, padx=20)172 def submit():173 if exists(self.json_file_name.get()) and getsize(self.json_file_name.get()) > 4:174 try:175 with open(self.json_file_name.get(), "r") as ip_file:176 ip_addr = json.load(ip_file)177 except FileNotFoundError:178 pass179 try:180 connect_ip_addr = getoutput(f'{adb} connect {ip_addr[self.ip_addr_json.get()]}')181 except KeyError:182 connect_ip_addr = getoutput(f'{adb} connect {self.ip_addr.get()}')183 else:184 connect_ip_addr = getoutput(f'{adb} connect {self.ip_addr.get()}')185 print(f"{INFO_CODE} {connect_ip_addr}")186 self.droid_logs_lvl_1 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {connect_ip_addr}", corner_radius=6, fg_color=("white", "gray38"))187 self.droid_logs_lvl_1.grid(row=1, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")188 self.start_connect = customtkinter.CTkButton(master=self.frame_middle, text="Submit", command=submit)189 self.start_connect.grid(row=9, column=1, pady=10, padx=20)190 def btn_download_file(self):191 # Buttons192 try:193 self.start_connect.destroy()194 except AttributeError:195 pass196 try:197 self.start_file_upload.destroy()198 except AttributeError:199 pass200 try:201 self.start_apk_upload.destroy()202 except AttributeError:203 pass204 try:205 self.start_apk_remove.destroy()206 except AttributeError:207 pass208 try:209 self.start_disconnect.destroy()210 except AttributeError:211 pass212 try:213 self.start_reboot.destroy()214 except AttributeError:215 pass216 try:217 self.start_screenshot.destroy()218 except AttributeError:219 pass220 try:221 self.start_bluetooth.destroy()222 except AttributeError:223 pass224 try:225 self.stop_bluetooth.destroy()226 except AttributeError:227 pass228 try:229 self.start_wifi.destroy()230 except AttributeError:231 pass232 try:233 self.stop_wifi.destroy()234 except AttributeError:235 pass236 try:237 self.start_file_modification.destroy()238 except AttributeError:239 pass240 # Input Fields241 try:242 self.ip_addr.destroy()243 except AttributeError:244 pass245 try:246 self.json_file_name.destroy()247 except AttributeError:248 pass249 try:250 self.ip_addr_json.destroy()251 except AttributeError:252 pass253 try:254 self.upload_file.destroy()255 except AttributeError:256 pass257 try:258 self.filename.destroy()259 except AttributeError:260 pass261 try:262 self.name_of_apk.destroy()263 except AttributeError:264 pass265 try:266 self.apk_package_name.destroy()267 except AttributeError:268 pass269 try:270 self.ip_addr.destroy()271 except AttributeError:272 pass273 try:274 self.screenshot_file.destroy()275 except AttributeError:276 pass277 try:278 self.name_of_file.destroy()279 except AttributeError:280 pass281 try:282 self.new_content.destroy()283 except AttributeError:284 pass285 self.download_file = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="Location of File on the Android device")286 self.download_file.grid(row=6, column=1, pady=10, padx=20)287 def submit():288 download_android_file = getoutput(f'{adb} pull {self.download_file.get()}')289 print(f"{INFO_CODE} {download_android_file}")290 self.droid_logs_lvl_2 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {download_android_file}", corner_radius=6, fg_color=("white", "gray38"))291 self.droid_logs_lvl_2.grid(row=2, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")292 self.start_file_download = customtkinter.CTkButton(master=self.frame_middle, text="Submit", command=submit)293 self.start_file_download.grid(row=7, column=1, pady=10, padx=20)294 def btn_upload_file(self):295 # Buttons296 try:297 self.start_connect.destroy()298 except AttributeError:299 pass300 try:301 self.start_file_download.destroy()302 except AttributeError:303 pass304 try:305 self.start_apk_upload.destroy()306 except AttributeError:307 pass308 try:309 self.start_apk_remove.destroy()310 except AttributeError:311 pass312 try:313 self.start_disconnect.destroy()314 except AttributeError:315 pass316 try:317 self.start_reboot.destroy()318 except AttributeError:319 pass320 try:321 self.start_screenshot.destroy()322 except AttributeError:323 pass324 try:325 self.start_bluetooth.destroy()326 except AttributeError:327 pass328 try:329 self.stop_bluetooth.destroy()330 except AttributeError:331 pass332 try:333 self.start_wifi.destroy()334 except AttributeError:335 pass336 try:337 self.stop_wifi.destroy()338 except AttributeError:339 pass340 try:341 self.start_file_modification.destroy()342 except AttributeError:343 pass344 # Input Fields345 try:346 self.ip_addr.destroy()347 except AttributeError:348 pass349 try:350 self.json_file_name.destroy()351 except AttributeError:352 pass353 try:354 self.ip_addr_json.destroy()355 except AttributeError:356 pass357 try:358 self.download_file.destroy()359 except AttributeError:360 pass361 try:362 self.name_of_apk.destroy()363 except AttributeError:364 pass365 try:366 self.apk_package_name.destroy()367 except AttributeError:368 pass369 try:370 self.ip_addr.destroy()371 except AttributeError:372 pass373 try:374 self.screenshot_file.destroy()375 except AttributeError:376 pass377 try:378 self.name_of_file.destroy()379 except AttributeError:380 pass381 try:382 self.new_content.destroy()383 except AttributeError:384 pass385 self.upload_file = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="Location to push the file on the Android device")386 self.upload_file.grid(row=6, column=1, pady=10, padx=20)387 self.filename = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="Name of the file on your local machine")388 self.filename.grid(row=7, column=1, pady=10, padx=20)389 def submit():390 upload_android_file = getoutput(f'{adb} push {self.filename.get()} {self.upload_file.get()}')391 print(f"{INFO_CODE} {upload_android_file}")392 self.droid_logs_lvl_3 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {upload_android_file}", corner_radius=6, fg_color=("white", "gray38"))393 394 self.droid_logs_lvl_3.grid(row=3, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")395 self.start_file_upload = customtkinter.CTkButton(master=self.frame_middle, text="Submit", command=submit)396 self.start_file_upload.grid(row=8, column=1, pady=10, padx=20)397 def btn_upload_apk(self):398 # Buttons399 try:400 self.start_connect.destroy()401 except AttributeError:402 pass403 try:404 self.start_file_download.destroy()405 except AttributeError:406 pass407 try:408 self.start_file_upload.destroy()409 except AttributeError:410 pass411 try:412 self.start_apk_remove.destroy()413 except AttributeError:414 pass415 try:416 self.start_disconnect.destroy()417 except AttributeError:418 pass419 try:420 self.start_reboot.destroy()421 except AttributeError:422 pass423 try:424 self.start_screenshot.destroy()425 except AttributeError:426 pass427 try:428 self.start_bluetooth.destroy()429 except AttributeError:430 pass431 try:432 self.stop_bluetooth.destroy()433 except AttributeError:434 pass435 try:436 self.start_wifi.destroy()437 except AttributeError:438 pass439 try:440 self.stop_wifi.destroy()441 except AttributeError:442 pass443 try:444 self.start_file_modification.destroy()445 except AttributeError:446 pass447 # Input Fields448 try:449 self.ip_addr.destroy()450 except AttributeError:451 pass452 try:453 self.json_file_name.destroy()454 except AttributeError:455 pass456 try:457 self.ip_addr_json.destroy()458 except AttributeError:459 pass460 try:461 self.download_file.destroy()462 except AttributeError:463 pass464 try:465 self.upload_file.destroy()466 except AttributeError:467 pass468 try:469 self.filename.destroy()470 except AttributeError:471 pass472 try:473 self.apk_package_name.destroy()474 except AttributeError:475 pass476 try:477 self.ip_addr.destroy()478 except AttributeError:479 pass480 try:481 self.screenshot_file.destroy()482 except AttributeError:483 pass484 try:485 self.name_of_file.destroy()486 except AttributeError:487 pass488 try:489 self.new_content.destroy()490 except AttributeError:491 pass492 self.name_of_apk = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="Absolute path of the APK")493 self.name_of_apk.grid(row=6, column=1, pady=10, padx=20)494 def submit():495 upload_android_apk = getoutput(f'{adb} install -r {self.name_of_apk.get()}')496 print(f"{INFO_CODE} {upload_android_apk}")497 self.droid_logs_lvl_4 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {upload_android_apk}", corner_radius=6, fg_color=("white", "gray38"))498 499 self.droid_logs_lvl_4.grid(row=4, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")500 501 self.start_apk_upload = customtkinter.CTkButton(master=self.frame_middle, text="Submit", command=submit)502 self.start_apk_upload.grid(row=7, column=1, pady=10, padx=20)503 def btn_remove_apk(self):504 # Buttons505 try:506 self.start_connect.destroy()507 except AttributeError:508 pass509 try:510 self.start_file_download.destroy()511 except AttributeError:512 pass513 try:514 self.start_file_upload.destroy()515 except AttributeError:516 pass517 try:518 self.start_apk_upload.destroy()519 except AttributeError:520 pass521 try:522 self.start_disconnect.destroy()523 except AttributeError:524 pass525 try:526 self.start_reboot.destroy()527 except AttributeError:528 pass529 try:530 self.start_screenshot.destroy()531 except AttributeError:532 pass533 try:534 self.start_bluetooth.destroy()535 except AttributeError:536 pass537 try:538 self.stop_bluetooth.destroy()539 except AttributeError:540 pass541 try:542 self.start_wifi.destroy()543 except AttributeError:544 pass545 try:546 self.stop_wifi.destroy()547 except AttributeError:548 pass549 try:550 self.start_file_modification.destroy()551 except AttributeError:552 pass553 # Input Fields554 try:555 self.ip_addr.destroy()556 except AttributeError:557 pass558 try:559 self.json_file_name.destroy()560 except AttributeError:561 pass562 try:563 self.ip_addr_json.destroy()564 except AttributeError:565 pass566 try:567 self.download_file.destroy()568 except AttributeError:569 pass570 try:571 self.upload_file.destroy()572 except AttributeError:573 pass574 try:575 self.filename.destroy()576 except AttributeError:577 pass578 try:579 self.name_of_apk.destroy()580 except AttributeError:581 pass582 try:583 self.ip_addr.destroy()584 except AttributeError:585 pass586 try:587 self.screenshot_file.destroy()588 except AttributeError:589 pass590 try:591 self.name_of_file.destroy()592 except AttributeError:593 pass594 try:595 self.new_content.destroy()596 except AttributeError:597 pass598 self.apk_package_name = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="Package Name for APK")599 self.apk_package_name.grid(row=6, column=1, pady=10, padx=20)600 def submit():601 remove_android_apk = getoutput(f'{adb} uninstall {self.apk_package_name.get()}')602 print(f"{INFO_CODE} {remove_android_apk}")603 self.droid_logs_lvl_5 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {remove_android_apk}", corner_radius=6, fg_color=("white", "gray38"))604 self.droid_logs_lvl_5.grid(row=5, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")605 self.start_apk_remove = customtkinter.CTkButton(master=self.frame_middle, text="Submit", command=submit)606 self.start_apk_remove.grid(row=7, column=1, pady=10, padx=20)607 608 def btn_disconnect(self):609 # Buttons610 try:611 self.start_connect.destroy()612 except AttributeError:613 pass614 try:615 self.start_file_download.destroy()616 except AttributeError:617 pass618 try:619 self.start_file_upload.destroy()620 except AttributeError:621 pass622 try:623 self.start_apk_upload.destroy()624 except AttributeError:625 pass626 try:627 self.start_apk_remove.destroy()628 except AttributeError:629 pass630 try:631 self.start_reboot.destroy()632 except AttributeError:633 pass634 try:635 self.start_screenshot.destroy()636 except AttributeError:637 pass638 try:639 self.start_bluetooth.destroy()640 except AttributeError:641 pass642 try:643 self.stop_bluetooth.destroy()644 except AttributeError:645 pass646 try:647 self.start_wifi.destroy()648 except AttributeError:649 pass650 try:651 self.stop_wifi.destroy()652 except AttributeError:653 pass654 try:655 self.start_file_modification.destroy()656 except AttributeError:657 pass658 # Input Fields659 try:660 self.ip_addr.destroy()661 except AttributeError:662 pass663 try:664 self.json_file_name.destroy()665 except AttributeError:666 pass667 try:668 self.ip_addr_json.destroy()669 except AttributeError:670 pass671 try:672 self.download_file.destroy()673 except AttributeError:674 pass675 try:676 self.upload_file.destroy()677 except AttributeError:678 pass679 try:680 self.filename.destroy()681 except AttributeError:682 pass683 try:684 self.name_of_apk.destroy()685 except AttributeError:686 pass687 try:688 self.apk_package_name.destroy()689 except AttributeError:690 pass691 try:692 self.screenshot_file.destroy()693 except AttributeError:694 pass695 try:696 self.name_of_file.destroy()697 except AttributeError:698 pass699 try:700 self.new_content.destroy()701 except AttributeError:702 pass703 self.ip_addr = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="IP Address of the Android device (leave blank to disconnect everything)")704 self.ip_addr.grid(row=6, column=1, pady=10, padx=20)705 def submit():706 disconnect_ip_addr = getoutput(f'{adb} disconnect {self.ip_addr.get()}')707 print(f"{INFO_CODE} {disconnect_ip_addr}")708 self.droid_logs_lvl_6 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {disconnect_ip_addr}", corner_radius=6, fg_color=("white", "gray38"))709 self.droid_logs_lvl_6.grid(row=6, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")710 self.start_disconnect = customtkinter.CTkButton(master=self.frame_middle, text="Submit", command=submit)711 self.start_disconnect.grid(row=7, column=1, pady=10, padx=20)712 def btn_reboot(self):713 # Buttons714 try:715 self.start_connect.destroy()716 except AttributeError:717 pass718 try:719 self.start_file_download.destroy()720 except AttributeError:721 pass722 try:723 self.start_file_upload.destroy()724 except AttributeError:725 pass726 try:727 self.start_apk_upload.destroy()728 except AttributeError:729 pass730 try:731 self.start_apk_remove.destroy()732 except AttributeError:733 pass734 try:735 self.start_disconnect.destroy()736 except AttributeError:737 pass738 try:739 self.start_screenshot.destroy()740 except AttributeError:741 pass742 try:743 self.start_bluetooth.destroy()744 except AttributeError:745 pass746 try:747 self.stop_bluetooth.destroy()748 except AttributeError:749 pass750 try:751 self.start_wifi.destroy()752 except AttributeError:753 pass754 try:755 self.stop_wifi.destroy()756 except AttributeError:757 pass758 try:759 self.start_file_modification.destroy()760 except AttributeError:761 pass762 # Input Fields763 try:764 self.ip_addr.destroy()765 except AttributeError:766 pass767 try:768 self.json_file_name.destroy()769 except AttributeError:770 pass771 try:772 self.ip_addr_json.destroy()773 except AttributeError:774 pass775 try:776 self.download_file.destroy()777 except AttributeError:778 pass779 try:780 self.upload_file.destroy()781 except AttributeError:782 pass783 try:784 self.filename.destroy()785 except AttributeError:786 pass787 try:788 self.name_of_apk.destroy()789 except AttributeError:790 pass791 try:792 self.apk_package_name.destroy()793 except AttributeError:794 pass795 try:796 self.screenshot_file.destroy()797 except AttributeError:798 pass799 try:800 self.name_of_file.destroy()801 except AttributeError:802 pass803 try:804 self.new_content.destroy()805 except AttributeError:806 pass807 self.ip_addr = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="IP Address of the Android device")808 self.ip_addr.grid(row=6, column=1, pady=10, padx=20)809 def submit():810 reboot_output = getoutput(f'{adb} reboot {self.ip_addr.get()}')811 print(f"{INFO_CODE} {reboot_output}")812 self.droid_logs_lvl_7 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {reboot_output}", corner_radius=6, fg_color=("white", "gray38"))813 self.droid_logs_lvl_7.grid(row=7, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")814 self.start_reboot = customtkinter.CTkButton(master=self.frame_middle, text="Submit", command=submit)815 self.start_reboot.grid(row=7, column=1, pady=10, padx=20)816 def btn_screenshot(self):817 # Buttons818 try:819 self.start_connect.destroy()820 except AttributeError:821 pass822 try:823 self.start_file_download.destroy()824 except AttributeError:825 pass826 try:827 self.start_file_upload.destroy()828 except AttributeError:829 pass830 try:831 self.start_apk_upload.destroy()832 except AttributeError:833 pass834 try:835 self.start_apk_remove.destroy()836 except AttributeError:837 pass838 try:839 self.start_disconnect.destroy()840 except AttributeError:841 pass842 try:843 self.start_reboot.destroy()844 except AttributeError:845 pass846 try:847 self.start_bluetooth.destroy()848 except AttributeError:849 pass850 try:851 self.stop_bluetooth.destroy()852 except AttributeError:853 pass854 try:855 self.start_wifi.destroy()856 except AttributeError:857 pass858 try:859 self.stop_wifi.destroy()860 except AttributeError:861 pass862 try:863 self.start_file_modification.destroy()864 except AttributeError:865 pass866 # Input Fields867 try:868 self.ip_addr.destroy()869 except AttributeError:870 pass871 try:872 self.json_file_name.destroy()873 except AttributeError:874 pass875 try:876 self.ip_addr_json.destroy()877 except AttributeError:878 pass879 try:880 self.download_file.destroy()881 except AttributeError:882 pass883 try:884 self.upload_file.destroy()885 except AttributeError:886 pass887 try:888 self.filename.destroy()889 except AttributeError:890 pass891 try:892 self.name_of_apk.destroy()893 except AttributeError:894 pass895 try:896 self.apk_package_name.destroy()897 except AttributeError:898 pass899 try:900 self.ip_addr.destroy()901 except AttributeError:902 pass903 try:904 self.name_of_file.destroy()905 except AttributeError:906 pass907 try:908 self.new_content.destroy()909 except AttributeError:910 pass911 self.screenshot_file = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="Filename (omit extension)")912 self.screenshot_file.grid(row=6, column=1, pady=10, padx=20)913 def submit():914 screenshot_output = getoutput(f"{adb} exec-out screencap -p > droid_{self.screenshot_file.get()}.png")915 print(f"{INFO_CODE} {screenshot_output}")916 self.droid_logs_lvl_8 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {screenshot_output}", corner_radius=6, fg_color=("white", "gray38"))917 self.droid_logs_lvl_8.grid(row=8, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")918 self.start_screenshot = customtkinter.CTkButton(master=self.frame_middle, text="Submit", command=submit)919 self.start_screenshot.grid(row=7, column=1, pady=10, padx=20)920 def btn_bluetooth(self):921 # Buttons922 try:923 self.start_connect.destroy()924 except AttributeError:925 pass926 try:927 self.start_file_download.destroy()928 except AttributeError:929 pass930 try:931 self.start_file_upload.destroy()932 except AttributeError:933 pass934 try:935 self.start_apk_upload.destroy()936 except AttributeError:937 pass938 try:939 self.start_apk_remove.destroy()940 except AttributeError:941 pass942 try:943 self.start_disconnect.destroy()944 except AttributeError:945 pass946 try:947 self.start_reboot.destroy()948 except AttributeError:949 pass950 try:951 self.start_screenshot.destroy()952 except AttributeError:953 pass954 try:955 self.start_bluetooth.destroy()956 except AttributeError:957 pass958 try:959 self.stop_bluetooth.destroy()960 except AttributeError:961 pass962 try:963 self.start_wifi.destroy()964 except AttributeError:965 pass966 try:967 self.stop_wifi.destroy()968 except AttributeError:969 pass970 try:971 self.start_file_modification.destroy()972 except AttributeError:973 pass974 # Input Fields975 try:976 self.ip_addr.destroy()977 except AttributeError:978 pass979 try:980 self.json_file_name.destroy()981 except AttributeError:982 pass983 try:984 self.ip_addr_json.destroy()985 except AttributeError:986 pass987 try:988 self.upload_file.destroy()989 except AttributeError:990 pass991 try:992 self.filename.destroy()993 except AttributeError:994 pass995 try:996 self.name_of_apk.destroy()997 except AttributeError:998 pass999 try:1000 self.apk_package_name.destroy()1001 except AttributeError:1002 pass1003 try:1004 self.ip_addr.destroy()1005 except AttributeError:1006 pass1007 try:1008 self.screenshot_file.destroy()1009 except AttributeError:1010 pass1011 try:1012 self.name_of_file.destroy()1013 except AttributeError:1014 pass1015 try:1016 self.new_content.destroy()1017 except AttributeError:1018 pass1019 try:1020 self.download_file.destroy()1021 except AttributeError:1022 pass1023 def start_bluetooth():1024 # Restarts adb in root1025 root_output = getoutput(f'{adb} root')1026 # Starts bluetooth service1027 bluetooth_output = getoutput(f'{adb} shell service call bluetooth_manager 6')1028 print(f"{INFO_CODE} {root_output}")1029 print(f"{INFO_CODE} {bluetooth_output}")1030 self.droid_logs_lvl_9 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {root_output}", corner_radius=6, fg_color=("white", "gray38"))1031 self.droid_logs_lvl_9.grid(row=9, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")1032 self.droid_logs_lvl_10 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {bluetooth_output}", corner_radius=6, fg_color=("white", "gray38"))1033 self.droid_logs_lvl_10.grid(row=10, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")1034 1035 def stop_bluetooth():1036 # Restarts adb in root1037 root_output = getoutput(f'{adb} root')1038 # Stops bluetooth service1039 bluetooth_output = getoutput(f'{adb} shell service call bluetooth_manager 8')1040 print(f"{INFO_CODE} {root_output}")1041 print(f"{INFO_CODE} {bluetooth_output}")1042 self.droid_logs_lvl_11 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {root_output}", corner_radius=6, fg_color=("white", "gray38"))1043 self.droid_logs_lvl_11.grid(row=11, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")1044 self.droid_logs_lvl_12 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {bluetooth_output}", corner_radius=6, fg_color=("white", "gray38"))1045 self.droid_logs_lvl_12.grid(row=12, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")1046 1047 self.start_bluetooth = customtkinter.CTkButton(master=self.frame_middle, text="Start Bluetooth", command=start_bluetooth)1048 self.start_bluetooth.grid(row=1, column=0, pady=10, padx=20)1049 self.stop_bluetooth = customtkinter.CTkButton(master=self.frame_middle, text="Stop Bluetooth", command=stop_bluetooth)1050 self.stop_bluetooth.grid(row=2, column=0, pady=10, padx=20)1051 def btn_wifi(self):1052 # Buttons1053 try:1054 self.start_connect.destroy()1055 except AttributeError:1056 pass1057 try:1058 self.start_file_download.destroy()1059 except AttributeError:1060 pass1061 try:1062 self.start_file_upload.destroy()1063 except AttributeError:1064 pass1065 try:1066 self.start_apk_upload.destroy()1067 except AttributeError:1068 pass1069 try:1070 self.start_apk_remove.destroy()1071 except AttributeError:1072 pass1073 try:1074 self.start_disconnect.destroy()1075 except AttributeError:1076 pass1077 try:1078 self.start_reboot.destroy()1079 except AttributeError:1080 pass1081 try:1082 self.start_screenshot.destroy()1083 except AttributeError:1084 pass1085 try:1086 self.start_bluetooth.destroy()1087 except AttributeError:1088 pass1089 try:1090 self.stop_bluetooth.destroy()1091 except AttributeError:1092 pass1093 try:1094 self.start_file_modification.destroy()1095 except AttributeError:1096 pass1097 # Input Fields1098 try:1099 self.ip_addr.destroy()1100 except AttributeError:1101 pass1102 try:1103 self.json_file_name.destroy()1104 except AttributeError:1105 pass1106 try:1107 self.ip_addr_json.destroy()1108 except AttributeError:1109 pass1110 try:1111 self.upload_file.destroy()1112 except AttributeError:1113 pass1114 try:1115 self.filename.destroy()1116 except AttributeError:1117 pass1118 try:1119 self.name_of_apk.destroy()1120 except AttributeError:1121 pass1122 try:1123 self.apk_package_name.destroy()1124 except AttributeError:1125 pass1126 try:1127 self.ip_addr.destroy()1128 except AttributeError:1129 pass1130 try:1131 self.screenshot_file.destroy()1132 except AttributeError:1133 pass1134 try:1135 self.name_of_file.destroy()1136 except AttributeError:1137 pass1138 try:1139 self.new_content.destroy()1140 except AttributeError:1141 pass1142 try:1143 self.download_file.destroy()1144 except AttributeError:1145 pass1146 def start_wifi():1147 # Restarts adb in root1148 root_output = getoutput(f'{adb} root')1149 # Starts wifi service1150 wifi_output = getoutput(f"{adb} shell 'svc wifi enable'")1151 print(f"{INFO_CODE} {root_output}")1152 print(f"{INFO_CODE} {wifi_output}")1153 self.droid_logs_lvl_13 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {root_output}", corner_radius=6, fg_color=("white", "gray38"))1154 self.droid_logs_lvl_13.grid(row=13, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")1155 self.droid_logs_lvl_14 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {wifi_output}", corner_radius=6, fg_color=("white", "gray38"))1156 self.droid_logs_lvl_14.grid(row=14, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")1157 def stop_wifi():1158 # Restarts adb in root1159 root_output = getoutput(f'{adb} root')1160 # Stops wifi service1161 wifi_output = getoutput(f"{adb} shell 'svc wifi disable'")1162 print(f"{INFO_CODE} {root_output}")1163 print(f"{INFO_CODE} {wifi_output}")1164 self.droid_logs_lvl_15 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {root_output}", corner_radius=6, fg_color=("white", "gray38"))1165 self.droid_logs_lvl_15.grid(row=15, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")1166 self.droid_logs_lvl_16 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {wifi_output}", corner_radius=6, fg_color=("white", "gray38"))1167 self.droid_logs_lvl_16.grid(row=16, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")1168 self.start_wifi = customtkinter.CTkButton(master=self.frame_middle, text="Start Wifi", command=start_wifi)1169 self.start_wifi.grid(row=1, column=0, pady=10, padx=20)1170 self.stop_wifi = customtkinter.CTkButton(master=self.frame_middle, text="Stop Wifi", command=stop_wifi)1171 self.stop_wifi.grid(row=2, column=0, pady=10, padx=20)1172 def btn_modify_file(self):1173 # Buttons1174 try:1175 self.start_connect.destroy()1176 except AttributeError:1177 pass1178 try:1179 self.start_file_download.destroy()1180 except AttributeError:1181 pass1182 try:1183 self.start_file_upload.destroy()1184 except AttributeError:1185 pass1186 try:1187 self.start_apk_upload.destroy()1188 except AttributeError:1189 pass1190 try:1191 self.start_apk_remove.destroy()1192 except AttributeError:1193 pass1194 try:1195 self.start_disconnect.destroy()1196 except AttributeError:1197 pass1198 try:1199 self.start_reboot.destroy()1200 except AttributeError:1201 pass1202 try:1203 self.start_screenshot.destroy()1204 except AttributeError:1205 pass1206 try:1207 self.start_bluetooth.destroy()1208 except AttributeError:1209 pass1210 try:1211 self.stop_bluetooth.destroy()1212 except AttributeError:1213 pass1214 try:1215 self.start_wifi.destroy()1216 except AttributeError:1217 pass1218 try:1219 self.stop_wifi.destroy()1220 except AttributeError:1221 pass1222 # Input Fields1223 try:1224 self.ip_addr.destroy()1225 except AttributeError:1226 pass1227 try:1228 self.json_file_name.destroy()1229 except AttributeError:1230 pass1231 try:1232 self.ip_addr_json.destroy()1233 except AttributeError:1234 pass1235 try:1236 self.download_file.destroy()1237 except AttributeError:1238 pass1239 try:1240 self.upload_file.destroy()1241 except AttributeError:1242 pass1243 try:1244 self.filename.destroy()1245 except AttributeError:1246 pass1247 try:1248 self.name_of_apk.destroy()1249 except AttributeError:1250 pass1251 try:1252 self.apk_package_name.destroy()1253 except AttributeError:1254 pass1255 try:1256 self.ip_addr.destroy()1257 except AttributeError:1258 pass1259 try:1260 self.screenshot_file.destroy()1261 except AttributeError:1262 pass1263 1264 self.name_of_file = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="Name of the file to modify")1265 self.name_of_file.grid(row=6, column=1, pady=10, padx=20)1266 self.new_content = customtkinter.CTkEntry(master=self.frame_middle, width=400, placeholder_text="Content to add into the modified file")1267 self.new_content.grid(row=7, column=1, pady=10, padx=20)1268 def submit():1269 # Modifies a file without downloading the file1270 file_write_output = getoutput(f"{adb} shell 'echo '{self.new_content.get()}' > {self.name_of_file.get()}'")1271 print(f"{INFO_CODE} {file_write_output}")1272 self.droid_logs_lvl_17 = customtkinter.CTkLabel(master=self.frame_right, text=f"{INFO_CODE} {file_write_output}", corner_radius=6, fg_color=("white", "gray38"))1273 1274 self.droid_logs_lvl_17.grid(row=17, column=1, columnspan=5, rowspan=1, pady=5, padx=5, sticky="nsew")1275 self.start_file_modification = customtkinter.CTkButton(master=self.frame_middle, text="Submit", command=submit)1276 self.start_file_modification.grid(row=8, column=1, pady=10, padx=20)1277 1278 def btn_help(self):1279 msg = "\n \1280 Connect | Connects to the Android device\n \1281 Disconnect | Disconnects from the Android device\n \1282 Reboot | Remotely reboots the Android device\n \1283 Screenshot | Takes a screenshot of the current screen\n \1284 Download | Download a file from the Android device\n \1285 Upload | Upload a file to the Android device\n \1286 Remove APK | Remove an apk from the Android device\n \1287 Upload APK | Upload an apk to the Android device\n \1288 Bluetooth | Start/stop the Bluetooth service\n \1289 Wifi | Start/stop the Wifi service\n \1290 Close | Closes Droid and disconnects from Android device\n \1291 Modify | Modify a file on the Android device without downloading anything\n \1292 Help | This help menu\n \1293 "1294 print(msg)1295 messagebox.showinfo("Help Menu", "Check terminal for help menu")1296 def btn_destroy(self):1297 print("Exiting...")1298 time.sleep(1)...

Full Screen

Full Screen

RuntimeCompositor.py

Source:RuntimeCompositor.py Github

copy

Full Screen

...118 self.env_layer.set_legacy_test_mode()119 self.env_layer.run_command_output = self.legacy_env_layer_extensions.run_command_output120 def reconfigure_reboot_manager(self):121 self.reboot_manager.start_reboot = self.start_reboot122 def start_reboot(self, message="Test initiated reboot mock"):123 self.status_handler.set_installation_reboot_status(Constants.RebootStatus.STARTED)124 def reconfigure_package_manager(self):125 self.backup_get_current_auto_os_patch_state = self.package_manager.get_current_auto_os_patch_state126 self.package_manager.get_current_auto_os_patch_state = self.get_current_auto_os_patch_state127 def mock_sleep(self, seconds):128 pass129 def check_sudo_status(self, raise_if_not_sudo=True):130 return True131 def get_current_auto_os_patch_state(self):132 return Constants.AutomaticOSPatchStates.DISABLED133 def mock_urlopen(self, url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, cafile=None, capath=None, cadefault=False, context=None):134 if self.vm_cloud_type == Constants.VMCloudType.AZURE:135 resp = urlreq.addinfourl(StringIO("mock file"), "mock message", "mockurl")136 resp.code = 200...

Full Screen

Full Screen

RebootManager.py

Source:RebootManager.py Github

copy

Full Screen

...51 def is_setting(self, setting_to_check):52 return self.reboot_setting == setting_to_check53 # REBOOT ACTION54 # =============55 def start_reboot(self, message="Azure Patch Management initiated a reboot after a patch installation run."):56 """ Perform a system reboot """57 self.composite_logger.log("\nThe machine is set to reboot in " + self.minutes_to_shutdown + " minutes.")58 self.status_handler.set_installation_reboot_status(Constants.RebootStatus.STARTED)59 reboot_init_time = self.env_layer.datetime.datetime_utcnow()60 self.env_layer.reboot_machine(self.reboot_cmd + self.minutes_to_shutdown + ' ' + message)61 # Wait for timeout62 max_allowable_time_to_reboot_in_minutes = int(self.minutes_to_shutdown) + Constants.REBOOT_WAIT_TIMEOUT_IN_MINUTES63 while 1:64 current_time = self.env_layer.datetime.datetime_utcnow()65 elapsed_time_in_minutes = self.env_layer.datetime.total_minutes_from_time_delta(current_time - reboot_init_time)66 if elapsed_time_in_minutes >= max_allowable_time_to_reboot_in_minutes:67 self.status_handler.set_installation_reboot_status(Constants.RebootStatus.FAILED)68 error_msg = "Reboot failed to proceed on the machine in a timely manner."69 self.status_handler.add_error_to_status(error_msg, Constants.PatchOperationErrorCodes.DEFAULT_ERROR)70 raise Exception(error_msg, "[{0}]".format(Constants.ERROR_ADDED_TO_STATUS))71 else:72 self.composite_logger.file_logger.flush()73 self.composite_logger.log("Waiting for machine reboot. [ElapsedTimeInMinutes={0}] [MaxTimeInMinutes={1}]".format(str(elapsed_time_in_minutes), str(max_allowable_time_to_reboot_in_minutes)))74 self.composite_logger.file_logger.flush()75 time.sleep(60)76 def start_reboot_if_required_and_time_available(self, current_time_available):77 """ Starts a reboot if required. Happens only at the end of the run if required. """78 self.composite_logger.log("\nReboot Management")79 reboot_pending = False if not self.status_handler else self.status_handler.is_reboot_pending80 reboot_pending = self.package_manager.force_reboot or reboot_pending81 if self.package_manager.force_reboot:82 self.composite_logger.log("A reboot is pending as the package manager required it.")83 # return if never84 if self.reboot_setting == Constants.REBOOT_NEVER:85 if reboot_pending:86 self.composite_logger.log_warning(' - There is a reboot pending, but reboot is blocked, as per patch installation configuration. (' + str(Constants.REBOOT_NEVER) + ')')87 else:88 self.composite_logger.log_warning(' - There is no reboot pending, and reboot is blocked regardless, as per patch installation configuration (' + str(Constants.REBOOT_NEVER) + ').')89 return False90 # return if system doesn't require it (and only reboot if it does)91 if self.reboot_setting == Constants.REBOOT_IF_REQUIRED and not reboot_pending:92 self.composite_logger.log(" - There was no reboot pending detected. Reboot is being skipped as it's not required, as per patch installation configuration (" + str(Constants.REBOOT_IF_REQUIRED) + ").")93 return False94 # prevent repeated reboots95 if self.reboot_setting == Constants.REBOOT_ALWAYS and not reboot_pending and self.status_handler.get_installation_reboot_status() == Constants.RebootStatus.COMPLETED:96 self.composite_logger.log(" - At least one reboot has occurred, and there's no reboot pending, so the conditions for the 'Reboot Always' setting is fulfilled and reboot won't be repeated.")97 return False98 # attempt to reboot is enough time is available99 if self.reboot_setting == Constants.REBOOT_ALWAYS or (self.reboot_setting == Constants.REBOOT_IF_REQUIRED and reboot_pending):100 if self.is_reboot_time_available(current_time_available):101 self.composite_logger.log(' - Reboot is being scheduled, as per patch installation configuration (' + str(self.reboot_setting) + ').')102 self.composite_logger.log(" - Reboot-pending status: " + str(reboot_pending))103 self.start_reboot()104 return True105 else:106 error_msg = ' - There is not enough time to schedule a reboot as per patch installation configuration (' + str(self.reboot_setting) + '). Reboot-pending status: ' + str(reboot_pending)107 self.composite_logger.log_error(error_msg)108 self.status_handler.add_error_to_status("Reboot Management" + str(error_msg), Constants.PatchOperationErrorCodes.DEFAULT_ERROR)109 self.maintenance_window_exceeded_flag = True...

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 autotest 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