Files
zentao-flow/tmp/pw_link_story_demo.py
T

67 lines
4.0 KiB
Python

# -*- coding: utf-8 -*-
"""演示:新建会议并关联用户需求 → 用户需求详情「需求讨论会议」tab 出现该会议"""
import io, sys, pymysql
from playwright.sync_api import sync_playwright
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
BASE = 'http://localhost:8089'
DB = dict(host='192.168.1.161', port=3306, user='devgps', password='dev@2021GPS', database='zentao_dev', charset='utf8mb4', autocommit=True)
USERSTORY_ID = 324
def db(sql, args=()):
conn = pymysql.connect(**DB); cur = conn.cursor(); cur.execute(sql, args)
r = cur.fetchone(); conn.close(); return r
with sync_playwright() as p:
b = p.chromium.launch(channel='chrome', headless=False, slow_mo=500, args=['--start-maximized'])
page = b.new_page(viewport={'width': 1500, 'height': 950})
page.goto(BASE, wait_until='domcontentloaded'); page.wait_for_timeout(2000)
page.locator('input[placeholder="用户名"]').fill('admin')
page.locator('input[placeholder="密码"]').fill('123456')
page.locator('text="登录"').first.click(); page.wait_for_timeout(6000)
page.goto(f'{BASE}/#/product-meeting/145', wait_until='domcontentloaded'); page.wait_for_timeout(5000)
page.locator('button.el-button--primary:has-text("会议纪要")').first.click(); page.wait_for_timeout(3000)
dlg = page.locator('.el-dialog:visible').last
print('>>> 会议类型选「需求会议」')
dlg.locator('.el-select').nth(1).click(); page.wait_for_timeout(1000)
page.locator('.el-select-dropdown:visible .el-select-dropdown__item:has-text("需求会议")').first.click(); page.wait_for_timeout(1500)
print('>>> 点「关联用户需求」')
dlg.locator('button:has-text("关联用户需求")').first.click(); page.wait_for_timeout(2500)
page.screenshot(path='tmp/pw_link_story_dialog.png', full_page=False)
# 内嵌「选择用户需求」弹窗:展开多选,勾第一个
inner = page.locator('.el-dialog:visible').last
inner.locator('.el-select').first.click(); page.wait_for_timeout(1500)
page.screenshot(path='tmp/pw_link_story_options.png', full_page=False)
page.locator('.el-select-dropdown:visible .el-select-dropdown__item').first.click(); page.wait_for_timeout(800)
page.keyboard.press('Escape'); page.wait_for_timeout(500)
inner.locator('button:has-text("确 定")').first.click(); page.wait_for_timeout(1500)
# 时间地点人员+富文本
dp = dlg.locator('input[placeholder="选择日期"]').first
dp.click(); page.wait_for_timeout(400); dp.fill('2026-07-29 16:00:00'); page.keyboard.press('Enter'); page.wait_for_timeout(400)
dlg.locator('.el-form-item:has-text("会议地点") input').fill('关联演示')
dlg.locator('.el-form-item:has-text("参会人") .el-select').first.click(); page.wait_for_timeout(1000)
page.locator('.el-select-dropdown:visible .el-select-dropdown__item').first.click(); page.wait_for_timeout(500)
page.keyboard.press('Escape'); page.wait_for_timeout(400)
for label, content in [('讨论的内容', '关联演示'), ('讨论的结果', '通过'), ('后续行动安排', '无')]:
ed = dlg.locator(f'.el-form-item:has-text("{label}") .ql-editor, .el-form-item:has-text("{label}") [contenteditable="true"]').first
ed.click(); page.wait_for_timeout(200); page.keyboard.type(content, delay=15)
page.screenshot(path='tmp/pw_link_story_form.png', full_page=False)
print('>>> 保存')
dlg.locator('button:has-text("确 定")').first.click(); page.wait_for_timeout(5000)
r = db("SELECT id, title, story_ids FROM zt_meeting ORDER BY id DESC LIMIT 1")
print('会议落库(含story_ids):', r)
print('>>> 打开用户需求详情,看「需求讨论会议」tab')
page.goto(f'{BASE}/#/product-user-story-info/{USERSTORY_ID}', wait_until='domcontentloaded'); page.wait_for_timeout(5000)
page.locator('text=需求讨论会议').first.click(); page.wait_for_timeout(3000)
page.screenshot(path='tmp/pw_link_story_tab.png', full_page=False)
print('>>> 完成,窗口停留 5 分钟')
page.wait_for_timeout(300000)
b.close()