import os
import time
import pyautogui
import pyperclip
import pandas as pd
import xlrd
查看依赖版本
(.venv) PS D:\WorkSpace\Exchange> pip list
Package Version
--------------- -------
et-xmlfile 1.1.0
MouseInfo 0.1.3
numpy 1.26.3
openpyxl 3.1.2
pandas 2.2.0
pillow 10.2.0
pip 23.2.1
PyAutoGUI 0.9.54
PyGetWindow 0.0.9
PyMsgBox 1.0.9
pyperclip 1.8.2
PyRect 0.2.0
PyScreeze 0.1.30
python-dateutil 2.8.2
pytweening 1.0.7
pytz 2023.4
setuptools 68.2.0
six 1.16.0
tzdata 2023.4
wheel 0.41.2
xlrd 2.0.1
提示
xlrd.biffh.XLRDError
ImageNotFoundException
可能是依赖版本太高,先卸载
pip uninstall PyScreeze
pip uninstall xlrd
再安装
pip install PyScreeze==0.1.29
pip install xlrd==1.2.0
pip install opencv-python
在图形目录下面命名想要点击的图形
生成Excel配置文件
数据检查
图形匹配
def mainWork(img,sheet1,i):
#i = 1
#while i < sheet1.nrows:
if i < sheet1.nrows:
#取本行指令的操作类型
cmdType = sheet1.row(i)[1]
if cmdType.value == 1.0:
#取图片名称
img = sheet1.row(i)[0].value
reTry = 1
if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
reTry = sheet1.row(i)[2].value
mouseClick(1,"left",img,reTry)
print("单击左键",img)
# 2 代表双击左键
elif cmdType.value == 2.0:
#取图片名称
img = sheet1.row(i)[0].value
#取重试次数
reTry = 1
if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
reTry = sheet1.row(i)[2].value
mouseClick(2,"left",img,reTry)
print("双击左键",img)
#3代表右键
elif cmdType.value == 3.0:
#取图片名称
img = sheet1.row(i)[0].value
#取重试次数
reTry = 1
if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
reTry = sheet1.row(i)[2].value
mouseClick(1,"right",img,reTry)
print("右键",img)
# 4代表输入
elif cmdType.value == 4.0:
inputValue = sheet1.row(i)[0].value
pyperclip.copy(inputValue)
pyautogui.hotkey('ctrl','v')
time.sleep(0.5)
print("输入:",inputValue)
#5代表等待
elif cmdType.value == 5.0:
#取图片名称
waitTime = sheet1.row(i)[0].value
time.sleep(waitTime)
print("等待",waitTime,"秒")
#6代表滚轮
elif cmdType.value == 6.0:
#取图片名称
scroll = sheet1.row(i)[0].value
pyautogui.scroll(int(scroll))
print("滚轮滑动",int(scroll),"距离")
# 主任务从第i个开始执行j次
def ReCycle(i, j, file):
# file = "D:/AutoTest/PythonProject/UseCase/output.xlsx"
# test = GUITest()
wb = xlrd.open_workbook(filename=file)
# wb = openpyxl.load_workbook(filename=file)
# 通过索引获取表格sheet页
sheet1 = wb.sheet_by_index(0)
print('欢迎使用PecCore自动化测试demo~')
# 数据检查
checkCmd = dataCheck(sheet1)
if checkCmd:
print("表不为空")
else:
print('输入有误或者已经退出!')
for index in range(0, j):
mainWork(sheet1, sheet1, i)
i += 1
print(i)
return i
调用
excel_generate("./img/", "./excel/output.xlsx")
ReCycle(1, 1, "./excel/output.xlsx")
控制台输出
欢迎使用PecCore自动化测试demo~
表不为空
未找到匹配图片,0.1秒后重试
未找到匹配图片,0.1秒后重试
未找到匹配图片,0.1秒后重试
未找到匹配图片,0.1秒后重试
未找到匹配图片,0.1秒后重试
未找到匹配图片,0.1秒后重试
单击左键 ./img/1_1_1.png
2