def childApp_newProject(self, entity, MenuOptions, source): """ 在子应用中新建项目 :return: """ from config.configurationFile import ProfileDataProcessing dlg_app = entity.child_window(title=self.windowTitle, class_name="wxWindowNR").wait("exists", timeout=60, retry_interval=0.2) dlg_app.menu_select(MenuOptions) # 点击菜单选项 Check_winControl("提示", "是").popUp_Whether_close() # 选择项目的保存路径 Popup_type2="无" list_AfterParsing = ["新建项目: 指定项目保存路径", "test_1", "保存"] ControlOperationSuite_Aercheck(None).SelectFile_Popover(list_AfterParsing, source,Popup_type2) # 项目设置,增加有限元模型路径 try: app = Application().connect(title="项目设置",timeout=5) # 连接项目设置弹窗 self.dlg_spec = app.window(title="项目设置") # app.window(title="项目设置").maximize() # 项目弹窗最大化 except findwindows.ElementNotFoundError: raise MyException("没有找到“项目设置“窗口") else: x = int(ProfileDataProcessing("commonality-Aerobook-Aerocheck", "coord1_x").config_File()) # 从配置文件获取鼠标点击坐标 y = int(ProfileDataProcessing("commonality-Aerobook-Aerocheck", "coord1_y").config_File()) # 从配置文件获取鼠标点击坐标 self.dlg_spec.click_input(button='left', coords= (x, y) ) # 点击有限元模型路径对应的文本框,显示出文本框 DetailedPath = source + "\Htail.fem" self.dlg_spec.Edit.wait("exists", timeout=60, retry_interval=1).set_text(DetailedPath) # 在有限元模型路径对应的文本框中输入数据 self.dlg_spec.wxPropertyGrid.click_input() Check_winControl("项目设置", "完成").nest_popUpWindows("警告", "OK",4) # 检查嵌套弹窗是否关闭
def SelectFile_Popover(self,list_Popup_parameter,location,Popup_type,Popup_parameter=None,window_one=None): """ 在保存和选择文件路径弹窗中操作 :param list_Popup_parameter:弹窗参数信息 :param location: 路径 :param window_one: 关闭弹窗按钮名称 :param Popup_type: 弹窗类型 :param Popup_parameter: 在文件名文本框输入的内容 :return: """ hwnd=0 Popup_Title = list_Popup_parameter[0] # 取出弹窗标题 file_name = list_Popup_parameter[1] # 取出输入的文件名 close_Name = list_Popup_parameter[2] # 取出关闭弹窗的按钮名称 if window_one: Check_winControl(Popup_Title, window_one).window_WhetherOpen() # 保证弹窗出现 try : n=0 i=10 while n<=i: time.sleep(0.2) hwnd = win32gui.FindWindow(None, Popup_Title) if hwnd !=0: break n+=1 if hwnd == 0: # 如果句柄不为零证明找到了该弹窗 raise MyException("没有找到弹窗") except Exception: print("没有找到“%r“窗口,获取的句柄为:%r"%(Popup_Title,hwnd), __file__, sys._getframe().f_lineno) raise MyException("没有找到“%r“窗口"%Popup_Title) else: app = Application().connect(handle=hwnd, timeout=20) self.dlg_spec = app.window(handle=hwnd) # 切换到选择文件弹窗窗口 # self.dlg_spec.print_control_identifiers() # 切换控件 dlg_spec1 = self.dlg_spec.child_window(class_name="WorkerW") dlg_spec2 = dlg_spec1.child_window(class_name="ReBarWindow32") dlg_spec3 = dlg_spec2.child_window(class_name="Address Band Root") dlg_spec4 = dlg_spec3.child_window(class_name="msctls_progress32") # 切换到选择文件弹窗中的地址栏 dlg_spec5 = dlg_spec4.child_window(class_name="Breadcrumb Parent") dlg_spec6 = dlg_spec5.Toolbar dlg_spec6.click_input(coords = (10, 10)) # 点击地址栏,让地址栏输入框显示出来 dlg_spec4.Edit.set_text(location) # 在地址栏输入地址 send_keys('{ENTER}') # 点击回车键 self.dlg_spec["Edit"].set_text(file_name) # 在文件名中输入内容 if Popup_type=="" or Popup_type=="无": Check_winControl(Popup_Title, close_Name).popUp_Whether_close() # 检查点击按钮后窗口是否关闭,如果没有关闭,继续点击按钮 else: list_AfterParsing = Popup_parameter.split(";") nest_PopWinTitle=list_AfterParsing[0] nest_control_Name = list_AfterParsing[1] Check_winControl(Popup_Title, close_Name).nest_popUpWindows(nest_PopWinTitle,nest_control_Name) # 检查嵌套弹窗是否关闭
def IdentificationMethod(self, Controlmethod, discern): """ 因为从电子表格获取的控件标识字符串,拼接在操作控件的时候会报错,暂时还没有找到原因,暂时使用该方法拼接操作方法 :return: """ # 解析参数 if ";" in discern: self.list_AfterParsing = discern.split(";") discern = self.list_AfterParsing[-1] if Controlmethod == "方式一": self.dlg_spec = OperatingControls( self.win_one).ExpressionAssembly(discern) Check_winControl("警告", "OK").popUp_Whether_close() elif Controlmethod == "方式二": if "][" in discern: # 解析参数 self.list_AfterParsing = discern.split("][") discern = self.list_AfterParsing[-1] title_n = self.list_AfterParsing[0] className = self.list_AfterParsing[1] self.dlg_spec = self.win_one.child_window(title=title_n, class_name=className) else: print("传过来的控件唯一标识没有“][”,所有无法被转化成列表:", discern, __file__, sys._getframe().f_lineno) raise MyException("没有找到弹窗") else: print("没有唯一标识的操作方法", __file__, sys._getframe().f_lineno) sys.exit(0) return self.dlg_spec
def coord_click_textbox(self, ControlProperties, argument): """ 坐标--文本框 通过点击坐标位置显示文本框,然后输入内容 选择材料许用值曲线 :param argument: 在文本框输入的参数 :param ControlProperties: 控件属性 :return: """ discern = ControlProperties["唯一标识"] ControlTypes = ControlProperties["控件类型"] if ControlTypes == "坐标--单击--文本框": self.dlg_spec = OperatingControls( self.win_one).coord_dblclick(discern) elif ControlTypes == "坐标--三击--文本框": self.dlg_spec = OperatingControls( self.win_one).coord_Threeclick(discern) elif ControlTypes == "坐标--键盘--文本框": OperatingControls(self.win_one).coord_keyboardInput( discern, argument) else: print("没有找到操作方法:", ControlTypes, __file__, sys._getframe().f_lineno) sys.exit(0) if ControlTypes != "坐标--键盘--文本框": Check_winControl(None, self.dlg_spec).Verify_inputBox(argument)
def get_WarningPopUp(self, Message_type, waitTime): """ 获取警告弹窗的文本信息 :param Message_type: 弹窗的类型 :param waitTime: 是个列表,等待弹窗出现的时间 :return: """ waitTime = waitTime[0] # 取出等待时间 UseCase_Number = self.property["用例编号"] # 用于生产截图的名称 Popup_type = "警告" # 定义弹窗标题,默认为“警告” close_button = "OK" # 定义弹窗的关闭按钮名称,默认为“OK” # 获取弹窗的类型,预期类型不多,所有写死 if "警告弹窗" == Message_type: Popup_type = "警告" close_button = "OK" elif "提示弹窗" == Message_type: Popup_type = "提示" close_button = "确定" result = Warning_PopUp().Check_warning(waitTime, Popup_type) # 确定弹窗是否存在 if result: # 如果警告弹窗存在 self.dicti_actual = Warning_PopUp().Warning_PopUp_TXT( UseCase_Number, Popup_type) # 获取弹窗的文本 Check_winControl(Popup_type, close_button).popUp_Whether_close() # 关闭警告窗口 else: self.dicti_actual = "没有警告弹窗" return self.dicti_actual
def clear_editWorkingCondition(self, moduleName): """ 编辑工况测试前清除所有的包络工况 :return: """ from tool import Check_winControl from OperatingControls.enterModule import BeingMeasured_popupWin Check_winControl("编辑工况", "关闭").popUp_Whether_close() self.dict["所在模块"] = "载荷信息->编辑工况" pywin_openAProgram(moduleName).menuOpen(self.dict) # 切换到编辑工况弹窗 module_window = BeingMeasured_popupWin("编辑工况").menu_LetsGoTopopover() while True: txt = module_window.ComboBox.window_text() if txt: module_window.编辑工况Button.click_input() else: break Check_winControl("编辑工况", "关闭").popUp_Whether_close()
def workField_Open_EditArgument(self): """ 紧固件强度校核--紧固件参数输入 打开编辑参数弹框,并返回窗口实例 :return: """ from tool import Check_winControl workField = self.workField.Button2 Check_winControl(None, workField).window_handle_WhetherOpen( "#32770", "Edit4") # 编辑参数是否打开 hwnd = win32gui.FindWindow("#32770", None) # 获取窗体的句柄 app = Application().connect(handle=hwnd, timeout=20) dlg_spec = app.window(handle=hwnd) # 切换到选择文件弹窗窗口 return dlg_spec
def button_popUp(self, ControlProperties, location): """ 套件操作 :param ControlProperties: 控件的属性 :param location: 项目存放路径 :return: """ examine = None Popup_type = ControlProperties["套件类型一"] Popup_parameter = ControlProperties["套件参数一"] if ";" in Popup_parameter: self.list_AfterParsing = Popup_parameter.split(";") if Popup_type == "路径弹窗": # 操作弹窗套件 Popup_type2 = ControlProperties["套件类型二"] Popup_parameter2 = ControlProperties["套件参数二"] ControlOperationSuite_Aercheck(None).SelectFile_Popover( self.list_AfterParsing, location, Popup_type2, Popup_parameter2, self.win_one) elif Popup_type == "选择材料许用值曲线": # 操作弹窗套件 str_coord = ControlProperties["唯一标识"] Check_winControl(Popup_parameter, self.win_one).window_WhetherOpen() # 判断预期窗口是否出现 ControlOperationSuite_Aercheck(None).select_AllowableCurve( str_coord) elif Popup_type == "选择校核工况" or Popup_type == "选择优化工况": # 操作弹窗套件 Check_winControl(Popup_type, self.win_one).window_WhetherOpen() # 判断选择校核工况是否出现 ControlOperationSuite_Aercheck(None).select_workingCondition( Popup_type) elif Popup_type == "选择结构单元": # 操作弹窗套件 time.sleep(0.3) self.win_one.click_input() KeyboardMouse().selectionModel() # 选择结构单元 else: print("被操作的套件名称不存在,套件名称为:", Popup_type, __file__, sys._getframe().f_lineno) sys.exit(0)
def select_AllowableCurve(self,str_coord): """ 材料信息--定义复合材料参数--拉伸、压缩、剪切对应的增加按钮 选择材料许用值曲线 :return: """ list_AfterParsing = str_coord.split(";") coord_X = int(list_AfterParsing[0]) coord_Y = int(list_AfterParsing[1]) # 连接“选择材料许用值曲线”弹窗 app_window = BeingMeasured_popupWin("选择材料许用值曲线").menu_LetsGoTopopover() dlg_spec=app_window.child_window(title="GridWindow", class_name="wxWindowNR") # 勾选数据 dlg_spec.double_click_input(coords=(coord_X, coord_Y), button="left") #钮 数据勾选完毕点击“确认”按 app_window.确认.click_input() # 检查“选择材料许用值曲线”窗口是否关闭 Check_winControl("选择材料许用值曲线", "确认").popUp_Whether_close()
def workField_fastenerSEO(self, operationWindow_son): """ 紧固件优化->紧固件参数优化 :return: """ from tool import Check_winControl from src.utils.OperatingControls.moduleControlOperation import OperatingControls dlg_spec = self.workField.材料许用值曲线表_wx_SysTabCtl32 self.win_one = dlg_spec.panelwxWindowNR0 if operationWindow_son == "编辑材料许用值曲线弹窗": dlg_spec = OperatingControls(self.win_one).ExpressionAssembly( "Button1") # 在编辑材料许用值工作栏点击“创建材料许用值曲线”按钮 Check_winControl("编辑材料许用值曲线", dlg_spec).window_WhetherOpen() # 判断预期窗口是否出现 self.win_one = BeingMeasured_popupWin( "编辑材料许用值曲线").menu_LetsGoTopopover() # 切换到“编辑材料许用值曲线弹窗”中 self.win_two = self.win_one.child_window( title="GridWindow", class_name="wxWindowNR") # 切换到网格窗口 return self.win_one, self.win_two
def select_workingCondition(self,title_name): """ 在工作栏中选择工况 :return: """ hwnd = win32gui.FindWindow(None, title_name) app = Application().connect(handle=hwnd,timeout=20) # 连接校核工况弹窗 dlg_spec = app.window(handle=hwnd) # dlg_spec.print_control_identifiers() txt=dlg_spec.ComboBox.window_text() # 检查是否已经有工况组合 if txt: # 如果txt不为空,说明有工况组合数据 dlg1_spec=dlg_spec.RadioButton2 Check_winControl(None,dlg1_spec).Verify_CheckBox_Status() # 点击工况组合选中工况组合 Check_winControl(title_name,"确认").popUp_Whether_close() else: # 如果txt为空,说明没有工况组合数据,就增加数据 dlg1_spec = dlg_spec.RadioButton3 Check_winControl(None,dlg1_spec).Verify_CheckBox_Status() # 点击工况组合选中工况组合 dlg2_spec = dlg_spec.Edit2 Check_winControl(None, dlg2_spec).Verify_inputBox("all") dlg3_spec = dlg_spec.新建工况组合Button Check_winControl(None, dlg3_spec).Verify_CheckBox_Status() # 点击工况组合选中工况组合 Check_winControl(title_name, "确认").popUp_Whether_close()
from tool import Check_winControl title = "Aerobook-Aerocheck" Check_winControl(title).examine_LocatedModule()
def console(self, Silverlight, argument): """ 操作控件控制台 每次循环就是操作一次控件 :param Silverlight: 控件的属性,例如:唯一标识、操作方法等 :param argument: 控件输入参数和需不要操作 :return: """ print("\033[0;32;33m《进入操作控件函数开始操作控件》\033[0m", __file__, sys._getframe().f_lineno) print(" ") location = argument["被测程序文件地址"] # 在用例字典中取出跟属性方法字典中相同键的键值 Controls_v = FormatConversion().takeOut_dict_SameKey( Silverlight, argument) # 循环取出“控件属性已经操作方法”内的数据 for UseCase_ControlsName, UseCase_Controlsvalue in Controls_v.items( ): # 在用例中循环取出控件的名称 if UseCase_ControlsName in Silverlight: # 在控件属性字典中取出控件的属性 attribute_ControlsName = Silverlight[UseCase_ControlsName] print( "\033[0;34m开始操作控件:%r 用例的值:%r\033[0m" % (UseCase_ControlsName, UseCase_Controlsvalue), __file__, sys._getframe().f_lineno) if UseCase_Controlsvalue != "默认": # 当该控件的用例值为“默认”,就不做任何操作 # 取出控件的操作属性 ControlTypes = attribute_ControlsName["控件类型"] operateWin = attribute_ControlsName["所操作控件窗口"] Controlmethod = attribute_ControlsName["唯一标识方法"] discern = attribute_ControlsName["唯一标识"] waitingTime = attribute_ControlsName["操作控件后等待时间"] Control_mode = attribute_ControlsName["唯一标识方法"] # 获取操作的控件的所在窗口 ControlWin = OperatingControls( self.win_one, self.win_two, self.win_three, self.win_four).acquire_controlWin(operateWin) # 获取操作控件的唯一标识 dlg_spec = OperatingControls( ControlWin).IdentificationMethod( Controlmethod, discern) # 具体的操作控件 if ControlTypes == "文本框": # 当控件是文本框的时候 if "][" in str( UseCase_Controlsvalue ): # 当输入的参数中有“][”符号,代表此文本框为路径文本框,并且需要拼接路径 list_operational = UseCase_Controlsvalue.split( "][") UseCase_Controlsvalue = list_operational[0] UseCase_Controlsvalue = location + UseCase_Controlsvalue # 拼接路径 Check_winControl(None, dlg_spec).Verify_inputBox( UseCase_Controlsvalue) # 向文本框中输入数据 print("在控件”%r“文本框中输入:%r" % (UseCase_ControlsName, UseCase_Controlsvalue)) elif ControlTypes == "勾选框" or ControlTypes == "单选框" or ControlTypes == "复选框": Check_winControl(None, dlg_spec).Verify_CheckBox_Status( UseCase_Controlsvalue) print("控件%r成功勾选" % UseCase_ControlsName) elif ControlTypes == "按钮": dlg_spec.click_input() print("控件”%r“按钮点击成功" % UseCase_ControlsName) elif ControlTypes == "按钮--弹窗套件": # 操作套件 OperatingControls(dlg_spec).button_popUp( attribute_ControlsName, location) print( "控件%r按钮点击后,成功弹出“%r”弹窗" % (UseCase_ControlsName, attribute_ControlsName["套件参数一"]), __file__, sys._getframe().f_lineno) elif ControlTypes == "坐标--单击--文本框": OperatingControls(ControlWin).coord_click_textbox( attribute_ControlsName, UseCase_Controlsvalue) print( "控件%r坐标选择正确,并且在文本框中正确输入数据" % UseCase_ControlsName, __file__, sys._getframe().f_lineno) elif ControlTypes == "坐标--双击--弹窗套件": OperatingControls(ControlWin).coord_dblclick_popUp( attribute_ControlsName, UseCase_Controlsvalue) print("控件%r操作成功" % UseCase_ControlsName, __file__, sys._getframe().f_lineno) elif ControlTypes == "坐标--三击--文本框": OperatingControls(ControlWin).coord_click_textbox( attribute_ControlsName, UseCase_Controlsvalue) print("控件%r操作成功" % UseCase_ControlsName, __file__, sys._getframe().f_lineno) elif ControlTypes == "坐标--键盘--文本框": OperatingControls(ControlWin).coord_click_textbox( attribute_ControlsName, UseCase_Controlsvalue) print("控件%r操作成功" % UseCase_ControlsName, __file__, sys._getframe().f_lineno) elif ControlTypes == "下拉框": if Control_mode == "方式二": Check_winControl( None, dlg_spec).Verify_dropDownBox_change( UseCase_Controlsvalue) else: Check_winControl(None, dlg_spec).Verify_dropDownBox( UseCase_Controlsvalue) print("控件%r下拉框选择数据成功" % UseCase_ControlsName, __file__, sys._getframe().f_lineno) elif ControlTypes == "滚动鼠标": OperatingControls(dlg_spec).scrollMouse() else: raise MyException("说明控件属性") if type(waitingTime) == int or type(waitingTime) == float: time.sleep(waitingTime) else: print( "不操作控件“%r”:%r" % (UseCase_ControlsName, UseCase_Controlsvalue), __file__, sys._getframe().f_lineno) else: print("\033[0;34m不操作控件“%r”\033[0m" % UseCase_ControlsName, __file__, sys._getframe().f_lineno) print(" ") print("\033[0;32;35m{{控件操作完成}} \033[0m", __file__, sys._getframe().f_lineno) print(" ") print(" ")