def open_waveApps(self): #open waveApps,wait for 3 seconds try: win32api.ShellExecute(0, 'open', WAVEApps_EXE_PATH, '', '', 1) print "open waveApps" time.sleep(3) except: print 'open waveApps error' log_public(ERR_NO_0005) self.m_ERROR_MSG = ERR_NO_0005 return False ''' #find handle for the waveApps window hwnd2 = win32gui.FindWindow(WAVEApps_CLASS,'IxVeriwave WaveApps Main Page') print 'hwnd2',hwnd2 #move window of 'IxVeriwave WaveApps Main Page' to top left corner win32gui.MoveWindow(hwnd2,0,0,626,270,1) time.sleep(0.5) #click button -- 'wired and wireless testing' self.myobj.Mouse_LB_D(str_app = WAVEApps_CLASS,lb_dx = '238',lb_dy = '165',Flag = '1') time.sleep(0.5) #click button -- 'wired only testing' #self.myobj.Mouse_LB_D(str_app='QWidget',lb_dx='426',lb_dy='166',Flag='1') #click button -- 'apply' self.myobj.Mouse_LB_D(str_app = WAVEApps_CLASS,lb_dx = '305',lb_dy = '240',Flag = '1') ''' return True
def KillMoreMark(self, strCheck, strEnd): myFindCheck = strCheck bFindMore = True idx = 0 try: while bFindMore == True: if myFindCheck.find(KEY_MORE) >= 0: self.m_COMhld.write(KEY_TAB) myFindCheck = self.m_COMhld.read(1024) print myFindCheck idx += 1 elif myFindCheck.find(strEnd) == -1: self.m_COMhld.write(KEY_RT) myFindCheck = self.m_COMhld.read(1024) print myFindCheck idx += 1 else: bFindMore = False except: log_public(KEY_SER_ERROR_004 + strEnd) #not find string,set error. self.m_ERROR_MSG = KEY_SER_ERROR_004 + strEnd return False print "idx", idx
def dialogEventStart(self,strOperate): strTemp = strOperate strTempWnd = '' strTempBtn = '' strTemp = strTemp[strTemp.find('$')+1:len(strTemp)] if strTemp.find('&&') == -1: return False strTempWnd = strTemp[0:strTemp.find('&&')] strTempWnd = strTempWnd[strTempWnd.find('=')+1:len(strTempWnd)] log_public(strTempWnd) strTempBtn = strTemp[strTemp.find('&&')+2:len(strTemp)] strTempBtn = strTempBtn[strTempBtn.find('=')+1:len(strTempBtn)] nTime = 1 aWindow = 0 clickCancel = cModalPopUp.handlePopup('Confirm',strTempBtn) clickCancel.popupName = strTempWnd clickCancel.start() return clickCancel
def init_PDF(self): try: hwnd1 = win32gui.FindWindow(PDF_CLASS, None) except: log_public(ERR_NO_0003) self.m_ERROR_MSG = ERR_NO_0003 hwnd1 = 0 print 'hwnd1:', hwnd1 while hwnd1 != 0: #close PDF window time.sleep(2) win32gui.PostMessage(hwnd1, win32con.WM_SYSCOMMAND, win32con.SC_CLOSE, 0) print 'close_PDF' try: hwnd1 = win32gui.FindWindow(PDF_CLASS, None) print 'new hwnd1---', hwnd1 except: log_public(ERR_NO_0004) self.m_ERROR_MSG = ERR_NO_0004 hwnd1 = 0 print 'new hwnd1:', hwnd1 else: print 'hwnd1=0,init_PDF has been done' return True
def dialogEventStart(self, strOperate): strTemp = strOperate strTempWnd = '' strTempBtn = '' strTemp = strTemp[strTemp.find('$') + 1:len(strTemp)] if strTemp.find('&&') == -1: return False strTempWnd = strTemp[0:strTemp.find('&&')] strTempWnd = strTempWnd[strTempWnd.find('=') + 1:len(strTempWnd)] log_public(strTempWnd) strTempBtn = strTemp[strTemp.find('&&') + 2:len(strTemp)] strTempBtn = strTempBtn[strTempBtn.find('=') + 1:len(strTempBtn)] nTime = 1 aWindow = 0 clickCancel = cModalPopUp.handlePopup('Confirm', strTempBtn) clickCancel.popupName = strTempWnd clickCancel.start() return clickCancel
def init_PDF(self): try: hwnd1 = win32gui.FindWindow(PDF_CLASS,None) except: log_public(ERR_NO_0003) self.m_ERROR_MSG = ERR_NO_0003 hwnd1 = 0 print 'hwnd1:',hwnd1 while hwnd1 != 0: #close PDF window time.sleep(2) win32gui.PostMessage(hwnd1, win32con.WM_SYSCOMMAND, win32con.SC_CLOSE, 0); print 'close_PDF' try: hwnd1 = win32gui.FindWindow(PDF_CLASS,None) print 'new hwnd1---',hwnd1 except: log_public(ERR_NO_0004) self.m_ERROR_MSG = ERR_NO_0004 hwnd1 = 0 print 'new hwnd1:',hwnd1 else: print 'hwnd1=0,init_PDF has been done' return True
def mycommand(self,SENDSTR,WAITSTR,TIMEOUTSTR='20'): myTIMEOUT = string.atoi(TIMEOUTSTR) #string to int timeCount = 0 if self.m_COMhld == None : return False try: while timeCount < myTIMEOUT: print 'mycommand read wait' strRead = self.m_COMhld.read(10240) #read serial information,read 1024bytes a time. print strRead if strRead.find(WAITSTR) >=0: #find string you waiting for. self.m_COMhld.write(SENDSTR+KEY_RT) # if find success,then send you are command return True else: self.m_COMhld.write(KEY_RT) #if not find,send return,wait 1 second,read next data. timeCount += 1 time.sleep(0.5) continue except: log_public(KEY_SER_ERROR_004+SENDSTR) #not find string,set error. self.m_ERROR_MSG = KEY_SER_ERROR_004+SENDSTR return False log_public(KEY_SER_ERROR_002+SENDSTR) #not find string,set error. self.m_ERROR_MSG = KEY_SER_ERROR_002+SENDSTR return False
def open_waveQoE(self): #open waveQoE,wait for 3 seconds try: win32api.ShellExecute(0,'open',WAVEQOE_EXE_PATH,'','',1) print "open waveQoE" time.sleep(3) except: print 'open waveQoE error' log_public(ERR_NO_0005) self.m_ERROR_MSG = ERR_NO_0005 return False #find handle for the waveQoE window hwnd2 = win32gui.FindWindow(WAVEQOE_CLASS,'IxVeriwave WaveQoE Main Page') print 'hwnd2',hwnd2 #move window of 'IxVeriwave WaveQoE Main Page' to top left corner win32gui.MoveWindow(hwnd2,0,0,626,270,1) time.sleep(0.5) #click button -- 'wired and wireless testing' self.myobj.Mouse_LB_D(str_app = WAVEQOE_CLASS,lb_dx = '238',lb_dy = '165',Flag = '1') time.sleep(0.5) #click button -- 'wired only testing' #self.myobj.Mouse_LB_D(str_app='QWidget',lb_dx='426',lb_dy='166',Flag='1') #click button -- 'apply' self.myobj.Mouse_LB_D(str_app = WAVEQOE_CLASS,lb_dx = '305',lb_dy = '240',Flag = '1') return True
def find_command(self,SENDSTR,WAITSTR,FINDSTR,TIMEOUT=10,RESENDFLAG=True): bstrEND = False bRet = False strMyFind = "" #temp storage information bRet = self.mycommand(SENDSTR,WAITSTR,TIMEOUT) if bRet == False: return False try: #check find string. while bstrEND == False: strMyFind = self.m_COMhld.read(1024) #read serial information,read 1024bytes a time. print strMyFind if strMyFind.find(FINDSTR) >=0: #find string you waiting for. self.KillMoreMark(strMyFind,WAITSTR) # kill ---more--- return True else: if strMyFind.find(WAITSTR) >=0: bstrEND = True self.m_COMhld.write(KEY_RT) #if not find,send return,wait 1 second,read next data. continue except: log_public(KEY_SER_ERROR_004+SENDSTR) #not find string,set error. m_ERROR_MSG = KEY_SER_ERROR_004+SENDSTR return False log_public(KEY_SER_ERROR_003+FINDSTR) #not find string,set error. m_ERROR_MSG = KEY_SER_ERROR_003+FINDSTR return True
def ReadWebPgURL(self, obj_table, dctCurNode, lst): strNextNode = '' myURL = '' row = dctCurNode[KEY_ROW] col = dctCurNode[KEY_COL] #Get Keyword URL myURL = obj_table.cell(row + 1, col).value myURL.strip() #check Keyword URL if cmp(myURL, KEY_URL) == -1: log_public(ERR_EXCEL_URL_0002) self.m_ERROR_MSG = ERR_EXCEL_URL_0002 return False #Get URL Value myURLValue = obj_table.cell(row + 1, col + 1).value myURLValue.strip() #test value.can not be empty. if myURLValue == '': log_public(ERR_EXCEL_URL_VALUE_0007) self.m_ERROR_MSG = ERR_EXCEL_URL_VALUE_0007 return False dct_URL = {KEY_URL: myURLValue} lst.append(dct_URL) #get NextNode strNextNode = obj_table.cell(row, col + 3).value return strNextNode
def find_command(self,SENDSTR,WAITSTR,FINDSTR,TIMEOUT='10',RESENDFLAG=True): bstrEND = False bRet = False strMyFind = "" #temp storage information bRet = self.mycommand(SENDSTR,WAITSTR,TIMEOUT) if bRet == False: return False try: #check find string. while bstrEND == False: strMyFind = self.m_COMhld.read(1024) #read serial information,read 1024bytes a time. print strMyFind if strMyFind.find(FINDSTR) >=0: #find string you waiting for. self.KillMoreMark(strMyFind,WAITSTR) # kill ---more--- return True else: if strMyFind.find(WAITSTR) >=0: bstrEND = True self.m_COMhld.write(KEY_RT) #if not find,send return,wait 1 second,read next data. continue except: log_public(KEY_SER_ERROR_004+SENDSTR) #not find string,set error. self.m_ERROR_MSG = KEY_SER_ERROR_004+SENDSTR return False log_public(KEY_SER_ERROR_003+FINDSTR) #not find string,set error. self.m_ERROR_MSG = KEY_SER_ERROR_003+FINDSTR return False
def setWebPage(self, filePath, FlowName, bCA): myPath = filePath lst = [] obj_book = 0 obj_table = 0 LOOPMAX = 0 shttName = '' ret = 0 #return value form function obj_book = self.OpenFile(myPath) for sheet_name in obj_book.sheet_names(): if sheet_name == u'0-ACPAGE': obj_table = obj_book.sheet_by_name(sheet_name) break if obj_table == 0: log_public(ERR_TABLE_OPENFAIL_0011) self.m_ERROR_MSG = ERR_TABLE_OPENFAIL_0011 return False #while loop bNeedReadHead = True NEXTNODE = True myDictNodeCur = {'rowx': '', 'coly': ''} myDictNodeNext = {'rowx': '', 'coly': ''} dct_Cell = {} #dicitionary while NEXTNODE == True: #read START if bNeedReadHead == True: if self.ReadFlowHeader(obj_table, FlowName, myDictNodeNext) == False: return False bNeedReadHead = False if (myDictNodeNext[KEY_ROW] == -1) & (myDictNodeNext[KEY_COL] == -1): NEXTNODE = False continue myDictNodeCur.update(myDictNodeNext) #read Page if self.ReadFlowPage(obj_table, myDictNodeCur, myDictNodeNext, lst) == False: return False if (myDictNodeNext[KEY_ROW] == -1) & (myDictNodeNext[KEY_COL] == -1): NEXTNODE = False continue print lst #need dele if self.OperateACWebPage(bCA, lst) == False: return False del lst return True
def serial_open(self): try: self.m_COMhld = serial.Serial( self.m_strMyPort, self.m_strMybaudrate, bytesize=8, # number of data bits parity='N', # enable parity checking stopbits=1, # number of stop bits timeout=1, # set a timeout value, None to wait forever xonxoff=False, # enable software flow control rtscts=False, # enable RTS/CTS flow control writeTimeout=None, # set a timeout for writes dsrdtr=False, # None: use rtscts setting, dsrdtr override if True or False interCharTimeout=None # Inter-character timeout, None to disable ) except: log_public(KEY_SER_ERROR_001+KEY_COM+self.m_strMyPort) self.m_ERROR_MSG = KEY_SER_ERROR_001+KEY_COM+self.m_strMyPort return None #print self.m_COMhld.portstr #delete self.m_COMhld.write(KEY_RT) self.m_COMhld.write(KEY_RT)
def KillMoreMark(self,strCheck,strEnd): myFindCheck = strCheck bFindMore = True idx = 0 try: while bFindMore == True: if myFindCheck.find(KEY_MORE) >= 0: self.m_COMhld.write(KEY_TAB) myFindCheck = self.m_COMhld.read(1024) print myFindCheck idx += 1 elif myFindCheck.find(strEnd) == -1: self.m_COMhld.write(KEY_RT) myFindCheck = self.m_COMhld.read(1024) print myFindCheck idx += 1 else: bFindMore = False except: log_public(KEY_SER_ERROR_004+strEnd) #not find string,set error. self.m_ERROR_MSG = KEY_SER_ERROR_004+strEnd return False print "idx",idx
def checkPageIsBusy(self,driver): print 'checkPageIsBusy fuction' time.sleep(1) strName = str(driver.page_source) ''' try: strName = ie.outerHTML() except Exception,str: log_print('outerHTML is except') log_print(str) return True ''' time.sleep(1) #log_public(strName) if strName.find("HTTP 500") >= 0: driver.back() time.sleep(3) log_public( "HTTP 500,Error") return True elif strName.find("<BODY></BODY>") >= 0: driver.back() time.sleep(3) log_public( "HTTP BLANK,Error") return True return False
def OpenFile(self,filePath): try: obj_book = xlrd.open_workbook(filePath) return obj_book except: log_public(ERR_FILE_OPENFAIL_0001) self.m_ERROR_MSG = ERR_FILE_OPENFAIL_0001
def ReadWebPgURL(self,obj_table,dctCurNode,lst): strNextNode = '' myURL ='' row = dctCurNode[KEY_ROW] col = dctCurNode[KEY_COL] #Get Keyword URL myURL = obj_table.cell(row+1,col).value myURL.strip() #check Keyword URL if cmp(myURL,KEY_URL) == -1: log_public( ERR_EXCEL_URL_0002) self.m_ERROR_MSG = ERR_EXCEL_URL_0002 return False #Get URL Value myURLValue = obj_table.cell(row+1,col+1).value myURLValue.strip() #test value.can not be empty. if myURLValue =='': log_public(ERR_EXCEL_URL_VALUE_0007) self.m_ERROR_MSG = ERR_EXCEL_URL_VALUE_0007 return False dct_URL = {KEY_URL:myURLValue} lst.append(dct_URL) #get NextNode strNextNode = obj_table.cell(row,col+3).value return strNextNode
def mycommand(self,SENDSTR,WAITSTR,TIMEOUTSTR): myTIMEOUT = string.atoi(TIMEOUTSTR) #string to int timeCount = 0 if self.m_COMhld == None : return False try: while timeCount < myTIMEOUT: strRead = self.m_COMhld.read(1024) #read serial information,read 1024bytes a time. print strRead if strRead.find(WAITSTR) >=0: #find string you waiting for. self.m_COMhld.write(SENDSTR+KEY_RT) # if find success,then send you are command return True else: self.m_COMhld.write(KEY_RT) #if not find,send return,wait 1 second,read next data. timeCount += 1 time.sleep(0.5) continue except: log_public(KEY_SER_ERROR_004+SENDSTR) #not find string,set error. m_ERROR_MSG = KEY_SER_ERROR_004+SENDSTR return False log_public(KEY_SER_ERROR_002+SENDSTR) #not find string,set error. m_ERROR_MSG = KEY_SER_ERROR_002+SENDSTR return True
def OpenFile(self, filePath): try: obj_book = xlrd.open_workbook(filePath) return obj_book except: log_public(ERR_FILE_OPENFAIL_0001) self.m_ERROR_MSG = ERR_FILE_OPENFAIL_0001
def __init__(self,port = "1", baudrate="115200",Platf = "M"): myPort = string.atoi(port) - 1 mybaudrate = string.atoi(baudrate) self.result =False try: self.m_COMhld = serial.Serial( myPort, mybaudrate, bytesize=8, # number of data bits parity='N', # enable parity checking stopbits=1, # number of stop bits timeout=1, # set a timeout value, None to wait forever xonxoff=False, # enable software flow control rtscts=False, # enable RTS/CTS flow control writeTimeout=None, # set a timeout for writes dsrdtr=False, # None: use rtscts setting, dsrdtr override if True or False interCharTimeout=None # Inter-character timeout, None to disable ) self.result = True except: log_public(KEY_SER_ERROR_001+KEY_COM+port) m_ERROR_MSG = KEY_SER_ERROR_001+KEY_COM+port self.result =False return None #print self.m_COMhld.portstr #delete self.m_COMhld.write(KEY_RT) self.m_COMhld.write(KEY_RT)
def serial_open(self): try: self.m_COMhld = serial.Serial( self.m_strMyPort, self.m_strMybaudrate, bytesize=8, # number of data bits parity='N', # enable parity checking stopbits=1, # number of stop bits timeout=1, # set a timeout value, None to wait forever xonxoff=False, # enable software flow control rtscts=False, # enable RTS/CTS flow control writeTimeout=None, # set a timeout for writes dsrdtr= False, # None: use rtscts setting, dsrdtr override if True or False interCharTimeout=None # Inter-character timeout, None to disable ) except: log_public(KEY_SER_ERROR_001 + KEY_COM + self.m_strMyPort) self.m_ERROR_MSG = KEY_SER_ERROR_001 + KEY_COM + self.m_strMyPort return None #print self.m_COMhld.portstr #delete self.m_COMhld.write(KEY_RT) self.m_COMhld.write(KEY_RT)
def close_waveApps(self): #get the handle of waveApps window. try: hwnd6 = win32gui.FindWindow(WAVEApps_CLASS, None) print 'hwnd6:', hwnd6 time.sleep(1) #set the waveApps window to the top. win32gui.SetForegroundWindow(hwnd6) time.sleep(1) except: print 'close error' log_public(ERR_NO_0009) self.m_ERROR_MSG = ERR_NO_0009 return False #click the title bar. #self.myobj.Mouse_LB_D(str_app = WAVEApps_CLASS,lb_dx = '75',lb_dy = '10',Flag = '1') #send Alt+F to open 'File' in menu bar. win32api.Sleep(1000) win32api.keybd_event(18, 0, 0, 0) #18��Alt�ļ��� win32api.keybd_event(70, 0, 0, 0) #70��F�ļ��� win32api.Sleep(1000) win32api.keybd_event(70, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.Sleep(1000) #send X to close waveApps window. win32api.keybd_event(88, 0, 0, 0) #88��X�ļ��� win32api.Sleep(1000) win32api.keybd_event(88, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.Sleep(1000) if self.timeout == 1: #send Alt+Y to exit waveApps without save. win32api.keybd_event(18, 0, 0, 0) #18��Alt�ļ��� win32api.keybd_event(89, 0, 0, 0) #89��Y�ļ��� win32api.Sleep(1000) win32api.keybd_event(89, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.Sleep(1000) else: #send Alt+N to exit waveApps without save. win32api.keybd_event(18, 0, 0, 0) #18��Alt�ļ��� win32api.keybd_event(78, 0, 0, 0) #78��N�ļ��� win32api.Sleep(1000) win32api.keybd_event(78, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.Sleep(1000) return True
def setWebPage(self,filePath,FlowName,bCA): myPath = filePath lst = [] obj_book = 0 obj_table = 0 LOOPMAX = 0 shttName ='' ret = 0 #return value form function obj_book = self.OpenFile(myPath) for sheet_name in obj_book.sheet_names(): if sheet_name == u'0-ACPAGE' : obj_table = obj_book.sheet_by_name(sheet_name) break if obj_table == 0 : log_public(ERR_TABLE_OPENFAIL_0011) self.m_ERROR_MSG = ERR_TABLE_OPENFAIL_0011 return False #while loop bNeedReadHead = True NEXTNODE = True myDictNodeCur = {'rowx':'','coly':''} myDictNodeNext = {'rowx':'','coly':''} dct_Cell={} #dicitionary while NEXTNODE == True: #read START if bNeedReadHead == True: if self.ReadFlowHeader(obj_table,FlowName,myDictNodeNext) == False: return False bNeedReadHead = False if (myDictNodeNext[KEY_ROW] == -1) & ( myDictNodeNext[KEY_COL] == -1): NEXTNODE = False continue myDictNodeCur.update(myDictNodeNext) #read Page if self.ReadFlowPage(obj_table,myDictNodeCur,myDictNodeNext,lst) == False: return False if (myDictNodeNext[KEY_ROW] == -1) & (myDictNodeNext[KEY_COL] == -1): NEXTNODE = False continue print lst #need dele if self.OperateACWebPage(bCA,lst) == False: return False del lst return True
def operate_report(self): #record start time of the test. time_start = time.time() print 'time_start:', time_start #get handle of PDF window,hwnd5=0 means there is not any PDF window. try: hwnd5 = win32gui.FindWindow(PDF_CLASS, None) except: log_public(ERR_NO_0007) self.m_ERROR_MSG = ERR_NO_0007 hwnd5 = 0 print 'hwnd5:', hwnd5 #loop to check whether the result pdf is created. #hwnd5 == 0 means the result pdf is not created,else created. while hwnd5 == 0: #check hwnd5 every 10 seconds. time.sleep(10) #timeout judgement time_current = time.time() loop_time = time_current - time_start print 'loop_time', loop_time wait_time = string.atoi(self.my_wait_time) if loop_time <= wait_time: self.timeout = 0 print 'timeout = 0,no timeout' else: self.timeout = 1 print 'timeout = 1,timeout!' break #check hwnd5. try: hwnd5 = win32gui.FindWindow(PDF_CLASS, None) except: log_public(ERR_NO_0008) self.m_ERROR_MSG = ERR_NO_0008 hwnd5 = 0 print 'new_hwnd5:', hwnd5 else: print 'pdf is created.' #close PDF window time.sleep(3) win32gui.PostMessage(hwnd5, win32con.WM_SYSCOMMAND, win32con.SC_CLOSE, 0) return True
def operate_report(self): #record start time of the test. time_start = time.time() print 'time_start:',time_start #get handle of PDF window,hwnd5=0 means there is not any PDF window. try: hwnd5 = win32gui.FindWindow(PDF_CLASS,None) except: log_public(ERR_NO_0007) self.m_ERROR_MSG = ERR_NO_0007 hwnd5 = 0 print 'hwnd5:',hwnd5 #loop to check whether the result pdf is created. #hwnd5 == 0 means the result pdf is not created,else created. while hwnd5 == 0: #check hwnd5 every 10 seconds. time.sleep(10) #timeout judgement time_current = time.time() loop_time = time_current - time_start print 'loop_time',loop_time wait_time = string.atoi(self.my_wait_time) if loop_time <= wait_time: self.timeout = 0 print 'timeout = 0,no timeout' else: self.timeout = 1 print 'timeout = 1,timeout!' break #check hwnd5. try: hwnd5 = win32gui.FindWindow(PDF_CLASS,None) except: log_public(ERR_NO_0008) self.m_ERROR_MSG = ERR_NO_0008 hwnd5 = 0 print 'new_hwnd5:',hwnd5 else: print 'pdf is created.' #close PDF window time.sleep(3) win32gui.PostMessage(hwnd5, win32con.WM_SYSCOMMAND, win32con.SC_CLOSE, 0); return True
def ping_close(self, filename): try: self.file_edit(filename) except: log_public(ERR_PING_CLOSE_0001) self.m_ERROR_MSG = ERR_PING_CLOSE_0001 return False print 'Close the pingtest software.' self.shortcut_keys(['Alt', 'F4']) return True
def close_waveQoE(self): #get the handle of waveQoE window. try: hwnd6 = win32gui.FindWindow(WAVEQOE_CLASS,None) print 'hwnd6:',hwnd6 time.sleep(1) #set the waveQoE window to the top. win32gui.SetForegroundWindow(hwnd6) time.sleep(1) except: print 'close error' log_public(ERR_NO_0009) self.m_ERROR_MSG = ERR_NO_0009 return False #click the title bar. self.myobj.Mouse_LB_D(str_app = WAVEQOE_CLASS,lb_dx = '75',lb_dy = '10',Flag = '1') #send Alt+F to open 'File' in menu bar. win32api.Sleep(1000) win32api.keybd_event(18,0,0,0); #18��Alt�ļ��� win32api.keybd_event(70,0,0,0); #70��F�ļ��� win32api.Sleep(1000) win32api.keybd_event(70,0,win32con.KEYEVENTF_KEYUP,0); win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0); win32api.Sleep(1000) #send X to close waveQoE window. win32api.keybd_event(88,0,0,0); #88��X�ļ��� win32api.Sleep(1000) win32api.keybd_event(88,0,win32con.KEYEVENTF_KEYUP,0); win32api.Sleep(1000) if self.timeout == 1: #send Alt+Y to exit waveQoE without save. win32api.keybd_event(18,0,0,0); #18��Alt�ļ��� win32api.keybd_event(89,0,0,0); #89��Y�ļ��� win32api.Sleep(1000) win32api.keybd_event(89,0,win32con.KEYEVENTF_KEYUP,0); win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0); win32api.Sleep(1000) else: #send Alt+N to exit waveQoE without save. win32api.keybd_event(18,0,0,0); #18��Alt�ļ��� win32api.keybd_event(78,0,0,0); #78��N�ļ��� win32api.Sleep(1000) win32api.keybd_event(78,0,win32con.KEYEVENTF_KEYUP,0); win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0); win32api.Sleep(1000) return True
def CheckWebPgControl(self,obj_table,dctCurNode): log_print( 'CheckWebPgControl fuction') row = dctCurNode[KEY_ROW]+2 col = dctCurNode[KEY_COL] myASSIST = obj_table.cell(row,col).value myASSIST.strip() myControlType = obj_table.cell(row,col+1).value myControlType.strip() myControlName = obj_table.cell(row,col+2).value myControlName.strip() myControlValue = obj_table.cell(row,col+3).value myControlValue.strip() if cmp(myASSIST,KEY_ASSIST) == -1: log_public(ERR_EXCEL_ASSIST_0003) self.m_ERROR_MSG = ERR_EXCEL_ASSIST_0003 return False if cmp(myControlType,KEY_CONTROLTYPE) == -1: log_public(ERR_EXCEL_CONTROLTYPE_0004) self.m_ERROR_MSG = ERR_EXCEL_CONTROLTYPE_0004 return False if cmp(myControlName,KEY_CONTROLNAME) == -1: log_public( ERR_EXCEL_CONTROLNAME_0005) self.m_ERROR_MSG = ERR_EXCEL_CONTROLNAME_0005 return False if cmp(myControlValue,KEY_CONTROLVALUE) == -1: log_public( ERR_EXCEL_CONTROLVALUE_0006) self.m_ERROR_MSG = ERR_EXCEL_CONTROLVALUE_0006 return False
def CheckWebPgControl(self,obj_table,dctCurNode): row = dctCurNode[KEY_ROW]+2 col = dctCurNode[KEY_COL] myASSIST = obj_table.cell(row,col).value myASSIST.strip() myControlType = obj_table.cell(row,col+1).value myControlType.strip() myControlName = obj_table.cell(row,col+2).value myControlName.strip() myControlValue = obj_table.cell(row,col+3).value myControlValue.strip() if cmp(myASSIST,KEY_ASSIST) == -1: log_public(ERR_EXCEL_ASSIST_0003) self.m_ERROR_MSG = ERR_EXCEL_ASSIST_0003 return False if cmp(myControlType,KEY_CONTROLTYPE) == -1: log_public(ERR_EXCEL_CONTROLTYPE_0004) self.m_ERROR_MSG = ERR_EXCEL_CONTROLTYPE_0004 return False if cmp(myControlName,KEY_CONTROLNAME) == -1: log_public( ERR_EXCEL_CONTROLNAME_0005) self.m_ERROR_MSG = ERR_EXCEL_CONTROLTYPE_0005 return False if cmp(myControlValue,KEY_CONTROLVALUE) == -1: log_public( ERR_EXCEL_CONTROLVALUE_0006) self.m_ERROR_MSG = ERR_EXCEL_CONTROLVALUE_0006 return False
def choose_conf_file(self): #get control of waveQoE window. hwnd3 = win32gui.FindWindow(WAVEQOE_CLASS,None) print 'hwnd3',hwnd3 time.sleep(0.5) #set waveQoE window to top. win32gui.SetForegroundWindow(hwnd3) time.sleep(0.5) #move waveQoE window to top left corner. win32gui.MoveWindow(hwnd3,0,0,1448,878,1) #send Alt+F to open 'File' in menu bar. win32api.Sleep(1000) win32api.keybd_event(18,0,0,0); #18��Alt�ļ��� win32api.keybd_event(70,0,0,0); #70��F�ļ��� win32api.Sleep(1000) win32api.keybd_event(70,0,win32con.KEYEVENTF_KEYUP,0); win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0); win32api.Sleep(1000) #send O to open 'open' window. win32api.keybd_event(79,0,0,0); #79��O�ļ��� win32api.Sleep(1000) win32api.keybd_event(79,0,win32con.KEYEVENTF_KEYUP,0); win32api.Sleep(1000) #choose config file and open it. self.myobj.Find_Gui_edit(str_app = 'Open',control_class = 'ComboBox',filename = self.conf_file_dir,control_name = '',stop_flag = '0') self.myobj.Find_Gui_button(str_app = 'Open',control_class = 'Button',control_name = '��(&O)') time.sleep(0.5) hwnd4 = win32gui.FindWindow('#32770','Open') print 'hwnd4: ',hwnd4 if hwnd4 > 0: log_public(ERR_NO_0006) self.m_ERROR_MSG = ERR_NO_0006 self.myobj.Find_Gui_button(str_app = 'Open',control_class = 'Button',control_name = 'ȷ��') time.sleep(0.5) self.myobj.Find_Gui_button(str_app = 'Open',control_class = 'Button',control_name = 'ȡ��') time.sleep(0.5) self.close_waveQoE() print 'close_waveqoe' return False else: print 'conf_file is correct.' return True
def config_log(self, log_name): print 'Control button: Log File' hwd = win32gui.FindWindow(None, "PingTest") hwd_butten = win32gui.FindWindowEx(hwd, None, 'Button', 'Log File:') #print hwd_butten self.Mouse_LB_click(hwd_butten) self.sleep('1') list_1 = '' sep = '\\' list_1 = log_name.split(sep) list_1.pop() file_name = sep.join(list_1) if os.path.exists(file_name) == False: msg = "Path does not exist not exists , I will help you mkdir this path:" + file_name print msg log_public(msg) os.mkdir(file_name) #log_name为空,用默认log_name if log_name == '': path1 = os.path.abspath(sys.argv[0]) str = path1.split('\\') path_parent = str[0] self.dst = path_parent + '\\result_' log_name = log_name + '_' + time.strftime(KEY_TIME_FORMAT) + '.txt' print 'To save the log to:', log_name try: self.input_msg('6', log_name) except: log_public(ERR_PING_TEST_0003) self.m_ERROR_MSG = ERR_PING_TEST_0003 return False return True
def init_waveQoE(self): try: hwnd0 = win32gui.FindWindow(WAVEQOE_CLASS,None) except: log_public(ERR_NO_0001) self.m_ERROR_MSG = ERR_NO_0001 hwnd0 = 0 print 'hwnd0:',hwnd0 while hwnd0 != 0: self.close_waveQoE() print 'close_waveqoe' try: hwnd0 = win32gui.FindWindow(WAVEQOE_CLASS,None) print 'new hwnd0---',hwnd0 except: log_public(ERR_NO_0002) self.m_ERROR_MSG = ERR_NO_0002 hwnd0 = 0 print 'new hwnd0:',hwnd0 else: print 'hwnd0=0,init_waveQoE has been done' return True
def init_waveQoE(self): try: hwnd0 = win32gui.FindWindow(WAVEQOE_CLASS, None) except: log_public(ERR_NO_0001) self.m_ERROR_MSG = ERR_NO_0001 hwnd0 = 0 print 'hwnd0:', hwnd0 while hwnd0 != 0: self.close_waveQoE() print 'close_waveqoe' try: hwnd0 = win32gui.FindWindow(WAVEQOE_CLASS, None) print 'new hwnd0---', hwnd0 except: log_public(ERR_NO_0002) self.m_ERROR_MSG = ERR_NO_0002 hwnd0 = 0 print 'new hwnd0:', hwnd0 else: print 'hwnd0=0,init_waveQoE has been done' return True
def ReadWebPgControl(self, obj_table, dctCurNode, lst): row = dctCurNode[KEY_ROW] + 3 col = dctCurNode[KEY_COL] nrows = obj_table.nrows timesBlank = 0 for rows in range(row, nrows): dct_Combn = {} mySubASSIST = str(obj_table.cell(rows, col).value) mySubASSIST.strip() if mySubASSIST == KEY_END: return True dct_ASSIST = {KEY_ASSIST: mySubASSIST} dct_Combn.update(dct_ASSIST) mySubControlType = str(obj_table.cell(rows, col + 1).value) mySubControlType.strip() if mySubControlType == '': log_public(ERR_EXCEL_NO_VALUE_0008) self.m_ERROR_MSG = ERR_EXCEL_NO_VALUE_0008 return False dct_CONTROLTYPE = {KEY_CONTROLTYPE: mySubControlType} log_public(dct_CONTROLTYPE) dct_Combn.update(dct_CONTROLTYPE) mySubControlName = str( obj_table.cell(rows, col + 2).value.encode('gb18030')) mySubControlName.strip() if mySubControlName == '': log_public(ERR_EXCEL_CONTROLNAME_VALUE_0010) self.m_ERROR_MSG = ERR_EXCEL_CONTROLNAME_VALUE_0010 return False dct_CONTROLNAME = {KEY_CONTROLNAME: mySubControlName} dct_Combn.update(dct_CONTROLNAME) mySubControlValue = obj_table.cell(rows, col + 3).value if isinstance(mySubControlValue, float) == False & isinstance( mySubControlValue, int) == False: mySubControlValue = obj_table.cell(rows, col + 3).value.encode('gb18030') else: mySubControlValue = str(mySubControlValue) mySubControlValue = mySubControlValue[0:mySubControlValue. find('.')] dct_CONTROLVALUE = {KEY_CONTROLVALUE: mySubControlValue} dct_Combn.update(dct_CONTROLVALUE) lst.append(dct_Combn) del dct_Combn return True
def ReadWebPgControl(self,obj_table,dctCurNode,lst): row = dctCurNode[KEY_ROW]+3 col = dctCurNode[KEY_COL] nrows = obj_table.nrows timesBlank = 0 for rows in range(row,nrows): dct_Combn={} mySubASSIST = str(obj_table.cell(rows,col).value) mySubASSIST.strip() if mySubASSIST == KEY_END: return True dct_ASSIST ={KEY_ASSIST:mySubASSIST} dct_Combn.update(dct_ASSIST) mySubControlType = str(obj_table.cell(rows,col+1).value) mySubControlType.strip() if mySubControlType =='': log_public(ERR_EXCEL_NO_VALUE_0008) self.m_ERROR_MSG = ERR_EXCEL_NO_VALUE_0008 return False dct_CONTROLTYPE= {KEY_CONTROLTYPE:mySubControlType} log_public(dct_CONTROLTYPE) dct_Combn.update(dct_CONTROLTYPE) mySubControlName = str(obj_table.cell(rows,col+2).value.encode('gb18030')) mySubControlName.strip() if mySubControlName =='': log_public(ERR_EXCEL_CONTROLNAME_VALUE_0010) self.m_ERROR_MSG = ERR_EXCEL_CONTROLNAME_VALUE_0010 return False dct_CONTROLNAME = {KEY_CONTROLNAME:mySubControlName} dct_Combn.update(dct_CONTROLNAME) mySubControlValue = obj_table.cell(rows,col+3).value if isinstance(mySubControlValue,float) == False & isinstance(mySubControlValue,int) == False: mySubControlValue = obj_table.cell(rows,col+3).value.encode('gb18030') else: mySubControlValue = str(mySubControlValue) mySubControlValue = mySubControlValue[0:mySubControlValue.find('.')] dct_CONTROLVALUE = {KEY_CONTROLVALUE:mySubControlValue} dct_Combn.update(dct_CONTROLVALUE) lst.append(dct_Combn) del dct_Combn return True
def config_edit(self, ip, packet, interv, count): print 'Input ip value:', ip try: self.input_msg('0', ip) except: log_public(ERR_PING_TEST_0003) self.m_ERROR_MSG = ERR_PING_TEST_0003 return False print 'Input packet value:', packet try: self.input_msg('1', packet) except: log_public(ERR_PING_TEST_0003) self.m_ERROR_MSG = ERR_PING_TEST_0003 return False print 'Input interv value:', interv try: self.input_msg('2', interv) except: log_public(ERR_PING_TEST_0003) self.m_ERROR_MSG = ERR_PING_TEST_0003 return False print 'Input count value:', count try: self.input_msg('4', count) except: log_public(ERR_PING_TEST_0003) self.m_ERROR_MSG = ERR_PING_TEST_0003 return False return True
def omnipeek_save(self,dst): result = False list_1 = '' sep = '\\' list_1 = dst.split(sep) list_1.pop() self.filename = sep.join(list_1) if os.path.exists(self.filename) == False: msg = "Path does not exist not exists , I will help you mkdir this path:"+self.filename print msg log_public(msg) os.mkdir(self.filename) self.dst = dst self.sleep('2') h = win32gui.FindWindow("OmniPeek", None) win32gui.SetForegroundWindow(h) #置顶 self.sleep('5') print 'Begin to save the test results' self.shortcut_keys(['Ctrl','S']) self.sleep('2') hwd = win32gui.FindWindow(None, '另存为') self.sleep('1') #print hwd #判断窗口存在 if hwd: self.flag_save = '1' win32gui.SetForegroundWindow(hwd) edit_list = findControls(hwd,wantedClass='Edit') #print edit_list for x in edit_list: rect_list = win32gui.GetWindowRect(x) t_dx = rect_list[2]-rect_list[0] t_dy = rect_list[3]-rect_list[1] t_tuple = (t_dx ,t_dy) if t_tuple ==(224,13): self.t_hwnd = x break if self.t_hwnd == 0: h = win32gui.FindWindowEx(hwd, None, 'Button', '取消') self.Mouse_LB_click(h) result = False #dst为空,用默认dst if self.dst == '': path1 = os.path.abspath(sys.argv[0]) str=path1.split('\\') path_parent=str[0] self.dst=path_parent +'\\result_' self.tmp_file = self.dst +'_'+time.strftime(KEY_TIME_FORMAT) print 'To save test results to:',self.tmp_file try: setEditText(self.t_hwnd,self.tmp_file) except: log_public(ERR_SAVE_RESULT_SETEDITTEXT_0004) self.m_ERROR_MSG = ERR_SAVE_RESULT_SETEDITTEXT_0004 result = False self.sleep('1') print 'Input the file name is successful, click save' self.shortcut_keys(['Alt','S']) #点击保存按钮 self.sleep('2') result = True else: print 'No test results can be saved' result = True return result
def omnipeek_save(self, dst): result = False list_1 = '' sep = '\\' list_1 = dst.split(sep) list_1.pop() self.filename = sep.join(list_1) if os.path.exists(self.filename) == False: msg = "Path does not exist not exists , I will help you mkdir this path:" + self.filename print msg log_public(msg) os.mkdir(self.filename) self.dst = dst self.sleep('2') h = win32gui.FindWindow("OmniPeek", None) win32gui.SetForegroundWindow(h) #置顶 self.sleep('5') print 'Begin to save the test results' self.shortcut_keys(['Ctrl', 'S']) self.sleep('2') hwd = win32gui.FindWindow(None, '另存为') self.sleep('1') #print hwd #判断窗口存在 if hwd: self.flag_save = '1' win32gui.SetForegroundWindow(hwd) edit_list = findControls(hwd, wantedClass='Edit') #print edit_list for x in edit_list: rect_list = win32gui.GetWindowRect(x) t_dx = rect_list[2] - rect_list[0] t_dy = rect_list[3] - rect_list[1] t_tuple = (t_dx, t_dy) if t_tuple == (224, 13): self.t_hwnd = x break if self.t_hwnd == 0: h = win32gui.FindWindowEx(hwd, None, 'Button', '取消') self.Mouse_LB_click(h) result = False #dst为空,用默认dst if self.dst == '': path1 = os.path.abspath(sys.argv[0]) str = path1.split('\\') path_parent = str[0] self.dst = path_parent + '\\result_' self.tmp_file = self.dst + '_' + time.strftime(KEY_TIME_FORMAT) print 'To save test results to:', self.tmp_file try: setEditText(self.t_hwnd, self.tmp_file) except: log_public(ERR_SAVE_RESULT_SETEDITTEXT_0004) self.m_ERROR_MSG = ERR_SAVE_RESULT_SETEDITTEXT_0004 result = False self.sleep('1') print 'Input the file name is successful, click save' self.shortcut_keys(['Alt', 'S']) #点击保存按钮 self.sleep('2') result = True else: print 'No test results can be saved' result = True return result
def file_edit(self, filename): try: packet_msg = self.get_msg('11') except: log_public(ERR_PING_TEST_0004) self.m_ERROR_MSG = ERR_PING_TEST_0004 return False print 'Get the packet message:', packet_msg try: min_msg = self.get_msg('12') except: log_public(ERR_PING_TEST_0004) self.m_ERROR_MSG = ERR_PING_TEST_0004 return False print 'Get the min message:', min_msg try: max_msg = self.get_msg('13') except: log_public(ERR_PING_TEST_0004) self.m_ERROR_MSG = ERR_PING_TEST_0004 return False print 'Get the max message:', max_msg try: avg_msg = self.get_msg('14') except: log_public(ERR_PING_TEST_0004) self.m_ERROR_MSG = ERR_PING_TEST_0004 return False print 'Get the avg message:', avg_msg list_1 = '' sep = '\\' list_1 = filename.split(sep) list_1.pop() file_name = sep.join(list_1) if os.path.exists(file_name) == False: msg = "Path does not exist not exists , I will help you mkdir this path:" + file_name print msg log_public(msg) os.mkdir(file_name) #filename为空,用默认filename if filename == '': path1 = os.path.abspath(sys.argv[0]) string = path1.split('\\') path_parent = string[0] filename = path_parent + '\\result_' tmp_file = filename + '_' + time.strftime(KEY_TIME_FORMAT) + '.txt' print 'To save the results to:', tmp_file file = open(tmp_file, 'w') list_text = 'Packet:', packet_msg, 'Min:', min_msg, 'Max:', max_msg, 'Avg:', avg_msg #print list_text list_text_str = str(list_text) print 'The file content:', list_text_str file.write(list_text_str) file.close() return True
def omnipeek_start(self, path, networkCard_Flag, channel, timesleep): print 'Open the omnipeek application software' try: self.startapp(path) except: #log_public(ERR_OMNIPEEK_START_STARTAPP_0001) self.m_ERROR_MSG = ERR_OMNIPEEK_START_STARTAPP_0001 return False self.sleep('18') ''' print 'To maximize the window' try: self.shortcut_keys(['Alt','Spacebar','X']) except Exception ,exc_str: print(exc_str) print 'Window to maximize success' return False ''' self.sleep('1') hwnd0 = win32gui.FindWindow("OmniPeek", 'OmniPeek - [Start Page]') win32gui.SetForegroundWindow(hwnd0) self.sleep('1') print 'Click on the New Capture' self.shortcut_keys(['Ctrl', 'N']) self.sleep('1') hwd = findTopWindow(wantedText='Capture Options') win32gui.SetForegroundWindow(hwd) #win32gui.MoveWindow(hwd,0,0,510,460,1) #Move the window self.sleep('1') #Adapter_networkCard print 'Click on the Adapter,Select', networkCard_Flag, 'network card.' h = win32gui.FindWindowEx(hwd, None, 'SysTreeView32', None) #print h self.Mouse_LB_click(h) self.shortcut_keys(['Home']) self.shortcut_keys(['Down']) self.sleep('1') #Select network card hw = win32gui.FindWindowEx(hwd, None, None, 'Adapter') hwn = win32gui.FindWindowEx(hw, None, 'SysTreeView32', None) self.Mouse_LB_click(hwn) self.shortcut_keys(['Home']) self.sleep('1') try: result = self.select_networkCard(networkCard_Flag) except: log_public(ERR_OMNIPEEK_START_SELECT_NETWORKCARD_0002) self.m_ERROR_MSG = ERR_OMNIPEEK_START_SELECT_NETWORKCARD_0002 return False if result != True: print 'Select network card failed' #点击取消 button_hwd = win32gui.FindWindowEx(hwd, None, 'Button', '取消') self.Mouse_LB_click(button_hwd) self.sleep('1') return False #802.11_channel self.sleep('1') print 'Begin to choose the channel:', channel h = win32gui.FindWindowEx(hwd, None, 'SysTreeView32', None) self.Mouse_LB_click(h) self.shortcut_keys(['Down']) self.sleep('1') h = win32gui.FindWindowEx(hwd, None, None, '802.11') hwnd = win32gui.FindWindowEx(h, None, 'Button', '&Number:') self.Mouse_LB_click(hwnd) self.sleep('1') channel_h = win32gui.FindWindowEx(h, None, 'ComboBox', None) #print channel_h bufLen = 1024 buf = win32gui.PyMakeBuffer(bufLen) n = win32gui.SendMessage(channel_h, win32con.WM_GETTEXT, bufLen, buf) #print buf[0:n] #Determine if there's any available channel if n == 0: print 'Have no channel to choose' #点击取消 button_hwd = win32gui.FindWindowEx(hwd, None, 'Button', '取消') #print button_hwd self.Mouse_LB_click(button_hwd) #print '点击 取消' self.sleep('1') return False if string.atoi(channel) >= 1: self.Mouse_LB_click(channel_h) try: self.selece_Channel(channel) except: log_public(ERR_OMNIPEEK_START_SELECT_CHANNEL_0003) self.m_ERROR_MSG = ERR_OMNIPEEK_START_SELECT_CHANNEL_0003 return False self.shortcut_keys(['Enter']) self.sleep('1') print 'Select channel success' #点击确定 button = win32gui.FindWindowEx(hwd, None, 'Button', '确定') #print 'button :',button self.Mouse_LB_click(button) self.sleep('8') #点击Start Capture print 'Begin to capture package' self.shortcut_keys(['Ctrl', 'Y']) #根据快捷键点击 self.sleep(timesleep) print 'After waiting for ', timesleep, 'seconds Stop capture package' self.shortcut_keys(['Ctrl', 'Y']) #点击Stop Capture return True
def OperateWebPage(self,FlowName,bCA,lst): self.test_NG_error = '' kill_program() lst = self.Replace_global_multi_list(lst) dstURL={} if self.test_NG_error.find('the global file')>-1: log_print('not fined the global file') return False driver = webdriver.Ie() i = 0 lstLen = len(lst) while i<lstLen: lstSub=[] lstSub.extend(lst[i]) lstSubLen = len(lstSub) j = 0 lstSubLen = len(lstSub) while j<lstSubLen: if j == 0 : dstURL={} dstURL.update(lstSub[j]) if self.OpenURL(driver,dstURL)==False: return False else: dstComb = {} dstComb.update(lstSub[j]) if cmp(dstComb['ASSIST'],KEY_COMMENT)==0: j+=1 continue elif cmp(dstComb['ASSIST'],KEY_LAND)==0: if self.LandDlg(dstComb)==False: return False else: Value = dstComb[KEY_CONTROLTYPE] log_print(KEY_WEB_TYPE_WAIT) log_print(dstComb[KEY_CONTROLNAME]) log_print(dstComb[KEY_CONTROLVALUE]) log_print(dstComb['ASSIST']) if Value == KEY_WEB_TYPE_WAIT: if self.waitEvent(dstComb[KEY_CONTROLNAME],dstComb[KEY_CONTROLVALUE]) == False: log_print('waitEvent is False') if self.checkPageIsBusy(driver) == True: log_print('checkPageIsBusy reutrn True') i = i-1 break self.ie_close(driver) log_public(WEB_ERR_NO_0007+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0007+dstComb[KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_CLICK: if self.EventClick(driver,dstComb[KEY_CONTROLNAME],dstComb[KEY_CONTROLVALUE])==False: if self.checkPageIsBusy(driver) == True: log_print('checkPageIsBusy reutrn True') i = i-1 break elif Value == KEY_WEB_TYPE_SWITCHDEFAULT: if self.EventSwitchDefault(driver)==False: return False elif Value == KEY_WEB_TYPE_SWITCHFRAME: if self.EventSwitchFrame(driver,dstComb[KEY_CONTROLNAME])==False: return False elif Value == KEY_WEB_TYPE_TEXTBOX: if self.EventTextBox(driver,dstComb)==False: return False elif Value == KEY_WEB_TYPE_DIALOG: if self.EventDialogA(dstComb)==False: return False elif Value ==KEY_WEB_TYPE_LISTBOX: if self.EventListBox(driver,dstComb) ==False: return False elif Value ==KEY_WEB_TYPE_CHECKBOX: if self.EventCheckBox(driver, dstComb) ==False: return False elif Value ==KEY_WEB_TYPE_DIALOG_UPDATA: if self.EventDialogB(driver,dstComb)==False: return False j+=1 i+=1 return
def setWebPage(self,filePath,FlowName,bCA): log_print( 'setWebPage fuction') version_file = find_parentpath()+'\\auto_conf\\version.ini' tmp_Land_Dialog_check_total=read_ini(version_file,'Land_Dialog_check_total','ACweb Debug') tmp_Wait_Dialog_time =read_ini(version_file,'tmp_Wait_Dialog_time','ACweb Debug') if len(tmp_Land_Dialog_check_total.strip())>0: self.Land_Dialog_check_total = string.atoi(tmp_Land_Dialog_check_total.strip()) if len(tmp_Wait_Dialog_time.strip())>0: self.Wait_Dialog_time = string.atof(tmp_Wait_Dialog_time.strip()) p_path1 = os.path.abspath(sys.argv[0]) tmp_global_file ='\\global\\global_param.xls' findstr = 'Simu' path_parent = Getfindpath(p_path1,findstr) global_file = path_parent + tmp_global_file self.read_global_param(global_file) myPath = filePath log_print(myPath) lst = [] obj_book = 0 obj_table = 0 LOOPMAX = 0 shttName ='' ret = 0 #return value form function obj_book = self.OpenFile(myPath) #print obj_book #print obj_book.sheet_names() for sheet_name in obj_book.sheet_names(): if sheet_name == u'0-ACPAGE' : obj_table = obj_book.sheet_by_name(sheet_name) break print obj_table if obj_table == 0 : log_public(ERR_TABLE_OPENFAIL_0011) self.m_ERROR_MSG = ERR_TABLE_OPENFAIL_0011 return False #while loop bNeedReadHead = True NEXTNODE = True myDictNodeCur = {'rowx':'','coly':''} myDictNodeNext = {'rowx':'','coly':''} dct_Cell={} #dicitionary while NEXTNODE == True: #read START if bNeedReadHead == True: if self.ReadFlowHeader(obj_table,FlowName,myDictNodeNext) == False: return False bNeedReadHead = False if (myDictNodeNext[KEY_ROW] == -1) & ( myDictNodeNext[KEY_COL] == -1): NEXTNODE = False continue myDictNodeCur.update(myDictNodeNext) #read Page if self.ReadFlowPage(obj_table,myDictNodeCur,myDictNodeNext,lst) == False: return False if (myDictNodeNext[KEY_ROW] == -1) & (myDictNodeNext[KEY_COL] == -1): NEXTNODE = False continue #print lst #need dele log_print( 'web execl,lst:') log_print( lst) if self.OperateWebPage(FlowName,bCA,lst) == False: return False del lst return True
def choose_conf_file(self): #get control of waveQoE window. hwnd3 = win32gui.FindWindow(WAVEQOE_CLASS, None) print 'hwnd3', hwnd3 time.sleep(0.5) #set waveQoE window to top. win32gui.SetForegroundWindow(hwnd3) time.sleep(0.5) #move waveQoE window to top left corner. win32gui.MoveWindow(hwnd3, 0, 0, 1448, 878, 1) #send Alt+F to open 'File' in menu bar. win32api.Sleep(1000) win32api.keybd_event(18, 0, 0, 0) #18��Alt�ļ��� win32api.keybd_event(70, 0, 0, 0) #70��F�ļ��� win32api.Sleep(1000) win32api.keybd_event(70, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.Sleep(1000) #send O to open 'open' window. win32api.keybd_event(79, 0, 0, 0) #79��O�ļ��� win32api.Sleep(1000) win32api.keybd_event(79, 0, win32con.KEYEVENTF_KEYUP, 0) win32api.Sleep(1000) #choose config file and open it. self.myobj.Find_Gui_edit(str_app='Open', control_class='ComboBox', filename=self.conf_file_dir, control_name='', stop_flag='0') self.myobj.Find_Gui_button(str_app='Open', control_class='Button', control_name='��(&O)') time.sleep(0.5) hwnd4 = win32gui.FindWindow('#32770', 'Open') print 'hwnd4: ', hwnd4 if hwnd4 > 0: log_public(ERR_NO_0006) self.m_ERROR_MSG = ERR_NO_0006 self.myobj.Find_Gui_button(str_app='Open', control_class='Button', control_name='ȷ��') time.sleep(0.5) self.myobj.Find_Gui_button(str_app='Open', control_class='Button', control_name='ȡ��') time.sleep(0.5) self.close_waveQoE() print 'close_waveqoe' return False else: print 'conf_file is correct.' return True
def ping_test(self, path, ip, packet, interv, count, time, step, Flag, log_name, test_time, status_flag, stop_flag, filename): try: self.startapp(path) except: log_public(ERR_PING_TEST_0001) self.m_ERROR_MSG = ERR_PING_TEST_0001 return False try: self.config_edit(ip, packet, interv, count) except: log_public(ERR_PING_TEST_0006) self.m_ERROR_MSG = ERR_PING_TEST_0006 return False try: self.config_PacketSize(time, step, Flag) except: log_public(ERR_PING_TEST_0007) self.m_ERROR_MSG = ERR_PING_TEST_0007 return False try: self.config_log(log_name) except: log_public(ERR_PING_TEST_0005) self.m_ERROR_MSG = ERR_PING_TEST_0005 return False try: self.control_butten_reset() except: log_public(ERR_PING_TEST_0008) self.m_ERROR_MSG = ERR_PING_TEST_0008 return False try: self.control_butten_clear() except: log_public(ERR_PING_TEST_0008) self.m_ERROR_MSG = ERR_PING_TEST_0008 return False if status_flag == '1': try: self.control_butten_status() except: log_public(ERR_PING_TEST_0008) self.m_ERROR_MSG = ERR_PING_TEST_0008 return False try: self.control_butten_ping() except: log_public(ERR_PING_TEST_0008) self.m_ERROR_MSG = ERR_PING_TEST_0008 return False if stop_flag == '0': self.sleep(count) else: self.sleep(test_time) try: self.control_butten_stop(ip) except: log_public(ERR_PING_TEST_0008) self.m_ERROR_MSG = ERR_PING_TEST_0008 return False if self.ping_close(filename) == False: return False return True
def OperateACWebPage(self,bCA,lst): #global Obj_WaitDialog_Cancel #g_Group_Idx #define 'ie' object to control web page ie = PAMIE() #check version of IE. different version have different operate. nVer = self.getIEVersion(ie) if nVer == -1: log_public(WEB_ERR_NO_0002+dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0002+dstURL[KEY_URL] return False #KillCA = True KillCA = bCA #loop to control every web page,all the control information storage at lst. #we loop to get page information at 'lst' to control web pages. #We call it one page_operate. lstLen = len(lst) for i in range(lstLen): #define 'lstSub',this list go to storage web page information. lstSub=[] lstSub.extend(lst[i]) #loop to control every control_components of one web page. #we loop to get control_components at 'lstSub' to control control_components of one web pages. #We call it line_operation. #Obj_WaitDialog_Cancel = 0 #if dialog popup after you click a button.you need to use WAIT DIALOG EVENT. This variable will starage the object. lstSubLen = len(lstSub) for j in range(0,lstSubLen): #get URL path #URL path is storage at '1' index of 'lstSubLen',so judge 'j' wether equal 1. if j == 0 : #define 'dstURL' as dictionary to storage URL and its value. dstURL={} dstURL.update(lstSub[j]) #URL Value can be None sometime,we will not go to the page when the value is 'NONE'. #if the value of 'KEY_URL' not NONE,we will got the page by 'navigate' function. if dstURL[KEY_URL]!=KEY_URL_NONE: ret = ie.navigate(dstURL[KEY_URL]) if ret == False: ie.quit() #write logging log_public(WEB_ERR_NO_0001+dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0001+dstURL[KEY_URL] return False if KillCA == 'CAON': #IE 8 need to click 'overridelink' #IE 6 need to click 'CA authentication dialog' if nVer == 8: time.sleep(1) ret = ie.clickLink('overridelink') #encode if ret == False: ie.quit() #write logging log_public(WEB_ERR_NO_0001+dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0001+dstURL[KEY_URL] return False KillCA = False #not need to kill next time open URL elif nVer == 6: time.sleep(1) KillCA = False else: #get line_operation. dstComb = {} dstComb.update(lstSub[j]) #if 'ASSIST' have '//',This line_operation will be ignore. if dstComb[KEY_ASSIST]== KEY_COMMENT: continue #dispatch line_operation.include kinds(set text box, set check box,select list box,...) Value = dstComb[KEY_CONTROLTYPE] if Value == KEY_WEB_TYPE_TEXTBOX: if ie.setTextBox(dstComb[KEY_CONTROLNAME], dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0003+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0003+dstComb[KEY_CONTROLNAME] return False elif Value== KEY_WEB_TYPE_CHECKBOX: if self.MainCheckBox(ie,dstComb[KEY_ASSIST],dstComb[KEY_CONTROLNAME],dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0004+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0004+dstComb[KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_LISTBOX: if self.MainListBox(ie,dstComb[KEY_ASSIST],dstComb[KEY_CONTROLNAME],dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0005+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0005+dstComb[KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_BUTTON: if self.MainButton(ie,dstComb[KEY_ASSIST],dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0006+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0006+dstComb[KEY_CONTROLNAME] False elif Value == KEY_WEB_TYPE_WAIT: if self.waitEvent(dstComb[KEY_CONTROLNAME],dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0007+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0007+dstComb[KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_JAVASCRIPT: if self.MainJavaScript(ie,dstComb[KEY_ASSIST],dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0008+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0008+dstComb[KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_GROUP_CHECKBOX: if self.GetGoupCheckBoxIndex(ie,dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0009+dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0009+dstComb[KEY_CONTROLNAME] return False #close ie after operation. ie.quit()
def ReadWebPgControl(self,obj_table,dctCurNode,lst): log_print( 'ReadWebPgControl fuction') print 'ReadWebPgControl' row = dctCurNode[KEY_ROW]+3 col = dctCurNode[KEY_COL] nrows = obj_table.nrows timesBlank = 0 for rows in range(row,nrows): dct_Combn={} mySubASSIST = str(obj_table.cell(rows,col).value) mySubASSIST.strip() if mySubASSIST == KEY_END: return True dct_ASSIST ={KEY_ASSIST:mySubASSIST} dct_Combn.update(dct_ASSIST) mySubControlType = str(obj_table.cell(rows,col+1).value) mySubControlType.strip() if mySubControlType =='': log_public(ERR_EXCEL_NO_VALUE_0008) self.m_ERROR_MSG = ERR_EXCEL_NO_VALUE_0008 return False dct_CONTROLTYPE= {KEY_CONTROLTYPE:mySubControlType} dct_Combn.update(dct_CONTROLTYPE) mySubControlName = str(obj_table.cell(rows,col+2).value.encode(ENCODE_DECODE)) mySubControlName.strip() if mySubControlName =='': log_public(ERR_EXCEL_CONTROLNAME_VALUE_0010) self.m_ERROR_MSG = ERR_EXCEL_CONTROLNAME_VALUE_0010 return False dct_CONTROLNAME = {KEY_CONTROLNAME:mySubControlName} dct_Combn.update(dct_CONTROLNAME) mySubControlValue = obj_table.cell(rows,col+3).value if isinstance(mySubControlValue,float) == False & isinstance(mySubControlValue,int) == False: #mySubControlValue = obj_table.cell(rows,col+3).value.encode('gb18030') #2013/03/04,gongke,if the string have chinese use unicode,else use encode('gb18030') if self.isChinese(mySubControlValue) == True: mySubControlValue = obj_table.cell(rows,col+3).value else: mySubControlValue = obj_table.cell(rows,col+3).value.encode(ENCODE_DECODE) else: mySubControlValue = str(mySubControlValue) mySubControlValue = mySubControlValue.encode(ENCODE_DECODE) mySubControlValue = mySubControlValue[0:mySubControlValue.find('.')] dct_CONTROLVALUE = {KEY_CONTROLVALUE:mySubControlValue} dct_Combn.update(dct_CONTROLVALUE) lst.append(dct_Combn) del dct_Combn return True
def omnipeek_start(self,path,networkCard_Flag,channel,timesleep): print 'Open the omnipeek application software' try: self.startapp(path) except: #log_public(ERR_OMNIPEEK_START_STARTAPP_0001) self.m_ERROR_MSG = ERR_OMNIPEEK_START_STARTAPP_0001 return False self.sleep('18') ''' print 'To maximize the window' try: self.shortcut_keys(['Alt','Spacebar','X']) except Exception ,exc_str: print(exc_str) print 'Window to maximize success' return False ''' self.sleep('1') hwnd0 = win32gui.FindWindow("OmniPeek", 'OmniPeek - [Start Page]') win32gui.SetForegroundWindow(hwnd0) self.sleep('1') print 'Click on the New Capture' self.shortcut_keys(['Ctrl','N']) self.sleep('1') hwd = findTopWindow(wantedText='Capture Options') win32gui.SetForegroundWindow(hwd) #win32gui.MoveWindow(hwd,0,0,510,460,1) #Move the window self.sleep('1') #Adapter_networkCard print 'Click on the Adapter,Select',networkCard_Flag,'network card.' h = win32gui.FindWindowEx(hwd, None, 'SysTreeView32', None) #print h self.Mouse_LB_click(h) self.shortcut_keys(['Home']) self.shortcut_keys(['Down']) self.sleep('1') #Select network card hw = win32gui.FindWindowEx(hwd, None, None, 'Adapter') hwn = win32gui.FindWindowEx(hw, None, 'SysTreeView32', None) self.Mouse_LB_click(hwn) self.shortcut_keys(['Home']) self.sleep('1') try: result = self.select_networkCard(networkCard_Flag) except: log_public(ERR_OMNIPEEK_START_SELECT_NETWORKCARD_0002) self.m_ERROR_MSG = ERR_OMNIPEEK_START_SELECT_NETWORKCARD_0002 return False if result != True: print 'Select network card failed' #点击取消 button_hwd = win32gui.FindWindowEx(hwd, None, 'Button', '取消') self.Mouse_LB_click(button_hwd) self.sleep('1') return False #802.11_channel self.sleep('1') print 'Begin to choose the channel:',channel h = win32gui.FindWindowEx(hwd, None, 'SysTreeView32', None) self.Mouse_LB_click(h) self.shortcut_keys(['Down']) self.sleep('1') h = win32gui.FindWindowEx(hwd, None, None, '802.11') hwnd = win32gui.FindWindowEx(h, None, 'Button', '&Number:') self.Mouse_LB_click(hwnd) self.sleep('1') channel_h = win32gui.FindWindowEx(h, None, 'ComboBox', None) #print channel_h bufLen = 1024 buf = win32gui.PyMakeBuffer(bufLen) n = win32gui.SendMessage(channel_h, win32con.WM_GETTEXT, bufLen, buf) #print buf[0:n] #Determine if there's any available channel if n == 0: print 'Have no channel to choose' #点击取消 button_hwd = win32gui.FindWindowEx(hwd, None, 'Button', '取消') #print button_hwd self.Mouse_LB_click(button_hwd) #print '点击 取消' self.sleep('1') return False if string.atoi(channel) >= 1: self.Mouse_LB_click(channel_h) try: self.selece_Channel(channel) except: log_public(ERR_OMNIPEEK_START_SELECT_CHANNEL_0003) self.m_ERROR_MSG = ERR_OMNIPEEK_START_SELECT_CHANNEL_0003 return False self.shortcut_keys(['Enter']) self.sleep('1') print 'Select channel success' #点击确定 button = win32gui.FindWindowEx(hwd, None, 'Button', '确定') #print 'button :',button self.Mouse_LB_click(button) self.sleep('8') #点击Start Capture print 'Begin to capture package' self.shortcut_keys(['Ctrl','Y']) #根据快捷键点击 self.sleep(timesleep) print 'After waiting for ',timesleep,'seconds Stop capture package' self.shortcut_keys(['Ctrl','Y']) #点击Stop Capture return True
def OperateACWebPage(self, bCA, lst): #global Obj_WaitDialog_Cancel #g_Group_Idx #define 'ie' object to control web page ie = PAMIE() #check version of IE. different version have different operate. nVer = self.getIEVersion(ie) if nVer == -1: log_public(WEB_ERR_NO_0002 + dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0002 + dstURL[KEY_URL] return False #KillCA = True KillCA = bCA #loop to control every web page,all the control information storage at lst. #we loop to get page information at 'lst' to control web pages. #We call it one page_operate. lstLen = len(lst) for i in range(lstLen): #define 'lstSub',this list go to storage web page information. lstSub = [] lstSub.extend(lst[i]) #loop to control every control_components of one web page. #we loop to get control_components at 'lstSub' to control control_components of one web pages. #We call it line_operation. #Obj_WaitDialog_Cancel = 0 #if dialog popup after you click a button.you need to use WAIT DIALOG EVENT. This variable will starage the object. lstSubLen = len(lstSub) for j in range(0, lstSubLen): #get URL path #URL path is storage at '1' index of 'lstSubLen',so judge 'j' wether equal 1. if j == 0: #define 'dstURL' as dictionary to storage URL and its value. dstURL = {} dstURL.update(lstSub[j]) #URL Value can be None sometime,we will not go to the page when the value is 'NONE'. #if the value of 'KEY_URL' not NONE,we will got the page by 'navigate' function. if dstURL[KEY_URL] != KEY_URL_NONE: ret = ie.navigate(dstURL[KEY_URL]) if ret == False: ie.quit() #write logging log_public(WEB_ERR_NO_0001 + dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0001 + dstURL[KEY_URL] return False if KillCA == 'CAON': #IE 8 need to click 'overridelink' #IE 6 need to click 'CA authentication dialog' if nVer == 8: time.sleep(1) ret = ie.clickLink('overridelink') #encode if ret == False: ie.quit() #write logging log_public(WEB_ERR_NO_0001 + dstURL[KEY_URL]) self.m_ERROR_MSG = WEB_ERR_NO_0001 + dstURL[ KEY_URL] return False KillCA = False #not need to kill next time open URL elif nVer == 6: time.sleep(1) KillCA = False else: #get line_operation. dstComb = {} dstComb.update(lstSub[j]) #if 'ASSIST' have '//',This line_operation will be ignore. if dstComb[KEY_ASSIST] == KEY_COMMENT: continue #dispatch line_operation.include kinds(set text box, set check box,select list box,...) Value = dstComb[KEY_CONTROLTYPE] if Value == KEY_WEB_TYPE_TEXTBOX: if ie.setTextBox(dstComb[KEY_CONTROLNAME], dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0003 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0003 + dstComb[ KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_CHECKBOX: if self.MainCheckBox( ie, dstComb[KEY_ASSIST], dstComb[KEY_CONTROLNAME], dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0004 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0004 + dstComb[ KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_LISTBOX: if self.MainListBox( ie, dstComb[KEY_ASSIST], dstComb[KEY_CONTROLNAME], dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0005 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0005 + dstComb[ KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_BUTTON: if self.MainButton(ie, dstComb[KEY_ASSIST], dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0006 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0006 + dstComb[ KEY_CONTROLNAME] False elif Value == KEY_WEB_TYPE_WAIT: if self.waitEvent(dstComb[KEY_CONTROLNAME], dstComb[KEY_CONTROLVALUE]) == False: log_public(WEB_ERR_NO_0007 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0007 + dstComb[ KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_JAVASCRIPT: if self.MainJavaScript( ie, dstComb[KEY_ASSIST], dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0008 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0008 + dstComb[ KEY_CONTROLNAME] return False elif Value == KEY_WEB_TYPE_GROUP_CHECKBOX: if self.GetGoupCheckBoxIndex( ie, dstComb[KEY_CONTROLNAME]) == False: log_public(WEB_ERR_NO_0009 + dstComb[KEY_CONTROLNAME]) self.m_ERROR_MSG = WEB_ERR_NO_0009 + dstComb[ KEY_CONTROLNAME] return False #close ie after operation. ie.quit()