python-archieve-projects/1.26 自动化测试/ui.py

174 lines
4.5 KiB
Python
Executable File

import sys
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import *
import testautomation_old as test
import os
class ui(QWidget):
def __init__(self):
super().__init__()
self.test1 = None
self.test2 = None
self.test3 = None
self.label = None
self.initUI()
def initUI(self):
self.setWindowTitle("自动化测试")
# 新增按钮
self.test1 = QPushButton('登录')
self.test2 = QPushButton('新增员工')
self.test3 = QPushButton('新增用户')
# 新建表格布局
grid = QGridLayout()
grid.setSpacing(50)
# 新增按钮到表格
grid.addWidget(self.test1, 1, 0, 5, 1)
grid.addWidget(self.test2, 1, 1, 5, 1)
grid.addWidget(self.test3, 1, 2, 5, 1)
# 绑定事件到按钮
self.test1.clicked.connect(self.login_test)
self.test2.clicked.connect(self.new_staff_test)
self.test3.clicked.connect(self.new_user_test)
self.setLayout(grid)
self.resize(500, 200)
self.setImage()
self.center()
self.show()
def login_test(self):
cnt = 1
result = test.login_test()
html = open('./result.html', 'w', encoding="utf-8")
html.write(
'''<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<table cellspacing="20" align="center">
<tr>
<th>ID</th>
<th>测试用例</th>
<th>测试结果</th>
</tr>''')
for i in result:
print(i)
html.write("<tr>")
html.write("<td>")
html.write(str(cnt))
html.write("</td>"
"<td>")
html.write(i.split('测试')[0])
html.write("</td>"
"<td>")
html.write(i.split(' ')[-1])
html.write("</td></tr>")
cnt += 1
html.write('''</table>
</body>
</html>''')
test.get_result()
def new_staff_test(self):
result = test.new_staff_test()
cnt=1
html = open('./result.html', 'w', encoding="utf-8")
html.write(
'''<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<table cellspacing="20" align="center">
<tr>
<th>ID</th>
<th>测试用例</th>
<th>测试结果</th>
</tr>''')
for i in result:
print(i)
html.write("<tr>")
html.write("<td>")
html.write(str(cnt))
html.write("</td>"
"<td>")
html.write(i.split('测试')[0])
html.write("</td>"
"<td>")
html.write(i.split(' ')[-1])
html.write("</td></tr>")
cnt+=1
html.write('''</table>
</body>
</html>''')
test.get_result()
def new_user_test(self):
result = test.new_ruser_test()
cnt = 1
html = open('./result.html', 'w', encoding="utf-8")
html.write(
'''<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<table cellspacing="20" align="center">
<tr>
<th>ID</th>
<th>测试用例</th>
<th>测试结果</th>
</tr>''')
for i in result:
print(i)
html.write("<tr>")
html.write("<td>")
html.write(str(cnt))
html.write("</td>"
"<td>")
html.write(i.split('测试')[0])
html.write("</td>"
"<td>")
html.write(i.split(' ')[-1])
html.write("</td></tr>")
cnt += 1
html.write('''</table>
</body>
</html>''')
test.get_result()
def setImage(self):
bg = QtGui.QImage()
bg.load(r'./bg.jpeg')
pa = QtGui.QPalette()
pa.setBrush(self.backgroundRole(), QtGui.QBrush(bg))
self.setPalette(pa)
self.setAutoFillBackground(True)
def closeEvent(self, event):
reply = QMessageBox.question(self, '退出', "确认退出吗?", QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore()
def center(self):
# 获得窗口
qr = self.frameGeometry()
# 获得屏幕中心点
cp = QDesktopWidget().availableGeometry().center()
# 显示到屏幕中心
qr.moveCenter(cp)
self.move(qr.topLeft())
if __name__ == '__main__':
app = QApplication(sys.argv)
ui = ui()
sys.exit(app.exec_())