-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathbotfather-e2e.js
More file actions
124 lines (109 loc) · 4.33 KB
/
Copy pathbotfather-e2e.js
File metadata and controls
124 lines (109 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const { chromium } = require('@playwright/test');
(async () => {
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
const BASE = 'http://localhost:82';
const USER = 'test_user_a';
const PASS = process.env.BOTFATHER_PASS;
if (!PASS) {
console.error('BOTFATHER_PASS environment variable is required');
process.exit(1);
}
console.log('=== 1. 登录 ===');
await page.goto(BASE);
await page.waitForTimeout(2000);
await page.getByPlaceholder('手机号或用户名').fill(USER);
await page.locator('input[name="password"]').fill(PASS);
await page.getByRole('button', { name: '登录', exact: true }).click();
try {
await page.getByRole('button', { name: '登录', exact: true }).waitFor({ state: 'hidden', timeout: 15000 });
console.log('✅ 登录成功');
} catch {
console.log('❌ 登录失败');
await page.screenshot({ path: '/tmp/e2e-login-fail.png' });
await browser.close();
return;
}
await page.waitForTimeout(3000);
await page.screenshot({ path: '/tmp/e2e-01-main.png' });
console.log('📸 主界面截图: /tmp/e2e-01-main.png');
// 2. 找到 BotFather 会话
console.log('\n=== 2. 找 BotFather ===');
// 搜索 botfather
const searchInput = await page.$('input[placeholder*="搜索"]');
if (searchInput) {
await searchInput.fill('BotFather');
await page.waitForTimeout(2000);
await page.screenshot({ path: '/tmp/e2e-02-search.png' });
console.log('📸 搜索截图: /tmp/e2e-02-search.png');
// 点击搜索结果
const result = await page.$('text=BotFather');
if (result) {
await result.click();
await page.waitForTimeout(2000);
console.log('✅ 找到 BotFather');
} else {
console.log('❌ 搜索结果中没找到 BotFather');
}
} else {
console.log('⚠️ 没找到搜索框,尝试直接找会话列表');
}
await page.screenshot({ path: '/tmp/e2e-03-botfather.png' });
console.log('📸 BotFather 截图: /tmp/e2e-03-botfather.png');
// 3. 发送 /newbot
console.log('\n=== 3. 发送 /newbot ===');
const msgInput = await page.$('[contenteditable="true"], textarea[placeholder*="消息"], input[placeholder*="消息"]');
if (msgInput) {
await msgInput.click();
await page.keyboard.type('/newbot');
await page.keyboard.press('Enter');
console.log('✅ 发送 /newbot');
await page.waitForTimeout(3000);
await page.screenshot({ path: '/tmp/e2e-04-newbot.png' });
console.log('📸 /newbot 截图: /tmp/e2e-04-newbot.png');
// 4. 发送 Bot 名称
console.log('\n=== 4. 发送 Bot 名称 ===');
await page.keyboard.type('E2E全流程Bot');
await page.keyboard.press('Enter');
await page.waitForTimeout(3000);
await page.screenshot({ path: '/tmp/e2e-05-name.png' });
// 5. 发送 Username
console.log('\n=== 5. 发送 Username ===');
await page.keyboard.type('e2e_full_flow_bot');
await page.keyboard.press('Enter');
await page.waitForTimeout(3000);
await page.screenshot({ path: '/tmp/e2e-06-username.png' });
console.log('📸 创建完成截图: /tmp/e2e-06-username.png');
} else {
console.log('❌ 没找到消息输入框');
}
// 截最终状态
await page.screenshot({ path: '/tmp/e2e-07-final.png' });
// 获取页面上的最新文本(找 bf_ token)
const bodyText = await page.textContent('body');
const tokenMatch = bodyText.match(/bf_[a-f0-9]+/);
if (tokenMatch) {
console.log(`\n🎉 获得 Bot Token: ${tokenMatch[0]}`);
} else {
console.log('\n⚠️ 页面上未找到 bf_ token');
}
// 6. 查看群聊
console.log('\n=== 6. 回到群聊列表 ===');
// 搜索测试群
if (searchInput || await page.$('input[placeholder*="搜索"]')) {
const search2 = await page.$('input[placeholder*="搜索"]');
if (search2) {
await search2.fill('AI协作测试群');
await page.waitForTimeout(2000);
const groupResult = await page.$('text=AI协作测试群');
if (groupResult) {
await groupResult.click();
await page.waitForTimeout(2000);
console.log('✅ 进入 AI协作测试群');
await page.screenshot({ path: '/tmp/e2e-08-group.png' });
}
}
}
await browser.close();
console.log('\n=== 测试完成 ===');
})();