| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- const CONFIG = {
- webUrl: 'http://192.168.16.18:8082',
- admin: { phone: '13800138000', password: 'admin123' }
- };
- async function navigate(url) {
- return await skill_mcp({ mcp_name: 'playwright', tool_name: 'browser_navigate', arguments: { url } });
- }
- async function snapshot() {
- return await skill_mcp({ mcp_name: 'playwright', tool_name: 'browser_snapshot', arguments: {} });
- }
- async function click(ref) {
- return await skill_mcp({ mcp_name: 'playwright', tool_name: 'browser_click', arguments: { target: ref } });
- }
- async function type(ref, text) {
- return await skill_mcp({ mcp_name: 'playwright', tool_name: 'browser_type', arguments: { target: ref, text } });
- }
- async function wait(seconds) {
- return await skill_mcp({ mcp_name: 'playwright', tool_name: 'browser_wait_for', arguments: { time: seconds } });
- }
- async function screenshot(filename) {
- return await skill_mcp({ mcp_name: 'playwright', tool_name: 'browser_take_screenshot', arguments: { type: 'png', filename } });
- }
- async function loginAdmin() {
- console.log('[登录] 开始管理员登录...');
- await navigate(CONFIG.webUrl);
- await wait(2);
-
- const snap = await snapshot();
- console.log('[登录] 页面快照:', snap.substring(0, 500));
-
- await type('e11', CONFIG.admin.phone);
- await type('e17', CONFIG.admin.password);
- await wait(1);
-
- await click('e22');
- await wait(3);
-
- const afterSnap = await snapshot();
- console.log('[登录] 登录后页面:', afterSnap.substring(0, 300));
-
- if (afterSnap.includes('dashboard') || afterSnap.includes('首页')) {
- console.log('[登录] 登录成功 ✅');
- return true;
- }
- console.log('[登录] 登录后未发现 dashboard');
- return false;
- }
- async function testWEB001() {
- console.log('\n=== TEST: WEB-001 管理员登录 ===');
- const passed = await loginAdmin();
- console.log(`WEB-001: ${passed ? 'PASSED ✅' : 'FAILED ❌'}`);
- return passed;
- }
- async function testWEB002() {
- console.log('\n=== TEST: WEB-002 管理员查看用户列表 ===');
- const loginOk = await loginAdmin();
- if (!loginOk) return false;
-
- await click('e41');
- await wait(1);
- await click('e153');
- await wait(2);
-
- const snap = await snapshot();
- const passed = snap.includes('用户管理') || snap.includes('用户列表');
- console.log(`WEB-002: ${passed ? 'PASSED ✅' : 'FAILED ❌'}`);
- return passed;
- }
- async function runTests() {
- console.log('===== 知心益家 MCP 测试 =====');
-
- const results = [];
-
- results.push({ id: 'WEB-001', result: await testWEB001() });
- results.push({ id: 'WEB-002', result: await testWEB002() });
-
- console.log('\n===== 结果汇总 =====');
- let passed = 0, failed = 0;
- for (const r of results) {
- console.log(`${r.id}: ${r.result ? 'PASSED' : 'FAILED'}`);
- if (r.result) passed++; else failed++;
- }
- console.log(`总计: ${passed} 通过, ${failed} 失败`);
-
- return results;
- }
- module.exports = { runTests, testWEB001, testWEB002 };
- if (require.main === module) {
- runTests();
- }
|