def get_email(): user_info = win32net.NetUserGetInfo(win32net.NetGetAnyDCName(), win32api.GetUserName(), 2) full_name = user_info["full_name"] full_name = full_name.replace(',', ' ') full_name = full_name.lower().strip() full_name = re.findall(r'\s*([^\s]+)', full_name)[:2] email = full_name[1] + "." + full_name[0] + "@cigna.com" return email
def _getDomainControllerName(self, domain): if self._presetserver != None: return self._presetserver try: # execute this on the localhost pdc = win32net.NetGetAnyDCName(None, domain) except: pdc = None return pdc
def _get_domain_controller_name(self, domain): if self.preset_server is not None: return self.preset_server try: # execute this on the localhost pdc = win32net.NetGetAnyDCName(None, domain) except Exception: pdc = None return pdc
def get_windows_display_name(): try: import win32api import win32net user_info = win32net.NetUserGetInfo(win32net.NetGetAnyDCName(), win32api.GetUserName(), 2) full_name = user_info["full_name"] return full_name except: import subprocess name = subprocess.check_output( 'net user "%USERNAME%" | FIND /I "Full Name"', shell=True) full_name = name.replace(b"Full Name", b"").strip() return full_name.decode("ascii")
self.textbox.config(state='disabled') self.scrollb = Scrollbar(text_frame, command=self.textbox.yview) self.textbox.config(yscrollcommand=self.scrollb.set) def toggle_details(self): if self.details_expanded: self.textbox.grid_forget() self.scrollb.grid_forget() self.geometry('380x95') self.details_expanded = False else: self.textbox.grid(row=0, column=0, sticky='nsew') self.scrollb.grid(row=0, column=1, sticky='nsew') self.geometry('380x160') self.details_expanded = True # https://superuser.com/questions/1239773/full-name-of-windows-user-name-in-domain-using-python user_info = win32net.NetUserGetInfo(win32net.NetGetAnyDCName(), win32api.GetUserName(), 2) full_name = user_info["full_name"] def main(): prog_gui = Gui() prog_gui.window.mainloop() if __name__ == "__main__": main()
def domain_controller(domain=None): return win32net.NetGetAnyDCName(None, domain)
def startAutomation(project: str = None, test_case_id_list: list = None, test_run_id: int = None): test_case_id_azure = 100000 duration = 0 status = None try: # Complete name (if is using the VPN). full_name = win32net.NetUserGetInfo(win32net.NetGetAnyDCName(), win32api.GetUserName(), 2)["full_name"] except: # Windows login (if is not using the VPN). full_name = os.getlogin() try: for test_case_id in test_case_id_list: list_steps, name_testcase, summary, cont_steps, change_download_config = Azure.startSteps(project, test_case_id) total_steps = len(list_steps) total_iteration = int(total_steps / cont_steps) + 1 step_initial = 0 step_final = cont_steps # Execution Initial time. initial_time = datetime.datetime.now() # Validate the testcase name. if Aux.validateTestName(name_testcase): continue # Create the TestSet folder. testsetpath = os.path.join(Aux.directories["EvidenceFolder"], Aux.otherConfigs["ETSName"] + str(test_case_id) + " - " + name_testcase) Aux.createDirectory(testsetpath) # Ask if need to save the evidence. if Aux.otherConfigs['ReplaceEvidence'].upper() in ('S', 'Y'): shutil.rmtree(testsetpath) os.makedirs(testsetpath) Aux.addLogs("General", Aux.logs["EvidenceFolder"]) else: Aux.addLogs("General", Aux.logs["WarningEvidenceFolder"]) status = "Not Completed" # Execute step by step per Iteration. for cont_iteration in range(1, total_iteration): Aux.addLogs("NewSession", "\nID: " + str(test_case_id) + " - TEST CASE: " + name_testcase + " - ITERATION: " + str(cont_iteration) + "\n") print(f"{classes.Textcolor.BOLD}{name_testcase}{classes.Textcolor.END}") status, step_failed = executeStepByStep(list_steps, testsetpath, step_initial, step_final, change_download_config) # If fail / abort in a iteration, jump to the next iteration. if status == "Failed": Func.verifyBrowser() elif status == "Aborted": Func.verifyBrowser() comments = Aux.otherConfigs['DownloadingFileIE']['Msg'] else: comments = Azure.getInfoRun(project, test_run_id, test_case_id_azure, name_testcase, cont_iteration, step_failed, status) # Set the test case duration. duration = datetime.datetime.now() - initial_time duration = int(duration.total_seconds() * 1000) # Process to generate the evidences and save to Azure. if Aux.otherConfigs["ReplaceEvidence"].upper() in ('S', 'Y'): # Update the test case inside the Run. Azure.updateTestCaseRun(project, test_run_id, test_case_id_azure, status, duration, comments) print(f"{classes.Textcolor.WARNING}{Aux.otherConfigs['GeneratingEvidence']['Msg']}{classes.Textcolor.END}\n") # If aborted do not create evidences. if Aux.otherConfigs["ReplaceEvidence"].upper() in ('S', 'Y') and status != 'Aborted': # Create an EST file. word_path = Aux.directories["ESTFile"] + ' ' + Aux.otherConfigs["Language"] + '.docx' est = Aux.wordAddSteps(test_run_id, test_case_id, name_testcase + " - ITERATION " + str(cont_iteration), summary, word_path, testsetpath, list_steps[step_initial:step_final], step_failed, full_name) pdf = Aux.wordToPDF(est) if est is None: Aux.addLogs("General", Aux.logs["ErrorEST"], name_testcase + " - ITERATION " + str(cont_iteration)) if pdf is None: Aux.addLogs("General", Aux.logs["ErrorConvertPDF"], name_testcase + " - ITERATION " + str(cont_iteration)) if (est is not None) and (pdf is not None): # Add the evidence to the Run and the Test case. Aux.addLogs("General", Aux.logs["ConvertPDF"], name_testcase + " - ITERATION " + str(cont_iteration)) Azure.SaveEvidenceRun(project, test_run_id, test_case_id_azure, Aux.directories["EvidenceFolder"], Aux.otherConfigs["ETSName"] + str(test_case_id) + " - " + name_testcase, cont_iteration) Azure.SaveEvidenceTestCase(project, Aux.directories["EvidenceFolder"], test_case_id, Aux.otherConfigs["ETSName"] + str(test_case_id) + " - " + name_testcase, cont_iteration) # Clear the evidences prints. Aux.deleteFiles(path_log=testsetpath, extension="png") # Variables. step_initial = step_final step_final = step_final + cont_steps test_case_id_azure += 1 except Exception as ex: print(f"{classes.Textcolor.FAIL}{Aux.logs['ErrorStartAutomation']['Msg']}{classes.Textcolor.END}", ex) Aux.addLogs("General", Aux.logs["ErrorStartAutomation"], str(ex)) Azure.updateTestCaseRun(project, test_run_id, test_case_id_azure, name_testcase, step_failed, cont_iteration, status, duration) Azure.updateRun(project, test_run_id, "Aborted") # Update the Run status. if Aux.otherConfigs["ReplaceEvidence"].upper() in ('S', 'Y'): Azure.updateRun(project, test_run_id, "Completed") Aux.addLogs("EndExecution")
def firstDraw(self): import os import tkinter as tk import win32api import win32net import other_gui_fncs import shopslist_fncs # ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ root = tk.Tk() root.state('zoomed') root.minsize(900, 500) root.grid_columnconfigure(0, weight=1) root.grid_rowconfigure(0, minsize=25) root.grid_rowconfigure(2, weight=1) root.grid_rowconfigure(3, minsize=25) headMenu_frame = tk.Frame(root) headMenu_frame.grid(row=0, column=0, sticky="nswe") tk.Frame(root, highlightcolor="#000000", highlightbackground="#000000", highlightthickness=1).grid(row=1, column=0, sticky="we") # Чёрточка main_frame = tk.Frame(root) main_frame.grid(row=2, column=0, sticky="nswe") down_frame = tk.Frame(root) down_frame.grid(row=3, column=0, sticky="nswe") # HEAD MENU headMenu_button_file = tk.Button(headMenu_frame, text="Файл", bd=0) headMenu_button_loadlist = tk.Button( headMenu_frame, command=lambda: shopslist_fncs.shoplist_update(self), text="Загрузить список магазинов", bd=0) other_gui_fncs.setActiveButton_bind(headMenu_button_file, 0) other_gui_fncs.setActiveButton_bind(headMenu_button_loadlist, 0) headMenu_button_file.grid(row=0, column=0, padx=2) headMenu_button_loadlist.grid(row=0, column=1, padx=2) # DOWN MENU tk.Label(down_frame, text="Пользователь: ", font=("Verdana", 8)).grid(row=0, column=0, padx=2, sticky="w") fr1 = tk.Frame(down_frame, highlightcolor="#000000", highlightbackground="#000000", highlightthickness=1) fr2 = tk.Frame(down_frame, highlightcolor="#000000", highlightbackground="#000000", highlightthickness=1) user1Label = tk.Label(fr1, text=" d", font=("Verdana", 8, "bold")) user2Label = tk.Label(fr2, text=" d", height=0, font=("Verdana", 8, "bold")) user1Label["text"] = win32net.NetUserGetInfo(win32net.NetGetAnyDCName(), self.USERNAME, 2)["full_name"] user2Label["text"] = "{}\\{}".format(self.DOMAIN, self.USERNAME) fr1.grid(row=0, column=1, padx=2, pady=2, sticky="w") fr2.grid(row=0, column=2, padx=2, pady=2, sticky="w") user1Label.grid() user2Label.grid() # !!!!!!!!!!!!! MAIN COMPOSITION !!!!!!!!!!!!! main_frame.grid_columnconfigure(1, weight=1) main_frame.grid_rowconfigure(0, weight=1) shops_frame = tk.Frame(main_frame, highlightcolor="#000000", highlightbackground="#000000", highlightthickness=1) root.act_frame = tk.Frame(main_frame, bg="#A9A9A9", highlightcolor="#000000", highlightbackground="#000000", highlightthickness=1) shops_frame.grid(row=0, column=0, padx=2, sticky="ns") root.act_frame.grid(row=0, column=1, padx=2, sticky="nswe") # SHOPS FRAME CONFIGURE tk.Label(shops_frame, text="Список магазинов:").grid(row=0, column=0, padx=2, pady=5, sticky="w") shopsCount_frame = tk.Frame(shops_frame) shopsCount_frame.grid(row=2, column=0, padx=2, pady=5, sticky="we") shopsCount_frame.grid_columnconfigure(1, weight=1) tk.Label(shopsCount_frame, text="Магазинов:", font=("Verdana", 8, "bold")).grid(row=0, column=0, sticky="w") root.shopsCount_label = tk.Label(shopsCount_frame, text="0", font=("Verdana", 8, "bold")) root.shopsCount_label.grid(row=0, column=1, sticky="e") # SHOPS LIST shops_frame.grid_rowconfigure(1, weight=1) shopsList_frame = tk.Frame(shops_frame, highlightcolor="#000000", highlightbackground="#000000", highlightthickness=1) shopsList_frame.grid_rowconfigure(0, weight=1) shopsList_frame.grid_columnconfigure(0, weight=2) shopsList_frame.grid(row=1, column=0, padx=2, sticky="nswe") self.shops_list = tk.Listbox(shopsList_frame, selectmode=tk.SINGLE, exportselection=False, bd=0, highlightcolor="SystemButtonFace") self.shops_list.grid(row=0, column=0, sticky="nswe") shops_scroll = tk.Scrollbar(shopsList_frame, orient='vertical', command=self.shops_list.yview) shops_scroll.grid(row=0, column=1, sticky="ns") self.shops_list['yscrollcommand'] = shops_scroll.set self.shops_list.bind( "<<ListboxSelect>>", lambda event: shopslist_fncs.shoplist_select(self, event)) self.shops_list.bind( "<KeyPress>", lambda event: shopslist_fncs.shoplist_keyNavigate(self, event)) return root
def get_display_name(): user_info = win32net.NetUserGetInfo(win32net.NetGetAnyDCName(), win32api.GetUserName(), 2) fullname = user_info["full_name"] return fullname
def startAutomation(**kwargs): # kwargs arguments. project = kwargs.get('project') test_run_id = kwargs.get('test_run_id') try: # Complete name (if is using the VPN). full_name = win32net.NetUserGetInfo(win32net.NetGetAnyDCName(), win32api.GetUserName(), 2)["full_name"] except: # Windows login (if is not using the VPN). full_name = os.getlogin() try: testsetpathmanual = Aux.directories["EvidenceFolderManual"] Aux.createDirectory(testsetpathmanual) # Execute the action to get the manual evidences. test_case_id_list, n_iterations_list, id_azure_list, n_test_case_list = Azure.manualEvidences( project, test_run_id) for test_case_id in test_case_id_list: list_steps, name_testcase, summary, cont_steps, change_download_config = Azure.startSteps( project, test_case_id) step_initial = 0 step_final = cont_steps n_print = 0 n_iterations = n_iterations_list.pop( 0) # Get the number of the iterations for the test order. id_azure = id_azure_list.pop(0) n_test_case = n_test_case_list.pop(0) # Create the TestSet folder. testsetpath = os.path.join( Aux.directories["EvidenceFolder"], Aux.otherConfigs["ETSName"] + str(test_case_id) + " - " + name_testcase) if os.path.exists(testsetpath): shutil.rmtree(testsetpath) os.makedirs(testsetpath) Aux.addLogs("General", Aux.logs["EvidenceFolder"]) Aux.createDirectory(testsetpath) print( f"{classes.Textcolor.WARNING}{Aux.otherConfigs['GeneratingEvidence']['Msg']}" f"{classes.Textcolor.END}\n") # Create an EST file. word_path = Aux.directories["ESTFile"] + ' ' + Aux.otherConfigs[ "Language"] + '.docx' # Create evidence step by step per Iteration. for n_iteration in range(1, n_iterations + 1): # Move the prints to the correct folder and rename the evidences - Order by older first. filenames = os.listdir(Aux.directories["EvidenceFolderManual"]) for filename in filenames: if n_print == cont_steps: break if (filename.endswith("png")) and \ (("CT" + str(n_test_case) + "-IT" + str(n_iteration)) in filename): file_newname = 'Screenshot_' + str(n_print) + '.png' # Rename the prints and move to the correct Test Case folder. os.rename( os.path.join(testsetpathmanual, filename), os.path.join(testsetpathmanual, file_newname)) shutil.move( os.path.join(testsetpathmanual, file_newname), testsetpath) n_print += 1 n_print = 0 est = Aux.wordAddSteps( test_run_id, test_case_id, name_testcase + " - ITERATION " + str(n_iteration), summary, word_path, testsetpath, list_steps[step_initial:step_final], "OK", full_name) if est is None: Aux.addLogs( "General", Aux.logs["ErrorEST"], name_testcase + " - ITERATION " + str(n_iteration)) pdf = Aux.wordToPDF(est) if pdf is None: Aux.addLogs( "General", Aux.logs["ErrorConvertPDF"], name_testcase + " - ITERATION " + str(n_iteration)) if (est is not None) and (pdf is not None): # Add the evidence to the Run and the Test case. Aux.addLogs( "General", Aux.logs["ConvertPDF"], name_testcase + " - ITERATION " + str(n_iteration)) Azure.SaveEvidenceRun( project, test_run_id, id_azure, Aux.directories["EvidenceFolder"], Aux.otherConfigs["ETSName"] + str(test_case_id) + " - " + name_testcase, n_iteration) Azure.SaveEvidenceTestCase( project, Aux.directories["EvidenceFolder"], test_case_id, Aux.otherConfigs["ETSName"] + str(test_case_id) + " - " + name_testcase, n_iteration) # Clear the evidences prints. Aux.deleteFiles(path_log=testsetpath, extension="png") n_test_case += 1 shutil.rmtree(testsetpathmanual) except Exception as ex: print( f"{classes.Textcolor.FAIL}{Aux.logs['ErrorStartAutomation']['Msg']}{classes.Textcolor.END}", ex) Aux.addLogs("General", Aux.logs["ErrorStartAutomation"], str(ex)) exit(1) Aux.addLogs("EndExecution")
# LOCAL_EMAIL # DEFAULT_USER_DIR # DEFAULT_USER_CONFIG # DEFAULT_SYSTEM_DIR ################################################## IS_WINDOWS = sys.platform.lower().startswith("win") LOCAL_USER_ID = LOCAL_USERNAME = getpass.getuser() LOCAL_USERNAME = LOCAL_USERNAME.title() if IS_WINDOWS: try: # pylint: disable=F0401 import win32net, win32api USER_INFO_20 = 20 LOCAL_USERNAME = win32net.NetUserGetInfo( win32net.NetGetAnyDCName(), win32api.GetUserName(), USER_INFO_20, )["full_name"] or LOCAL_USERNAME except ImportError: pass else: # pylint: disable=F0401 import pwd # only available on non-win32 LOCAL_USERNAME = pwd.getpwnam(LOCAL_USER_ID).pw_gecos.split(',', 1)[0] LOCAL_EMAIL = ( os.environ.get("EMAIL", "") or "%s@%s" % (LOCAL_USER_ID, gethostname()) ) if IS_WINDOWS: