08ea5fbe98
添加用户管理视图、API和状态管理文件
262 lines
9.0 KiB
TypeScript
262 lines
9.0 KiB
TypeScript
import { test, expect } from '../fixtures/test-fixtures';
|
|
|
|
test.describe('Uniapp黄历功能测试', () => {
|
|
test.beforeEach(async ({ page, testConfig, testLogger }) => {
|
|
testLogger.startTest('Uniapp黄历功能测试');
|
|
await page.goto(testConfig.getEnvironment().uniappBaseURL);
|
|
});
|
|
|
|
test.afterEach(async ({ testLogger }) => {
|
|
testLogger.endTest('Uniapp黄历功能测试', 'passed');
|
|
});
|
|
|
|
test('TC-ALMANAC-001: 黄历搜索功能', async ({
|
|
page,
|
|
assertionHelper,
|
|
testLogger,
|
|
screenshotHelper
|
|
}) => {
|
|
testLogger.startStep('步骤1: 等待页面加载完成');
|
|
|
|
await page.waitForLoadState('networkidle');
|
|
await assertionHelper.assertElementVisible(page, '.almanac-search-container', '黄历搜索容器应该显示');
|
|
|
|
testLogger.endStep('步骤1: 等待页面加载完成', 'passed');
|
|
|
|
testLogger.startStep('步骤2: 输入搜索关键词');
|
|
|
|
const searchInput = page.locator('.search-input, input[placeholder*="搜索"]');
|
|
await searchInput.fill('2024');
|
|
|
|
testLogger.endStep('步骤2: 输入搜索关键词', 'passed');
|
|
|
|
testLogger.startStep('步骤3: 执行搜索');
|
|
|
|
const searchButton = page.locator('.search-button, button:has-text("搜索")');
|
|
if (await searchButton.isVisible()) {
|
|
await searchButton.click();
|
|
} else {
|
|
await page.keyboard.press('Enter');
|
|
}
|
|
|
|
testLogger.endStep('步骤3: 执行搜索', 'passed');
|
|
|
|
testLogger.startStep('步骤4: 等待搜索结果加载');
|
|
|
|
await assertionHelper.assertLoading(page, '加载指示器应该显示');
|
|
await assertionHelper.assertNotLoading(page, '加载指示器应该消失');
|
|
|
|
testLogger.endStep('步骤4: 等待搜索结果加载', 'passed');
|
|
|
|
testLogger.startStep('步骤5: 验证搜索结果');
|
|
|
|
const searchResults = page.locator('.search-result-card, .almanac-item');
|
|
const resultCount = await searchResults.count();
|
|
|
|
expect(resultCount).toBeGreaterThan(0);
|
|
|
|
testLogger.endStep('步骤5: 验证搜索结果', 'passed');
|
|
|
|
await screenshotHelper.takeScreenshotOnSuccess('almanac-search');
|
|
});
|
|
|
|
test('TC-ALMANAC-002: 黄历详情查看', async ({
|
|
page,
|
|
assertionHelper,
|
|
testLogger,
|
|
screenshotHelper
|
|
}) => {
|
|
testLogger.startStep('步骤1: 等待黄历列表加载');
|
|
|
|
await page.waitForLoadState('networkidle');
|
|
await assertionHelper.assertElementVisible(page, '.almanac-list, .almanac-container', '黄历列表应该显示');
|
|
|
|
testLogger.endStep('步骤1: 等待黄历列表加载', 'passed');
|
|
|
|
testLogger.startStep('步骤2: 点击第一个黄历项');
|
|
|
|
const firstAlmanacItem = page.locator('.almanac-item, .search-result-card').first();
|
|
await firstAlmanacItem.click();
|
|
|
|
testLogger.endStep('步骤2: 点击第一个黄历项', 'passed');
|
|
|
|
testLogger.startStep('步骤3: 验证详情页显示');
|
|
|
|
await page.waitForURL(/.*\/detail/);
|
|
await assertionHelper.assertElementVisible(page, '.almanac-detail, .detail-container', '黄历详情应该显示');
|
|
|
|
testLogger.endStep('步骤3: 验证详情页显示', 'passed');
|
|
|
|
testLogger.startStep('步骤4: 验证详情信息完整性');
|
|
|
|
const detailElements = [
|
|
'.almanac-date',
|
|
'.almanac-gan-zhi',
|
|
'.almanac-yi',
|
|
'.almanac-ji',
|
|
'.almanac-chong'
|
|
];
|
|
|
|
for (const selector of detailElements) {
|
|
const element = page.locator(selector);
|
|
const isVisible = await element.isVisible().catch(() => false);
|
|
if (isVisible) {
|
|
const text = await element.textContent();
|
|
expect(text?.trim()).toBeTruthy();
|
|
}
|
|
}
|
|
|
|
testLogger.endStep('步骤4: 验证详情信息完整性', 'passed');
|
|
|
|
testLogger.startStep('步骤5: 返回列表页');
|
|
|
|
const backButton = page.locator('.back-button, button:has-text("返回")');
|
|
await backButton.click();
|
|
|
|
await assertionHelper.assertElementVisible(page, '.almanac-list, .almanac-container', '黄历列表应该重新显示');
|
|
|
|
testLogger.endStep('步骤5: 返回列表页', 'passed');
|
|
|
|
await screenshotHelper.takeScreenshotOnSuccess('almanac-detail');
|
|
});
|
|
|
|
test('TC-ALMANAC-003: 黄历收藏功能', async ({
|
|
page,
|
|
assertionHelper,
|
|
testLogger,
|
|
screenshotHelper
|
|
}) => {
|
|
testLogger.startStep('步骤1: 等待黄历列表加载');
|
|
|
|
await page.waitForLoadState('networkidle');
|
|
await assertionHelper.assertElementVisible(page, '.almanac-list, .almanac-container', '黄历列表应该显示');
|
|
|
|
testLogger.endStep('步骤1: 等待黄历列表加载', 'passed');
|
|
|
|
testLogger.startStep('步骤2: 点击收藏按钮');
|
|
|
|
const favoriteButton = page.locator('.favorite-button, .collect-button').first();
|
|
await favoriteButton.click();
|
|
|
|
testLogger.endStep('步骤2: 点击收藏按钮', 'passed');
|
|
|
|
testLogger.startStep('步骤3: 验证收藏成功提示');
|
|
|
|
await assertionHelper.assertToastVisible(page, '收藏成功提示应该显示');
|
|
|
|
testLogger.endStep('步骤3: 验证收藏成功提示', 'passed');
|
|
|
|
testLogger.startStep('步骤4: 验证收藏图标状态');
|
|
|
|
const isFavorited = await favoriteButton.getAttribute('class');
|
|
expect(isFavorited).toContain('active', '收藏按钮应该处于激活状态');
|
|
|
|
testLogger.endStep('步骤4: 验证收藏图标状态', 'passed');
|
|
|
|
testLogger.startStep('步骤5: 取消收藏');
|
|
|
|
await favoriteButton.click();
|
|
await assertionHelper.assertToastVisible(page, '取消收藏提示应该显示');
|
|
|
|
testLogger.endStep('步骤5: 取消收藏', 'passed');
|
|
|
|
await screenshotHelper.takeScreenshotOnSuccess('almanac-favorite');
|
|
});
|
|
|
|
test('TC-ALMANAC-004: 黄历分享功能', async ({
|
|
page,
|
|
assertionHelper,
|
|
testLogger,
|
|
screenshotHelper
|
|
}) => {
|
|
testLogger.startStep('步骤1: 进入黄历详情页');
|
|
|
|
await page.waitForLoadState('networkidle');
|
|
const firstAlmanacItem = page.locator('.almanac-item, .search-result-card').first();
|
|
await firstAlmanacItem.click();
|
|
|
|
testLogger.endStep('步骤1: 进入黄历详情页', 'passed');
|
|
|
|
testLogger.startStep('步骤2: 点击分享按钮');
|
|
|
|
const shareButton = page.locator('.share-button, button:has-text("分享")');
|
|
await shareButton.click();
|
|
|
|
testLogger.endStep('步骤2: 点击分享按钮', 'passed');
|
|
|
|
testLogger.startStep('步骤3: 验证分享弹窗显示');
|
|
|
|
await assertionHelper.assertModalVisible(page, '分享弹窗应该显示');
|
|
await assertionHelper.assertElementVisible(page, '.share-options, .share-menu', '分享选项应该显示');
|
|
|
|
testLogger.endStep('步骤3: 验证分享弹窗显示', 'passed');
|
|
|
|
testLogger.startStep('步骤4: 验证分享渠道');
|
|
|
|
const shareChannels = ['微信', '朋友圈', '微博', '复制链接'];
|
|
for (const channel of shareChannels) {
|
|
const channelButton = page.locator(`.share-option:has-text("${channel}")`);
|
|
const isVisible = await channelButton.isVisible().catch(() => false);
|
|
if (isVisible) {
|
|
expect(isVisible).toBe(true);
|
|
}
|
|
}
|
|
|
|
testLogger.endStep('步骤4: 验证分享渠道', 'passed');
|
|
|
|
testLogger.startStep('步骤5: 关闭分享弹窗');
|
|
|
|
const closeButton = page.locator('.modal-close, .close-button');
|
|
await closeButton.click();
|
|
|
|
await assertionHelper.assertModalHidden(page, '分享弹窗应该关闭');
|
|
|
|
testLogger.endStep('步骤5: 关闭分享弹窗', 'passed');
|
|
|
|
await screenshotHelper.takeScreenshotOnSuccess('almanac-share');
|
|
});
|
|
|
|
test('TC-ALMANAC-005: 黄历历史记录', async ({
|
|
page,
|
|
assertionHelper,
|
|
testLogger,
|
|
screenshotHelper
|
|
}) => {
|
|
testLogger.startStep('步骤1: 点击历史记录按钮');
|
|
|
|
const historyButton = page.locator('.history-button, button:has-text("历史")');
|
|
if (await historyButton.isVisible()) {
|
|
await historyButton.click();
|
|
}
|
|
|
|
testLogger.endStep('步骤1: 点击历史记录按钮', 'passed');
|
|
|
|
testLogger.startStep('步骤2: 验证历史记录列表显示');
|
|
|
|
const historyList = page.locator('.history-list, .history-container');
|
|
if (await historyList.isVisible()) {
|
|
await assertionHelper.assertElementVisible(page, '.history-list, .history-container', '历史记录列表应该显示');
|
|
|
|
const historyItems = page.locator('.history-item');
|
|
const itemCount = await historyItems.count();
|
|
|
|
expect(itemCount).toBeGreaterThan(0);
|
|
}
|
|
|
|
testLogger.endStep('步骤2: 验证历史记录列表显示', 'passed');
|
|
|
|
testLogger.startStep('步骤3: 清空历史记录');
|
|
|
|
const clearButton = page.locator('.clear-history, button:has-text("清空")');
|
|
if (await clearButton.isVisible()) {
|
|
await clearButton.click();
|
|
|
|
await assertionHelper.assertToastVisible(page, '清空成功提示应该显示');
|
|
}
|
|
|
|
testLogger.endStep('步骤3: 清空历史记录', 'passed');
|
|
|
|
await screenshotHelper.takeScreenshotOnSuccess('almanac-history');
|
|
});
|
|
});
|