# -*- coding: utf-8 -*- """票 12 补验 r2:取 contact/page 首行真值,回查 contact/search/customer/search""" import io, json, sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') from playwright.sync_api import sync_playwright URL = 'file:///E:/code/crm-backend-matt/.scratch/customer-demo-ref/demo/index.html' errors = [] out = {} with sync_playwright() as p: b = p.chromium.launch() pg = b.new_page(viewport={'width': 1720, 'height': 1080}) pg.on('pageerror', lambda e: errors.append(str(e))) pg.goto(URL) pg.wait_for_timeout(600) pg.fill('#uidInput', '739564171091247104') pg.evaluate('loginByUid()') pg.wait_for_timeout(2500) out['page0'] = pg.evaluate('''async () => { const d = await api('/api/customer/contact/page?current=1&size=3'); return (d && d.content || []).map(r => ({ name: r.name, phone: r.phone, source: r.source, customerName: r.customerName })); }''') out['search_by_row_name'] = pg.evaluate('''async () => { const d = await api('/api/customer/contact/page?current=1&size=1'); const nm = d && d.content && d.content[0] && d.content[0].name; if (!nm) return 'no-row'; const arr = await api('/api/customer/contact/search?keyword=' + encodeURIComponent(nm) + '&limit=20'); return { kw: nm, n: (arr || []).length, phone0: arr && arr[0] ? arr[0].phone : null }; }''') out['ws_page0'] = pg.evaluate('''async () => { const d = await api('/api/customer/workspace/page', { method: 'POST', body: 'workspace=mine¤t=1&size=3&archiveStatus=1' }); return { total: d && d.total, rows: (d && d.content || []).map(r => ({ customerName: r.customerName, ownerNameSnapshot: r.ownerNameSnapshot })) }; }''') b.close() out['pageerror'] = errors print(json.dumps(out, ensure_ascii=False, indent=1))