#!/usr/local/bin/python2.7
# encoding: utf-8
import os
import time
from pywinauto import application
import win32api
import win32con
import win32gui
import win32com.client
import winGuiAuto
from win32con import MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP
import thread
def hello(count):
#//打开银豹收银软件
#win32api.MessageBox(win32con.NULL, u'您即将进入调用银豹收银系统进入测试',u'账单截获自动测试脚本', win32con.MB_OK)
print u"正在运行第"+str(count)+u"次"
os.system("C:\Users\Public\Desktop\PosPal.lnk")
# os.system("C:\Users\Public\Desktop\PosPal.lnk")
time.sleep(1)
posname=u"PosPal 收银系统"
hn=win32gui.FindWindow('SWT_Window0',posname)
#//点击收银功能进入登录界面
win32gui.ShowWindow(hn,win32con.SW_SHOWNORMAL)
hwnd=win32gui.WindowFromPoint((610,450))
win32api.SetCursorPos((590,430))
win32api.SendMessage(hwnd,win32con.WM_LBUTTONDOWN)
win32api.SendMessage(hwnd,win32con.WM_LBUTTONUP)
time.sleep(1)
#//在登录界面输入收银用户名和密码
posname1=u"PosPal - 登录"
hn1=win32gui.FindWindow('SWT_Window0',posname1)
tid = win32gui.FindWindowEx(hn1, None, 'Edit', None)
win32gui.SendMessage(tid, win32con.WM_SETTEXT, None, '1001')
username = win32gui.FindWindowEx(hn1, tid, 'Edit', None)
win32gui.SendMessage(username, win32con.WM_SETTEXT, None, '1001')
#//登录银银豹收银主界面
# posname1=u"PosPal - 登录"
# hn2=win32gui.FindWindow('SWT_Window0',posname1)
# win32gui.ShowWindow(hn2,win32con.SW_SHOWNORMAL)
# x1c1,y1c1 = win32gui.ScreenToClient(hn2,(678,525))
hwnd2=win32gui.WindowFromPoint((700,540))
name = win32gui.GetClassName(hwnd2)
win32api.SetCursorPos((680,530))
time.sleep(3)
win32api.SendMessage(hwnd2,win32con.WM_LBUTTONDOWN)
win32api.SendMessage(hwnd2,win32con.WM_LBUTTONUP)
print count
time.sleep(1)
#//在银豹主界面输入上面名称
hwnd3=win32gui.WindowFromPoint((420,620))
#if (count%2==0):
win32gui.SendMessage(hwnd3, win32con.WM_SETTEXT, None,'6921168504015')
hwnd4=win32gui.WindowFromPoint((657,614))
win32api.SetCursorPos((657,614))
time.sleep(1)
win32api.SendMessage(hwnd4,win32con.WM_LBUTTONDOWN)
win32api.SendMessage(hwnd4,win32con.WM_LBUTTONUP)
win32gui.SendMessage(hwnd3, win32con.WM_SETTEXT, None,'9771607160008')
hwnd4=win32gui.WindowFromPoint((657,614))
win32api.SetCursorPos((657,614))
time.sleep(1)
win32api.SendMessage(hwnd4,win32con.WM_LBUTTONDOWN)
win32api.SendMessage(hwnd4,win32con.WM_LBUTTONUP)
#else:
win32gui.SendMessage(hwnd3, win32con.WM_SETTEXT, None,'6901668054012')
hwnd4=win32gui.WindowFromPoint((657,614))
win32api.SetCursorPos((657,614))
time.sleep(1)
win32api.SendMessage(hwnd4,win32con.WM_LBUTTONDOWN)
win32api.SendMessage(hwnd4,win32con.WM_LBUTTONUP)
win32gui.SendMessage(hwnd3, win32con.WM_SETTEXT, None,'9787508609393')
hwnd4=win32gui.WindowFromPoint((657,614))
win32api.SetCursorPos((657,614))
time.sleep(1)
win32api.SendMessage(hwnd4,win32con.WM_LBUTTONDOWN)
win32api.SendMessage(hwnd4,win32con.WM_LBUTTONUP)
#
# win32gui.SendMessage(hwnd3, win32con.WM_SETTEXT, None,'6920907809909')
# hwnd4=win32gui.WindowFromPoint((657,614))
# win32api.SetCursorPos((657,614))
# time.sleep(1)
# win32api.SendMessage(hwnd4,win32con.WM_LBUTTONDOWN)
# win32api.SendMessage(hwnd4,win32con.WM_LBUTTONUP)
#
# win32gui.SendMessage(hwnd3, win32con.WM_SETTEXT, None,'6901668054012')
# hwnd4=win32gui.WindowFromPoint((657,614))
# win32api.SetCursorPos((657,614))
# time.sleep(1)
# win32api.SendMessage(hwnd4,win32con.WM_LBUTTONDOWN)
# win32api.SendMessage(hwnd4,win32con.WM_LBUTTONUP)
#//按收银按钮做结算处理
hwnd5=win32gui.WindowFromPoint((1085,614))
win32api.SetCursorPos((658,615))
time.sleep(1)
win32api.SendMessage(hwnd5,win32con.WM_LBUTTONDOWN)
win32api.SendMessage(hwnd5,win32con.WM_LBUTTONUP)
#//按确认打印小票
win32api.SetCursorPos((570,605))
time.sleep(1)
win32api.mouse_event(MOUSEEVENTF_LEFTDOWN,569,603,764,654)
win32api.mouse_event(MOUSEEVENTF_LEFTUP,569,603,764,654)
#//关闭主界面窗口
win32api.SetCursorPos((1154,152))
time.sleep(1)
win32api.mouse_event(MOUSEEVENTF_LEFTDOWN,1153,151,1194,171)
win32api.mouse_event(MOUSEEVENTF_LEFTUP,1153,151,1194,171)
#//按收银按钮做结算处理
#aa=win32api.MessageBox(win32con.NULL, u'恭喜你完成本次测试,是否进去循环无限次测试!!!',u'测试结束', win32con.MB_YESNO)
#if aa==6: