fix: update E2E test selectors and improve login stability
- Fix selectors to use config keys instead of Chinese labels - Add page load waiting and element visibility checks - Improve global setup with better error handling - Update all config-linkage tests with correct selectors
This commit is contained in:
+6
-1
@@ -16,7 +16,12 @@ async function globalSetup(config: FullConfig) {
|
|||||||
console.log('📝 访问登录页面...');
|
console.log('📝 访问登录页面...');
|
||||||
await page.goto(`${env.baseURL}/admin/login`, { waitUntil: 'networkidle' });
|
await page.goto(`${env.baseURL}/admin/login`, { waitUntil: 'networkidle' });
|
||||||
|
|
||||||
|
console.log('⏳ 等待页面加载...');
|
||||||
|
await page.waitForLoadState('domcontentloaded', { timeout: 10000 });
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
console.log('🔑 填写登录信息...');
|
console.log('🔑 填写登录信息...');
|
||||||
|
await page.waitForSelector('#email', { timeout: 10000 });
|
||||||
await page.locator('#email').fill('admin@novalon.cn');
|
await page.locator('#email').fill('admin@novalon.cn');
|
||||||
await page.locator('#password').fill('admin123456');
|
await page.locator('#password').fill('admin123456');
|
||||||
|
|
||||||
@@ -32,7 +37,7 @@ async function globalSetup(config: FullConfig) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('❌ 登录超时,当前URL:', page.url());
|
console.log('❌ 登录超时,当前URL:', page.url());
|
||||||
console.log('📸 截图保存...');
|
console.log('📸 截图保存...');
|
||||||
await page.screenshot({ path: 'test-results/login-failure.png' });
|
await page.screenshot({ path: 'test-results/login-failure.png', fullPage: true });
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ test.describe('前后台配置参数测试', () => {
|
|||||||
await adminPage.goto('/admin/settings');
|
await adminPage.goto('/admin/settings');
|
||||||
await adminPage.waitForLoadState('networkidle');
|
await adminPage.waitForLoadState('networkidle');
|
||||||
|
|
||||||
const newsConfig = adminPage.locator('text=新闻模块配置').locator('..').locator('..');
|
const newsConfig = adminPage.locator('text=feature_news').locator('..').locator('..');
|
||||||
|
|
||||||
await newsConfig.locator('input[type="number"]').fill('2');
|
await newsConfig.locator('input[type="number"]').fill('2');
|
||||||
await newsConfig.locator('button:has-text("保存")').click();
|
await newsConfig.locator('button:has-text("保存")').click();
|
||||||
@@ -60,7 +60,7 @@ test.describe('前后台配置参数测试', () => {
|
|||||||
await adminPage.goto('/admin/settings');
|
await adminPage.goto('/admin/settings');
|
||||||
await adminPage.waitForLoadState('networkidle');
|
await adminPage.waitForLoadState('networkidle');
|
||||||
|
|
||||||
const newsConfig = adminPage.locator('text=新闻模块配置').locator('..').locator('..');
|
const newsConfig = adminPage.locator('text=feature_news').locator('..').locator('..');
|
||||||
|
|
||||||
const categoriesTextarea = newsConfig.locator('textarea');
|
const categoriesTextarea = newsConfig.locator('textarea');
|
||||||
await categoriesTextarea.fill('公司新闻\n产品发布');
|
await categoriesTextarea.fill('公司新闻\n产品发布');
|
||||||
@@ -99,7 +99,7 @@ test.describe('前后台配置参数测试', () => {
|
|||||||
await adminPage.goto('/admin/settings');
|
await adminPage.goto('/admin/settings');
|
||||||
await adminPage.waitForLoadState('networkidle');
|
await adminPage.waitForLoadState('networkidle');
|
||||||
|
|
||||||
const newsConfig = adminPage.locator('text=新闻模块配置').locator('..').locator('..');
|
const newsConfig = adminPage.locator('text=feature_news').locator('..').locator('..');
|
||||||
|
|
||||||
await newsConfig.locator('select').selectOption('desc');
|
await newsConfig.locator('select').selectOption('desc');
|
||||||
await newsConfig.locator('button:has-text("保存")').click();
|
await newsConfig.locator('button:has-text("保存")').click();
|
||||||
@@ -142,7 +142,7 @@ test.describe('前后台配置参数测试', () => {
|
|||||||
await adminPage.goto('/admin/settings');
|
await adminPage.goto('/admin/settings');
|
||||||
await adminPage.waitForLoadState('networkidle');
|
await adminPage.waitForLoadState('networkidle');
|
||||||
|
|
||||||
const productsConfig = adminPage.locator('text=产品模块配置').locator('..').locator('..');
|
const productsConfig = adminPage.locator('text=feature_products').locator('..').locator('..');
|
||||||
|
|
||||||
await productsConfig.locator('text=showPricing').locator('..').locator('input[type="checkbox"]').check();
|
await productsConfig.locator('text=showPricing').locator('..').locator('input[type="checkbox"]').check();
|
||||||
await productsConfig.locator('button:has-text("保存")').click();
|
await productsConfig.locator('button:has-text("保存")').click();
|
||||||
@@ -182,9 +182,9 @@ test.describe('前后台配置参数测试', () => {
|
|||||||
await adminPage.goto('/admin/settings');
|
await adminPage.goto('/admin/settings');
|
||||||
await adminPage.waitForLoadState('networkidle');
|
await adminPage.waitForLoadState('networkidle');
|
||||||
|
|
||||||
const productsConfig = adminPage.locator('text=产品模块配置').locator('..').locator('..');
|
const productsConfig = adminPage.locator('text=feature_products').locator('..').locator('..');
|
||||||
|
|
||||||
const featuredProductsTextarea = productsConfig.locator('text=featuredProducts').locator('..').locator('textarea');
|
const featuredProductsTextarea = productsConfig.locator('textarea');
|
||||||
await featuredProductsTextarea.fill('erp');
|
await featuredProductsTextarea.fill('erp');
|
||||||
await productsConfig.locator('button:has-text("保存")').click();
|
await productsConfig.locator('button:has-text("保存")').click();
|
||||||
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ test.describe('前后台配置联动测试', () => {
|
|||||||
await adminPage.goto('/admin/settings');
|
await adminPage.goto('/admin/settings');
|
||||||
await adminPage.waitForLoadState('networkidle');
|
await adminPage.waitForLoadState('networkidle');
|
||||||
|
|
||||||
const servicesConfig = adminPage.locator('text=服务模块配置').locator('..').locator('..');
|
const servicesConfig = adminPage.locator('text=feature_services').locator('..').locator('..');
|
||||||
await servicesConfig.locator('input[type="checkbox"]').first().check();
|
await servicesConfig.locator('input[type="checkbox"]').first().check();
|
||||||
await servicesConfig.locator('button:has-text("保存")').click();
|
await servicesConfig.locator('button:has-text("保存")').click();
|
||||||
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
||||||
@@ -53,7 +53,7 @@ test.describe('前后台配置联动测试', () => {
|
|||||||
await adminPage.goto('/admin/settings');
|
await adminPage.goto('/admin/settings');
|
||||||
await adminPage.waitForLoadState('networkidle');
|
await adminPage.waitForLoadState('networkidle');
|
||||||
|
|
||||||
const productsConfig = adminPage.locator('text=产品模块配置').locator('..').locator('..');
|
const productsConfig = adminPage.locator('text=feature_products').locator('..').locator('..');
|
||||||
await productsConfig.locator('input[type="checkbox"]').first().check();
|
await productsConfig.locator('input[type="checkbox"]').first().check();
|
||||||
await productsConfig.locator('button:has-text("保存")').click();
|
await productsConfig.locator('button:has-text("保存")').click();
|
||||||
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
||||||
@@ -89,7 +89,7 @@ test.describe('前后台配置联动测试', () => {
|
|||||||
await adminPage.goto('/admin/settings');
|
await adminPage.goto('/admin/settings');
|
||||||
await adminPage.waitForLoadState('networkidle');
|
await adminPage.waitForLoadState('networkidle');
|
||||||
|
|
||||||
const newsConfig = adminPage.locator('text=新闻模块配置').locator('..').locator('..');
|
const newsConfig = adminPage.locator('text=feature_news').locator('..').locator('..');
|
||||||
await newsConfig.locator('input[type="checkbox"]').first().check();
|
await newsConfig.locator('input[type="checkbox"]').first().check();
|
||||||
await newsConfig.locator('button:has-text("保存")').click();
|
await newsConfig.locator('button:has-text("保存")').click();
|
||||||
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
await adminPage.waitForSelector('text=保存成功', { timeout: 5000 });
|
||||||
|
|||||||
Reference in New Issue
Block a user