Files

60 lines
3.0 KiB
Python

# -*- coding: utf-8 -*-
"""CHG-037 绩效弹窗分岗位验证:月报→绩效按钮→截图+关键行断言"""
import io, sys
from playwright.sync_api import sync_playwright
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
BASE = 'http://localhost:8088'
TARGETS = [
('jiangheng', '蒋恒', ['需求PRD工作量指标完成率', '团队工作量指标完成率', '版本计划完成率', '项目工作流程完整、工作文档齐备', '专业技能持续提升']),
]
with sync_playwright() as p:
b = p.chromium.launch(channel='chrome', headless=True, args=['--start-maximized'])
page = b.new_page(viewport={'width': 1600, 'height': 1000})
page.goto(BASE, wait_until='domcontentloaded'); page.wait_for_timeout(2500)
page.locator('input[placeholder="用户名"]').fill('admin')
page.locator('input[placeholder="密码"]').fill('123456')
page.locator('text="登录"').first.click(); page.wait_for_timeout(8000)
page.goto(f'{BASE}/#/worktime/count', wait_until='domcontentloaded'); page.wait_for_timeout(8000)
page.locator('.el-tabs__item:has-text("月报"):visible').first.click(); page.wait_for_timeout(5000)
# 切到 6 月(当前 7 月无数据)
page.locator('button:has-text("上月"):visible').first.click(); page.wait_for_timeout(1000)
page.locator('button:has-text("查询"):visible').first.click()
# 等 6 月列表真正加载(7 月为空的标志是任何行出现)
try:
page.wait_for_selector('tr:has-text("王宇航")', timeout=25000)
except Exception:
page.screenshot(path='tmp/pw_chg037_nolist.png', full_page=True)
print('6 月列表加载超时,截图 tmp/pw_chg037_nolist.png')
b.close(); raise SystemExit(1)
page.wait_for_timeout(2000)
for account, cname, keys in TARGETS:
row = page.locator(f'tr:has-text("{cname}")').first
if row.count() == 0:
row = page.locator(f'tr:has-text("{account}")').first
if row.count() == 0:
print(f'[{account}] 月报列表未找到 {cname}/{account} 行,跳过')
continue
btn = row.locator('button:has-text("绩效")')
if btn.count() == 0:
print(f'[{account}] 无绩效按钮,跳过')
continue
btn.first.click(); page.wait_for_timeout(5000)
body = page.locator('body').inner_text()
miss = [k for k in keys if k not in body]
page.screenshot(path=f'tmp/pw_chg037_{account}.png', full_page=True)
print(f'[{account}] {"PASS" if not miss else "MISS:" + str(miss)} 截图 tmp/pw_chg037_{account}.png')
# 关闭弹窗
closed = False
for sel in ['.el-dialog__close', 'button:has-text("取 消")', 'button:has-text("取消")']:
loc = page.locator(sel)
if loc.count():
try:
loc.first.click(); closed = True; break
except Exception:
pass
if not closed:
page.keyboard.press('Escape')
page.wait_for_timeout(2000)
b.close()
print('done')