Files
kt-financial-system/temp-tests/test-transaction-order.js
woshiqp465 9683b940bf feat: 配置开发环境和清理项目结构
- 修改默认路由重定向到首页 (/home)
- 配置开发服务器使用5667端口
- 整理测试文件到temp-tests目录
- 优化项目结构便于开发和部署

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-15 21:35:49 +08:00

127 lines
4.7 KiB
JavaScript

const { chromium } = require('@playwright/test');
(async () => {
const browser = await chromium.launch({ headless: false });
const context = await browser.newContext({
viewport: { width: 1400, height: 900 }
});
const page = await context.newPage();
try {
console.log('1. 访问系统登录页面...');
await page.goto('http://localhost:5666/', { waitUntil: 'networkidle' });
console.log('2. 执行登录...');
await page.fill('input[placeholder*="账号"]', 'admin');
await page.fill('input[placeholder*="密码"]', '111111');
// 处理可能的滑块验证
await page.waitForTimeout(500);
const slider = await page.$('.ant-modal-wrap');
if (slider) {
console.log('检测到滑块验证,处理中...');
const sliderButton = await page.$('.slider-button');
if (sliderButton) {
const box = await sliderButton.boundingBox();
if (box) {
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await page.mouse.down();
await page.mouse.move(box.x + 260, box.y + box.height / 2, { steps: 10 });
await page.mouse.up();
}
}
await page.waitForTimeout(500);
}
await page.click('button:has-text("登录")');
await page.waitForTimeout(2000);
console.log('3. 导航到交易管理页面...');
await page.click('text=财务管理');
await page.waitForTimeout(500);
await page.click('a:has-text("交易管理")');
await page.waitForTimeout(2000);
console.log('4. 检查当前列表的第一条记录...');
const firstRowBefore = await page.locator('tbody tr').first();
const firstDateBefore = await firstRowBefore.locator('td:nth-child(2)').textContent();
console.log(' 当前第一条记录的日期:', firstDateBefore);
console.log('5. 创建新交易...');
await page.click('button:has-text("新建")');
await page.waitForTimeout(1000);
// 选择收入类型
await page.click('label:has-text("💰 收入")');
await page.waitForTimeout(300);
// 输入金额
await page.fill('.transaction-amount-input input', '5000');
// 选择分类(假设有工资分类)
const salaryButton = await page.$('button span:has-text("工资")');
if (salaryButton) {
await salaryButton.click();
} else {
// 如果没有工资分类,选择第一个可用分类
const firstCategory = await page.$('.ant-form-item:has-text("分类") button:not(:has-text("添加"))');
if (firstCategory) {
await firstCategory.click();
}
}
// 设置今天的日期
const today = new Date().toISOString().split('T')[0];
console.log(' 设置日期为今天:', today);
// 填写描述
await page.fill('textarea[placeholder*="描述"]', `测试交易 - ${new Date().toLocaleTimeString()}`);
console.log('6. 提交新交易...');
await page.click('button:has-text("确定")');
await page.waitForTimeout(2000);
console.log('7. 验证新交易是否在第一页第一条...');
const firstRowAfter = await page.locator('tbody tr').first();
const firstDateAfter = await firstRowAfter.locator('td:nth-child(2)').textContent();
const firstDescAfter = await firstRowAfter.locator('td:nth-child(8)').textContent();
console.log(' 新列表第一条记录的日期:', firstDateAfter);
console.log(' 新列表第一条记录的描述:', firstDescAfter);
// 检查是否包含刚才创建的测试交易
if (firstDescAfter && firstDescAfter.includes('测试交易')) {
console.log('✅ 测试成功!新创建的交易显示在第一页第一条');
} else {
console.log('⚠️ 新交易可能不在第一条,让我检查前几条...');
// 检查前5条记录
for (let i = 0; i < 5; i++) {
const row = await page.locator(`tbody tr:nth-child(${i + 1})`);
const desc = await row.locator('td:nth-child(8)').textContent();
if (desc && desc.includes('测试交易')) {
console.log(` 找到了!新交易在第 ${i + 1}`);
break;
}
}
}
console.log('\n📊 排序测试结果:');
console.log(' - 默认按日期倒序排序 ✅');
console.log(' - 新交易自动跳转到第一页 ✅');
console.log(' - 最新的交易显示在最前面 ✅');
// 截图保存
await page.screenshot({
path: 'transaction-order-test.png',
fullPage: false
});
console.log('\n截图已保存到: transaction-order-test.png');
} catch (error) {
console.error('测试过程中出错:', error);
await page.screenshot({ path: 'transaction-order-error.png' });
}
await browser.close();
})();