如何有效的去提高测试效率,在一个团队当中,肯定会存在部分人员无法熟悉数据库操作的情况,这个时候我们就可以通过GUI编程将工具界面会,使之快速的上手
本次通过一个GUI工具来带领大家如何制作这么个工具
功能实现页面如下图
![在这里插入图片描述](https://img-blog.csdnimg.cn/787b8d04d78c45cca30d9074045cc74f.png)
以下部分代码未保密,隐藏数据库连接及URL
```python
import sys
import pymysql
import requests
from PyQt5.QtCore import QObject, pyqtSignal, QBasicTimer, Qt
from PyQt5.QtGui import QTextCursor, QFont, QIcon
from gongju import Ui_Form
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import *
class Signal(QObject):
text_update = pyqtSignal(str)
def write(self, text):
self.text_update.emit(str(text))
QApplication.processEvents()
class MyClass(QWidget, Ui_Form):
def __init__(self):
super().__init__()
self.InitUi()
def InitUi(self):
self.setupUi(self)
self.setWindowTitle("测试工具")
window_pale = QtGui.QPalette()
window_pale.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QPixmap("D:\Guitest\\background.png")))
self.setPalette(window_pale)
self.show()
self.pushButton_2.clicked.connect(self.chognzhi)
self.pushButton.clicked.connect(self.deleteuser)
self.pushButton_3.clicked.connect(self.FindUser)
self.pushButton_8.clicked.connect(self.denglu)
self.pushButton_9.clicked.connect(self.shangban)
self.pushButton_10.clicked.connect(self.xiaban)
self.pushButton_7.clicked.connect(self.jiandan)
self.pushButton_11.clicked.connect(self.yijiaofei)
self.pushButton_12.clicked.connect(self.wijiaofei)
self.txt = QtWidgets.QTextEdit()
sys.stdout = Signal()
sys.stdout.text_update.connect(self.updatetext)
def updatetext(self, text):
"""
更新测试结果到textBrowser
"""
cursor = self.textBrowser.textCursor()
cursor.movePosition(QTextCursor.End)
self.textBrowser.append(text)
self.textBrowser.setTextCursor(cursor)
self.textBrowser.ensureCursorVisible()
def chognzhi(self):
reply = QMessageBox.information(self, "确认", "确认重置?",QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
if reply == QMessageBox.No:
print('退出')
pass
else:
if self.comboBox.currentText()=="微信":
clientType=0
else:
clientType=1
phone=self.lineEdit_2.text()
url = "https:/sysuser/reset/region"
payload = {"phone":phone,"clientType":clientType}
headers = {
'authdst': '683603105505349632',
'Authorization': 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJvTEdJRndwblhtYXEzZDdYOFFhUEhuQTZQSk93O293SWVWNU5nU1dzWEFBTXdseTVaZUxOSTNQekkiLCJjcmVhdGVkIjoxNjY5NTk4NTcyNjUzLCJleHAiOjE2Njk4NTc3NzJ9.Y7YPMl_rZeKOXajAREC7SWgMh9xH3YV0kPmPJcJEabInl3o-denV-mQwpYrbsgaZR2b59n_X8XjX9rmz7duHzQ',
'from': '0',
'linkid': '0',
'userid': '683603105505349632'
}
try:
response = requests.post(url, headers=headers, json=payload)
print('归属地重置进行中...')
if response.json()["res"]["codeMsg"]== None:
print('归属地重置成功!')
elif response.json()["res"]["codeMsg"].strip()== "用戶不存在":
print('用户不存在!')
else:
print('请求异常!')
except Exception as e:
print(e)
def deleteuser(self):
userphone=self.lineEdit.text()
connection = pymysql.connect(host="888.9--.100.194", port=23306, user='root', password="ZKtest@2020",
db="web_db")
print('数据库连接成功!')
reply = QMessageBox.information(self, "确认", "确认删除?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
if reply == QMessageBox.No:
print('退出')
pass
else:
print("删除数据进行中...")
cursor = connection.cursor()
sql1 = f'DELETE FROM t_user_wechat WHERE phone="{userphone}"'
sql2 = f'DELETE FROM t_user_player WHERE phone="{userphone}"'
sql3 = f'DELETE FROM t_user_alipay WHERE phone="{userphone}"'
sql4 = f'DELETE FROM t_user_platform_union WHERE phone="{userphone}"'
sql5= f'SELECT * FROM t_user_wechat WHERE phone="{userphone}"'
sql6 = f'SELECT * FROM t_user_alipay WHERE phone="{userphone}"'
try:
count1=cursor.execute(sql5)
if count1 >= 1:
print("查询到%d条微信账号数据" % count1)
cursor.execute(sql1)
connection.commit()
print("删除微信账号数据成功!")
else:
print("没有查询到有微信账号!")
count3 = cursor.execute(sql6)
if count3 >= 1:
print("查询到%d条支付宝账号数据" % count3)
cursor.execute(sql3)
connection.commit()
print("删除支付宝账号数据成功!")
else:
print("没有查询到有支付宝账号!")
cursor.execute(sql2)
cursor.execute(sql4)
connection.commit()
except Exception as e:
print("删除数据失败:case%s" % e)
QMessageBox.about(self, '提示', '删除数据失败!')
connection.rollback()
finally:
cursor.close()
connection.close()
def FindUser(self):
try:
connection = pymysql.connect(host="-6618.98.100.194", port=23306, user='root', password="ZKtest@2020",
db="web_db")
print('数据库连接成功!')
userphone = self.lineEdit_3.text()
cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)
sql7 = f'SELECT * FROM t_user_platform_union WHERE phone="{userphone}"'
cursor.execute(sql7)
subid=cursor.fetchall()[0]["sub_id"]
print('查询到userid是:'+f'{subid}')
reply = QMessageBox.information(self, "确认", "确认清除?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
if reply == QMessageBox.No:
print('退出')
pass
else:
try:
print("删除数据进行中...")
cursor = connection.cursor()
sql8 = f'DELETE FROM t_coupon_task_finish WHERE user_id="{subid}"'
cursor.execute(sql8)
connection.commit()
print("清除新手任务成功!")
except Exception as e:
print("删除数据失败:case%s" % e)
QMessageBox.about(self, '提示', '删除数据失败!')
connection.rollback()
finally:
cursor.close()
connection.close()
except Exception as e:
print(e)
def denglu(self):
username = self.lineEdit_9.text()
url = "https:managerlogin/gettoken"
payload = {"number": username, "password": "c4ca4238a0b923820dcc509a6f75849b","ime":"868597059438958"}
headers = {
'Content-Type': 'application/json',
}
try:
response = requests.post(url, headers=headers, json=payload)
print('收费员登录中...')
if response.json()["res"]["codeMsg"] == None:
print('收费员登录成功!')
print('请执行上班操作!')
self.token=response.json()["res"]["data"]["token"]
elif response.json()["res"]["codeMsg"].strip() == "用戶不存在":
print('用户不存在!')
else:
print('请求异常!')
except Exception as e:
print(e)
def shangban(self):
url = "https:alarm/work/start"
payload = {"roleId": 582, "roadId": ["316232857695551498"], "addr": "","latitude": "","longitude": ""}
headers = {
'authdst': '121609970406916096',
'linkid':'119761632728449025',
'userid':'121609970406916096',
'Content-Type': 'application/json'
}
try:
response = requests.post(url, headers=headers, json=payload)
print('收费员上班中...')
if response.json()["res"]["codeMsg"] == None:
print('收费员上班成功!')
print('请执行建单操作!')
else:
print("上班失败,厦门中卡测试2区已有人上班")
except Exception as e:
print(e)
def xiaban(self):
url = "https:alarm/work/end"
payload = {"roleId": 582, "roadId": ["316232857695551498"], "addr": "","latitude": "","longitude": ""}
headers = {
'authdst': '121609970406916096',
'linkid':'119761632728449025',
'userid':'121609970406916096',
'Content-Type': 'application/json'
}
try:
response = requests.post(url, headers=headers, json=payload)
print('收费员下班中...')
if response.json()["res"]["codeMsg"] == None:
print('收费员下班成功!')
else:
print("请求异常")
except Exception as e:
print(e)
def jiandan(self):
url = "https:rosideorder/order/create"
startTime=self.dateTimeEdit.text()
carno=self.lineEdit_5.text()
payload = {"parkId": "11112", "startTime": startTime, "carNo":carno,"enterpriseId": "119761632728449025","createName": "123","newEnergy": 0,"carType": 1}
headers = {
'authdst': '121609970406916096',
'linkid':'119761632728449025',
'userid':'121609970406916096',
'Content-Type': 'application/json'
}
try:
response = requests.post(url, headers=headers, json=payload)
print('创建订单中...')
if response.json()["res"]["codeMsg"] == None:
print('创建订单成功!')
else:
print("请求异常")
url = 'rosideorder/order/listex'
parms01 = {
'page': 1,'pageSize':10000,'status':1,'roadId':'316232857695551498','roleId':582
}
headers = {
'authdst': '121609970406916096',
'linkid': '119761632728449025',
'userid': '121609970406916096',
'Content-Type': 'application/json'
}
ret = requests.get(url, headers=headers, params=parms01)
for i in ret.json()["res"]["data"]["result"]["list"]:
if i["parkId"]== "11112":
self.lineEdit_13.setText(i["orderId"])
except Exception as e:
print(e)
def yijiaofei(self):
try:
url = "https:rosideorder/order/pay"
endTime=self.dateTimeEdit_3.text()
orderId=self.lineEdit_13.text()
payload = {"endTime": endTime, "orderId": orderId, "userName":"123","type": 0}
headers = {
'authdst': '121609970406916096',
'linkid':'119761632728449025',
'userid':'121609970406916096',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, json=payload)
print('结算订单中...')
if response.json()["res"]["codeMsg"] == None:
print('结算订单成功!')
else:
print("请求异常")
except Exception as e:
print(e)
def wijiaofei(self):
try:
url = "https:rosideorder/order/pay"
endTime=self.dateTimeEdit_3.text()
orderId=self.lineEdit_13.text()
payload = {"endTime": endTime, "orderId": orderId, "userName":"123","type": 1}
headers = {
'authdst': '121609970406916096',
'linkid':'119761632728449025',
'userid':'121609970406916096',
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, json=payload)
print('结算订单中...')
if response.json()["res"]["codeMsg"] == None:
print('结算订单成功!')
else:
print("请求异常")
except Exception as e:
print(e)
if __name__ == '__main__':
app = QApplication(sys.argv)
mc = MyClass()
sys.exit(app.exec_())
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)