An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
-
齐 振鋆 authoreddfe9909a
# -*- coding:utf-8 -*-
import argparse
import os
import flet
import pytest
from flet import ResponsiveRow, Column, ElevatedButton, Text, TextField, Dropdown, icons, FilePickerResultEvent, \
FilePicker, alignment, Container, dropdown, KeyboardType
from flet import Ref
from unit.public.DataDic import DataDic
dd = DataDic()
def py_run():
tab_code = dd.get_value('tab')
if tab_code is None:
pytest.main(['cases/UI/{}/{}'.format(dd.get_value('project'), dd.get_value('module'))])
else:
pytest.main(
['cases/UI/{}/{}'.format(dd.get_value('project'), dd.get_value('module')), '-m', tab_code])
# allure generate allure-results -o allure-report --clean
os.system("allure generate allure-results -o allure-report --clean")
def get_command_args():
"""命令行参数解析"""
parser = argparse.ArgumentParser(description=u'可选择参数:')
parser.add_argument("--client", default='localhost', help="client:客户端IP")
parser.add_argument("--project", default='GuKeYiTiHua', help="project:项目")
# url: 'http://10.17.65.216:8088/portal/' 'http://10.17.65.200:8088/portal/'
parser.add_argument("--url", default='http://10.17.65.216:8088/portal/', help="url: 地址")
# ;手术跟台: surgery | 采购管理:purchase | 调拨管理: Transfer | 库存管理:inventory | 调试:debug
parser.add_argument("--module", default='purchase', help="module:模块")
parser.add_argument("--tab", default='purchase', help="tab:标记")
parser.add_argument("--order", help="order: 单据编码")
parser.add_argument("--co", help="co: 公司")
parser.add_argument("--wh", help="wh: 仓库")
parser.add_argument("--good", help="good: 商品")
parser.add_argument("--num", help="num: 数量")
args = parser.parse_args()
dd.set_value('client', args.client)
dd.set_value('project', args.project)
dd.set_value('url', args.url)
dd.set_value('module', args.module)
dd.set_value('tab', args.tab)
dd.set_value('order', args.order)
dd.set_value('company', args.co)
dd.set_value('warehouse', args.wh)
dd.set_value('custGood', args.good)
dd.set_value('custNum', args.num)
py_run()
def get_ui_args(page):
page.title = "国药自动化测试启动器"
client_ip = Ref[TextField]()
test_url = Ref[TextField]()
project_name = Ref[Dropdown]()
module_name = Ref[Dropdown]()
tab_name = Ref[Dropdown]()
test_file = Ref[TextField]()
greetings = Ref[Column]()
def run(e):
greetings.current.controls.append(
Text(f"【测试环境】:{test_url.current.value}")
)
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
greetings.current.controls.append(
Text(f"【项目】:{project_name.current.value}-【模块】:{module_name.current.value}-【标签】:{tab_name.current.value}")
)
page.update()
dd.set_value('client', client_ip.current.value)
p_name = project_name.current.value
p_code = 'GuKeYiTiHua' if p_name == '骨科一体化' else 'TestProject'
dd.set_value('project', p_code)
dd.set_value('url', test_url.current.value)
m_name = module_name.current.value
m_code = 'purchase' if m_name == '采购管理' \
else 'surgery' if m_name == '手术跟台' \
else 'transfer' if m_name == '调拨管理' \
else None
dd.set_value('module', m_code)
t_name = tab_name.current.value
t_code = 'all' if t_name == '全量' else 'smoking' if t_name == '冒烟' else 'debug' if t_name == '调试' else None
dd.set_value('tab', t_code)
py_run()
def stop(e):
dd.get_value('driver').close()
dd.get_value('driver').quit()
def module_update(e):
m_options = []
module_list = ['采购管理', '手术跟台', '调拨管理'] if project_name.current.value == '骨科一体化' \
else ['模块1', '模块2', '模块3'] if project_name.current.value == '测试项目' \
else []
for m_item in module_list:
m_options.append(dropdown.Option(m_item))
module.options = m_options
page.update()
def pick_files_result(e: FilePickerResultEvent):
selected_files.value = (
e.files[0].path if e.files else "Cancelled!"
)
selected_files.update()
test_data_file = test_file.current.value
dd.set_value('test_data_file', test_data_file)
client = TextField(ref=client_ip, label="客户端地址", icon=icons.BOY, autofocus=True, value='localhost',
read_only=True, )
url = TextField(ref=test_url, label="测试环境", icon=icons.HTTP, keyboard_type=KeyboardType.URL, value='http://10.17.65.216:8088/portal/r/w')
project_options = []
for item in ['骨科一体化', '测试项目']:
project_options.append(dropdown.Option(item))
project = Dropdown(ref=project_name, label="项目名称", icon=icons.HOUSE, options=project_options,
on_change=module_update)
module_options = []
module = Dropdown(ref=module_name, label="模块名称", icon=icons.MOOD, options=module_options)
tab_options = []
for item in ['全量', '冒烟', '调试']:
tab_options.append(dropdown.Option(item))
tab = Dropdown(ref=tab_name, label="标签名称", icon=icons.TAB, options=tab_options)
file = ElevatedButton(
"测试数据文件",
on_click=lambda _: pick_files_dialog.pick_files(
allow_multiple=False,
allowed_extensions=["yaml"]
),
)
pick_files_dialog = FilePicker(on_result=pick_files_result)
selected_files = TextField(ref=test_file, label="测试数据", icon=icons.DATASET, read_only=True, )
page.overlay.append(pick_files_dialog)
page.add(
Container(client, col={"sm": 6, "md": 4, "xl": 2}),
141142143144145146147148149150151152153154155156157158159160
Container(url, col={"sm": 6, "md": 4, "xl": 2}),
Container(project, col={"sm": 6, "md": 4, "xl": 2}),
Container(module, col={"sm": 6, "md": 4, "xl": 2}),
Container(tab, col={"sm": 6, "md": 4, "xl": 2}),
ResponsiveRow([
Container(selected_files, col={"sm": 10}),
Container(file, col={"sm": 2}),
]),
ResponsiveRow([
Container(ElevatedButton("运行", on_click=run), col={"sm": 1}, alignment=alignment.center),
Container(ElevatedButton("停止", on_click=stop), col={"sm": 1}, alignment=alignment.center),
]),
Container(Column(ref=greetings), )
)
if __name__ == '__main__':
UI = False # 运行模式
flet.app(target=get_ui_args) if UI is True else get_command_args()