本文主要是介绍提高测试人员测试效率之GUI工具,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
如何有效的去提高测试效率,在一个团队当中,肯定会存在部分人员无法熟悉数据库操作的情况,这个时候我们就可以通过GUI编程将工具界面会,使之快速的上手
本次通过一个GUI工具来带领大家如何制作这么个工具
功能实现页面如下图
以下部分代码未保密,隐藏数据库连接及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('退出')passelse:if self.comboBox.currentText()=="微信":clientType=0else:clientType=1phone=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): # 连接mysql数据库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('退出')passelse: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:# 执行SQL语句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}"'# 执行SQL语句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('退出')passelse: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)#print(ret.json()["res"]["data"]["result"]["list"])for i in ret.json()["res"]["data"]["result"]["list"]:#print(i)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_())
这篇关于提高测试人员测试效率之GUI工具的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!