Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
280 lines
11 KiB
JavaScript
280 lines
11 KiB
JavaScript
const { test, expect } = require('@playwright/test');
|
||
|
||
/**
|
||
* 统一注册系统端到端测试 - 修复版
|
||
* 测试批量注册功能的完整流程
|
||
*/
|
||
|
||
test.describe('统一注册系统测试 - 修复版', () => {
|
||
test.beforeEach(async ({ page }) => {
|
||
// 设置视口大小
|
||
await page.setViewportSize({ width: 1920, height: 1080 });
|
||
|
||
// 访问系统首页并登录
|
||
await page.goto('http://localhost:8890');
|
||
await page.waitForLoadState('networkidle');
|
||
|
||
// 检查是否需要登录
|
||
const loginButton = await page.locator('button:has-text("登录")').first();
|
||
if (await loginButton.isVisible()) {
|
||
// 填写登录信息
|
||
await page.locator('input[type="text"]').first().fill('admin');
|
||
await page.locator('input[type="password"]').first().fill('111111');
|
||
await loginButton.click();
|
||
await page.waitForTimeout(3000);
|
||
await page.waitForLoadState('networkidle');
|
||
}
|
||
});
|
||
|
||
test('1. 页面访问和布局验证', async ({ page }) => {
|
||
console.log('🧪 测试1: 页面访问和布局验证');
|
||
|
||
// 1.1 直接访问统一注册页面(更可靠的方式)
|
||
console.log('📍 步骤 1.1: 直接访问统一注册系统页面');
|
||
await page.goto('http://localhost:8890/#/tgAccountManage/unifiedRegister');
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 1.2 验证页面URL
|
||
console.log('📍 步骤 1.2: 验证页面URL');
|
||
await expect(page).toHaveURL(/.*unifiedRegister.*/, { timeout: 5000 });
|
||
console.log('✅ 页面URL正确');
|
||
|
||
// 1.3 验证页面标题
|
||
console.log('📍 步骤 1.3: 验证页面标题和描述');
|
||
await expect(page.locator('h2:has-text("统一注册系统")')).toBeVisible();
|
||
await expect(page.locator('text=基于策略模式的Telegram账号注册系统')).toBeVisible();
|
||
console.log('✅ 页面标题和描述显示正确');
|
||
|
||
// 1.4 验证策略选择区域
|
||
console.log('📍 步骤 1.4: 验证策略选择区域');
|
||
await expect(page.locator('text=选择注册策略')).toBeVisible();
|
||
await expect(page.locator('text=批量注册')).toBeVisible();
|
||
await expect(page.locator('text=连续注册')).toBeVisible();
|
||
console.log('✅ 策略选择区域显示正确');
|
||
|
||
// 1.5 验证配置面板
|
||
console.log('📍 步骤 1.5: 验证配置面板');
|
||
await expect(page.locator('text=注册配置')).toBeVisible();
|
||
await expect(page.locator('text=基础配置')).toBeVisible();
|
||
console.log('✅ 配置面板显示正确');
|
||
|
||
// 1.6 验证操作按钮
|
||
console.log('📍 步骤 1.6: 验证操作按钮');
|
||
await expect(page.locator('button:has-text("开始注册")')).toBeVisible();
|
||
await expect(page.locator('button:has-text("暂停")')).toBeVisible();
|
||
await expect(page.locator('button:has-text("停止注册")')).toBeVisible();
|
||
console.log('✅ 操作按钮显示正确');
|
||
});
|
||
|
||
test('2. 批量注册策略配置测试', async ({ page }) => {
|
||
console.log('🧪 测试2: 批量注册策略配置测试');
|
||
|
||
// 导航到页面
|
||
await page.goto('http://localhost:8890/#/tgAccountManage/unifiedRegister');
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 2.1 选择批量注册策略
|
||
console.log('📍 步骤 2.1: 选择批量注册策略');
|
||
const batchRadio = page.locator('input[type="radio"][value="batch"]');
|
||
await batchRadio.check();
|
||
console.log('✅ 批量注册策略已选择');
|
||
|
||
// 2.2 验证批量注册特定配置显示
|
||
console.log('📍 步骤 2.2: 验证批量注册配置选项');
|
||
await expect(page.locator('text=批量注册配置')).toBeVisible();
|
||
await expect(page.locator('text=注册数量')).toBeVisible();
|
||
await expect(page.locator('text=并发数')).toBeVisible();
|
||
await expect(page.locator('text=任务间隔')).toBeVisible();
|
||
console.log('✅ 批量注册配置选项显示正确');
|
||
|
||
// 2.3 填写基础配置
|
||
console.log('📍 步骤 2.3: 填写基础配置');
|
||
|
||
// 选择国家
|
||
const countrySelect = page.locator('select').first();
|
||
if (await countrySelect.isVisible()) {
|
||
await countrySelect.selectOption('1'); // 俄罗斯
|
||
console.log('✅ 国家已选择');
|
||
}
|
||
|
||
// 选择用途
|
||
const usageSelect = page.locator('select').nth(1);
|
||
if (await usageSelect.isVisible()) {
|
||
await usageSelect.selectOption('1'); // 营销推广
|
||
console.log('✅ 用途已选择');
|
||
}
|
||
|
||
// 填写AI名字提示词
|
||
const namePromptInput = page.locator('input[placeholder*="AI生成名字"]');
|
||
if (await namePromptInput.isVisible()) {
|
||
await namePromptInput.fill('生成英文名字');
|
||
console.log('✅ AI名字提示词已填写');
|
||
}
|
||
|
||
// 2.4 配置批量注册参数
|
||
console.log('📍 步骤 2.4: 配置批量注册参数');
|
||
|
||
// 设置注册数量
|
||
const quantityInput = page.locator('input[type="number"]').first();
|
||
if (await quantityInput.isVisible()) {
|
||
await quantityInput.fill('5');
|
||
console.log('✅ 注册数量设置为5');
|
||
}
|
||
|
||
// 设置并发数
|
||
const concurrencyInput = page.locator('input[type="number"]').nth(1);
|
||
if (await concurrencyInput.isVisible()) {
|
||
await concurrencyInput.fill('2');
|
||
console.log('✅ 并发数设置为2');
|
||
}
|
||
|
||
// 设置任务间隔
|
||
const intervalInput = page.locator('input[type="number"]').nth(2);
|
||
if (await intervalInput.isVisible()) {
|
||
await intervalInput.fill('3000');
|
||
console.log('✅ 任务间隔设置为3000ms');
|
||
}
|
||
});
|
||
|
||
test('3. 连续注册策略配置测试', async ({ page }) => {
|
||
console.log('🧪 测试3: 连续注册策略配置测试');
|
||
|
||
// 导航到页面
|
||
await page.goto('http://localhost:8890/#/tgAccountManage/unifiedRegister');
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 3.1 选择连续注册策略
|
||
console.log('📍 步骤 3.1: 选择连续注册策略');
|
||
const continuousRadio = page.locator('input[type="radio"][value="continuous"]');
|
||
await continuousRadio.check();
|
||
console.log('✅ 连续注册策略已选择');
|
||
|
||
// 3.2 验证连续注册特定配置显示
|
||
console.log('📍 步骤 3.2: 验证连续注册配置选项');
|
||
await expect(page.locator('text=连续注册配置')).toBeVisible();
|
||
console.log('✅ 连续注册配置选项显示正确');
|
||
|
||
// 3.3 检查连续注册特有的配置项
|
||
console.log('📍 步骤 3.3: 检查连续注册配置项');
|
||
|
||
// 等待配置面板更新
|
||
await page.waitForTimeout(1000);
|
||
|
||
// 检查是否有QPS相关配置
|
||
const configElements = await page.locator('.config-item, .form-item').count();
|
||
console.log(`✅ 配置项数量: ${configElements}`);
|
||
});
|
||
|
||
test('4. 功能按钮状态测试', async ({ page }) => {
|
||
console.log('🧪 测试4: 功能按钮状态测试');
|
||
|
||
// 导航到页面并配置
|
||
await page.goto('http://localhost:8890/#/tgAccountManage/unifiedRegister');
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 配置批量注册
|
||
const batchRadio = page.locator('input[type="radio"][value="batch"]');
|
||
await batchRadio.check();
|
||
|
||
// 4.1 验证初始按钮状态
|
||
console.log('📍 步骤 4.1: 验证初始按钮状态');
|
||
const startButton = page.locator('button:has-text("开始注册")');
|
||
const pauseButton = page.locator('button:has-text("暂停")');
|
||
const stopButton = page.locator('button:has-text("停止注册")');
|
||
|
||
// 检查按钮可见性
|
||
await expect(startButton).toBeVisible();
|
||
await expect(pauseButton).toBeVisible();
|
||
await expect(stopButton).toBeVisible();
|
||
console.log('✅ 所有功能按钮都可见');
|
||
|
||
// 4.2 测试按钮交互(不实际启动注册)
|
||
console.log('📍 步骤 4.2: 测试按钮交互');
|
||
|
||
// 填写最少必要配置
|
||
const quantityInput = page.locator('input[type="number"]').first();
|
||
if (await quantityInput.isVisible()) {
|
||
await quantityInput.fill('1');
|
||
}
|
||
|
||
// 检查开始按钮是否可点击
|
||
if (await startButton.isEnabled()) {
|
||
console.log('✅ 开始按钮在配置完成后可用');
|
||
} else {
|
||
console.log('ℹ️ 开始按钮需要更多配置才能启用');
|
||
}
|
||
});
|
||
|
||
test('5. 响应式布局测试', async ({ page }) => {
|
||
console.log('🧪 测试5: 响应式布局测试');
|
||
|
||
await page.goto('http://localhost:8890/#/tgAccountManage/unifiedRegister');
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 5.1 桌面尺寸测试
|
||
console.log('📍 步骤 5.1: 桌面尺寸布局测试');
|
||
await page.setViewportSize({ width: 1920, height: 1080 });
|
||
await page.waitForTimeout(1000);
|
||
|
||
const pageContent = page.locator('h2:has-text("统一注册系统")');
|
||
await expect(pageContent).toBeVisible();
|
||
console.log('✅ 桌面尺寸布局正常');
|
||
|
||
// 5.2 平板尺寸测试
|
||
console.log('📍 步骤 5.2: 平板尺寸布局测试');
|
||
await page.setViewportSize({ width: 1024, height: 768 });
|
||
await page.waitForTimeout(1000);
|
||
|
||
await expect(pageContent).toBeVisible();
|
||
console.log('✅ 平板尺寸布局正常');
|
||
|
||
// 5.3 手机尺寸测试
|
||
console.log('📍 步骤 5.3: 手机尺寸布局测试');
|
||
await page.setViewportSize({ width: 375, height: 667 });
|
||
await page.waitForTimeout(1000);
|
||
|
||
await expect(pageContent).toBeVisible();
|
||
console.log('✅ 手机尺寸布局正常');
|
||
|
||
// 恢复桌面尺寸
|
||
await page.setViewportSize({ width: 1920, height: 1080 });
|
||
});
|
||
|
||
test('6. 配置验证测试', async ({ page }) => {
|
||
console.log('🧪 测试6: 配置验证测试');
|
||
|
||
await page.goto('http://localhost:8890/#/tgAccountManage/unifiedRegister');
|
||
await page.waitForLoadState('networkidle');
|
||
await page.waitForTimeout(2000);
|
||
|
||
// 6.1 测试必填字段验证
|
||
console.log('📍 步骤 6.1: 测试必填字段验证');
|
||
|
||
// 选择批量注册
|
||
const batchRadio = page.locator('input[type="radio"][value="batch"]');
|
||
await batchRadio.check();
|
||
|
||
// 尝试不填写配置直接点击开始
|
||
const startButton = page.locator('button:has-text("开始注册")');
|
||
|
||
// 检查按钮初始状态
|
||
const initiallyEnabled = await startButton.isEnabled();
|
||
console.log(`ℹ️ 开始按钮初始状态: ${initiallyEnabled ? '启用' : '禁用'}`);
|
||
|
||
// 6.2 填写有效配置
|
||
console.log('📍 步骤 6.2: 填写有效配置');
|
||
|
||
// 填写数字配置
|
||
const inputs = await page.locator('input[type="number"]').all();
|
||
for (let i = 0; i < inputs.length && i < 3; i++) {
|
||
await inputs[i].fill((i + 1).toString());
|
||
}
|
||
|
||
console.log('✅ 配置验证测试完成');
|
||
});
|
||
}); |