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
python类FindWindowEx()的实例源码
ctrl_pingtest.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def FindWindowByClassName(self, class_name):
win_info = FX_WINDOW_INFO()
win_info.Win32Window = win32gui.FindWindowEx(None, None, class_name, None)
print(win_info.Win32Window)
if win_info.Win32Window == 0:
return None
thread_process = win32process.GetWindowThreadProcessId(win_info.Win32Window)
win_info.ProcessID = thread_process[1]
win_info.ThreadID = thread_process[0]
win_info.Title = win32gui.GetWindowText(win_info.Win32Window)
return FX_Window(win_info)
def FindWindowByName(self, title_name):
win_info = FX_WINDOW_INFO()
win_info.Win32Window = win32gui.FindWindowEx(None, None, None, title_name)
if win_info.Win32Window == 0:
return None
thread_process = win32process.GetWindowThreadProcessId(win_info.Win32Window)
win_info.ProcessID = thread_process[1]
win_info.ThreadID = thread_process[0]
win_info.Title = win32gui.GetWindowText(win_info.Win32Window)
return FX_Window(win_info)
def get_expect_window_label_text(self, _expect_sec_window):
'''
Try to get window label text
'''
# label_text = u"????"
# label_text = label_text.encode('utf-8')
# return label_text
label_text = ''
window = self.expect_sec_window
child_control = None
last_child = 0
while True:
logging.debug("Find the child controls for parent window")
child_control = win32gui.FindWindowEx(window, last_child, 'static', None)
if not child_control:
logging.debug("The child is None")
break;
else:
logging.debug("The child is not None, ")
buffer = win32gui.PyMakeBuffer(200)
length = win32gui.SendMessage(child_control, win32con.WM_GETTEXT, 200, buffer)
result = buffer[:length]
result = result.decode('gbk').encode('utf-8')
logging.debug("Got the child text is :" + result)
last_child = child_control
label_text = result
time.sleep(0.5)
def _winfun(hwnd, lparam):
s = win32gui.GetWindowText(hwnd)
s = s.decode('gbk').encode('utf-8')
logging.debug("winfun, child_hwnd: %d txt: %s" % (hwnd, s))
return 1
if window:
logging.debug("To enumerate all the child windows")
win32gui.EnumChildWindows(self.expect_sec_window, _winfun, None)
#bufferlength = struct.pack('i', 255)
#count = win32gui.SendMessage(self.expect_sec_window, win32con.get, 0, 0)
#for itemIndex in range(count):
# value = array.array('c', bufferlength +str().ljust(253))
# valueLength = win32gui.SendMessage(self.expect_sec_window, getValueMessage, itemIndex, value)
# yield value.tostring()[:valueLength]
return label_text
ctrl_waveQoE.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def select_ssid(self):
hwd0 = win32gui.FindWindow(WAVEQOE_CLASS,'WaveQoE - Real-World Deployment Tests: WaveQoE - 802.11ng_20.wml')
#print hwd0
win32gui.SetForegroundWindow(hwd0)
hwd1 = win32gui.FindWindowEx(hwd0, None, WAVEQOE_CLASS, 'qt_central_widget')
#print hwd1
hwd2 = win32gui.FindWindowEx(hwd1, None, WAVEQOE_CLASS, 'splitter6')
#print hwd2
hwd3 = win32gui.FindWindowEx(hwd2, None, WAVEQOE_CLASS, 'layout156')
#print hwd3
hwd4 = win32gui.FindWindowEx(hwd3, None, WAVEQOE_CLASS, 'mainStack')
print hwd4
hwd5 = win32gui.FindWindowEx(hwd4, None, WAVEQOE_CLASS, 'portSetup')
print hwd5
hwd6 = win32gui.FindWindowEx(hwd5, None, WAVEQOE_CLASS, 'buttonGroup28')
#print hwd6
#click Connect butten
hwd7 = win32gui.FindWindowEx(hwd6, None, WAVEQOE_CLASS, 'chassisConnectBtn')
#print hwd7
self.Mouse_LB_click(hwd7)
time.sleep(5)
#click Scan Channels butten
hwd8 = win32gui.FindWindowEx(hwd6, None, WAVEQOE_CLASS, 'autoScanBtn')
self.Mouse_LB_click(hwd8)
time.sleep(30)
#click Clients butten
hwd9 = win32gui.FindWindowEx(hwd3, None, WAVEQOE_CLASS, 'groupBox35')
#print hwd9
hwd10 = win32gui.FindWindowEx(hwd9, None, WAVEQOE_CLASS, 'mainToolBox')
#print hwd10
ComboBox_list = findControls(hwd10,wantedClass = WAVEQOE_CLASS)
#print ComboBox_list
hwd11 = ComboBox_list[174]
#print hwd11
self.Mouse_LB_click(hwd11)
time.sleep(2)
#select SSID
self.click_CurrentPlace(lb_dx = '967',lb_dy = '228')
self.click_CurrentPlace(lb_dx = '967',lb_dy = '228')
self.click_CurrentPlace(lb_dx = '967',lb_dy = '228')
time.sleep(1)
self.click_CurrentPlace(lb_dx = '967',lb_dy = '247')
time.sleep(1)
return True
#-----------------------------------------------------------------------------
# Name: run_waveQoE
# purpose: run waveQoE,begin the test.
# explain:
# Author: gongke
#
# Created: 2013/05/20
#-----------------------------------------------------------------------------
def Find_Gui_Tree(self,str_app='New Scenario',control_class='Button',filename='test_baidu',control_name='AfxOleControl'):
print "*********Find_Gui_Tree function**********"
time.sleep(1)
#self.Mousepos_print()
print 'str_app',str_app
hwnd = win32gui.FindWindow(None, str_app)
if hwnd < 1:
hwnd = self.find_main_window(str_app)
print 'hwnd',hwnd
win32gui.SetForegroundWindow(hwnd)
print 'hwnd :',hwnd,str_app
win32gui.SetForegroundWindow(hwnd)
#self.Mousepos_print('5')
comboHwnd = win32gui.FindWindowEx(hwnd,0,control_class,None)
print '111111111111comboHwnd',comboHwnd
while comboHwnd:
print "control_class:",comboHwnd
cla = win32gui.GetClassName(comboHwnd)
print "control_class_NAME:",cla
bufLen=1024
buf =win32gui.PyMakeBuffer(bufLen)
n = win32gui.SendMessage(comboHwnd,win32con.WM_GETTEXT,bufLen,buf)
str = buf[:n]
print str
'''
if control_class in cla:
n = win32gui.SendMessage(comboHwnd,win32con.WM_GETTEXT,bufLen,buf)
str = buf[:n]
print str
if (len(control_name ) ==0 and n==0) or ((len(control_name )>0 and str.find(control_name)>-1 )):
win32gui.SendMessage(comboHwnd,win32con.WM_LBUTTONDOWN,0)
time.sleep(0.05)
win32gui.SendMessage(comboHwnd,win32con.WM_LBUTTONUP,0)
time.sleep(0.05)
win32gui.SendMessage(win32con.WM_CLOSE,0,0)
break
'''
comboHwnd = win32gui.GetWindow(comboHwnd,win32con.GW_HWNDNEXT)
time.sleep(1)
return True
ctrl_waveApps.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 35
收藏 0
点赞 0
评论 0
def select_ssid(self):
hwd0 = win32gui.FindWindow(WAVEApps_CLASS,None)
#print hwd0
win32gui.SetForegroundWindow(hwd0)
hwd1 = win32gui.FindWindowEx(hwd0, None, WAVEApps_CLASS, 'qt_central_widget')
#print hwd1
hwd2 = win32gui.FindWindowEx(hwd1, None, WAVEApps_CLASS, 'mainStack')
#print hwd2
hwd3 = win32gui.FindWindowEx(hwd2, None, WAVEApps_CLASS, 'portSetup')
#print hwd3
hwd4 = win32gui.FindWindowEx(hwd3, None, WAVEApps_CLASS, 'buttonGroup28')
#print hwd4
#click Connect butten
hwd5 = win32gui.FindWindowEx(hwd4, None, WAVEApps_CLASS, 'chassisConnectBtn')
#print hwd5
self.Mouse_LB_click(hwd5)
time.sleep(5)
#click Scan Channels butten
hwd6 = win32gui.FindWindowEx(hwd4, None, WAVEApps_CLASS, 'autoScanBtn')
self.Mouse_LB_click(hwd6)
time.sleep(30)
#click Clients butten
hwd7 = win32gui.FindWindowEx(hwd1, None, WAVEApps_CLASS, 'groupBox66')
#print hwd7
hwd8 = win32gui.FindWindowEx(hwd7, None, WAVEApps_CLASS, 'mainToolBox')
#print hwd8
ComboBox_list = findControls(hwd8,wantedClass = WAVEApps_CLASS)
#print ComboBox_list
hwd9 = ComboBox_list[130]
#print hwd9
self.Mouse_LB_click(hwd9)
time.sleep(2)
#select SSID
self.click_CurrentPlace(lb_dx = '1040',lb_dy = '226')
self.click_CurrentPlace(lb_dx = '1040',lb_dy = '226')
self.click_CurrentPlace(lb_dx = '1040',lb_dy = '226')
time.sleep(1)
self.click_CurrentPlace(lb_dx = '1040',lb_dy = '245')
time.sleep(1)
return True
#-----------------------------------------------------------------------------
# Name: run_waveApps
# purpose: run waveApps,begin the test.
# explain:
# Author: gongke
#
# Created: 2013/05/20
#-----------------------------------------------------------------------------
def get_hwnd_by_title_class(self, class_text = None, title_text= None, parent_title = None,parent_class = None):
""" Returns a windows window_handler
Args:
title_text (string): the title of the window we are looking for
SPECIAL CASE: if "desktop:n" is given, a handle to the desktop number n handle is given
Returns:
int: the handler for the window if found
Raises:
win32.error: If the windowtitle is invalid
"""
if 'desktop:' in title_text.lower():
_ , num = title_text.lower().split(':',1)
num = int(num)
monitors = win32api.EnumDisplayMonitors()
tar_mon = monitors[num]
self.hwnd = tar_mon[1]
return self.hwnd
if title_text.lower() == "desktop":
self.hwnd = win32gui.GetDesktopWindow()
return self.hwnd
child_hwnd = []
def child_enumerator(hwnd,param):
child_hwnd.append(hwnd)
return True
if parent_title is not None or parent_class is not None:
logging.debug("Where supplied title/class: {0}/{1}".format(str(title_text), str(class_text)))
parent_hwnd = self.get_hwnd_by_title_class(class_text=parent_class,title_text=parent_title)
win32gui.EnumChildWindows(parent_hwnd,child_enumerator,None)
for hwnd in child_hwnd:
hwnd_title = win32gui.GetWindowText(hwnd)
hwnd_class = win32gui.GetClassName(hwnd)
if (hwnd_title == title_text and title_text is not None) or \
(hwnd_class == class_text and class_text is not None):
self.hwnd = hwnd
return hwnd
# logging.debug("Found parent with title/class {0}{1} at {2}".format(parent_title,parent_class,parent_hwnd))
# self.hwnd = win32gui.FindWindowEx(parent_hwnd,0,class_text,title_text)
else:
logging.debug("Where supplied title/class: {0}/{1}".format(str(title_text), str(class_text)))
self.hwnd = win32gui.FindWindow(class_text, title_text)
if self.hwnd == 0:
raise ValueError('Unable to find a window with that title or class')
logging.debug("Found window 0x{:2X}".format(self.hwnd))
return self.hwnd