优化文件路径
This commit is contained in:
parent
25c56b2e14
commit
431551a9ae
@ -10,7 +10,23 @@ class BasePage {
|
||||
*/
|
||||
constructor(page) {
|
||||
this.page = page;
|
||||
this.timeout = 30000; // 默认使用配置中的元素超时时间
|
||||
this.initializeConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化配置
|
||||
* @protected
|
||||
*/
|
||||
initializeConfig() {
|
||||
this.config = {
|
||||
timeout: 30000, // 默认超时时间
|
||||
pageLoad: {
|
||||
maxRetries: 30,
|
||||
retryInterval: 500,
|
||||
stabilityDelay: 1000
|
||||
},
|
||||
menuTimeout: parseInt(process.env.MENU_TIME_OUT || '30000', 10)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +56,7 @@ class BasePage {
|
||||
|
||||
await element.waitFor({
|
||||
state: 'visible',
|
||||
timeout: options.timeout || this.timeout
|
||||
timeout: options.timeout || this.config.timeout
|
||||
});
|
||||
|
||||
return options.returnBoolean ? true : element;
|
||||
@ -177,6 +193,39 @@ class BasePage {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待指定时间
|
||||
* @param {number} ms 等待时间(毫秒)
|
||||
*/
|
||||
async wait(ms) {
|
||||
await this.page.waitForTimeout(ms);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查元素是否存在
|
||||
* @param {string} selector 元素选择器
|
||||
* @returns {Promise<boolean>} 是否存在
|
||||
*/
|
||||
async elementExists(selector) {
|
||||
const count = await this.page.locator(selector).count();
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取元素文本
|
||||
* @param {Object} element Playwright元素对象
|
||||
* @returns {Promise<string>} 元素文本
|
||||
*/
|
||||
async getElementText(element) {
|
||||
try {
|
||||
const text = await element.textContent();
|
||||
return text.trim();
|
||||
} catch (error) {
|
||||
console.error('获取元素文本失败:', error.message);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BasePage;
|
||||
@ -46,51 +46,13 @@ class LongiMainPage extends BasePage {
|
||||
* @private
|
||||
*/
|
||||
initializeConfig() {
|
||||
this.config = {
|
||||
timeout: 10000,
|
||||
pageLoad: {
|
||||
maxRetries: 30,
|
||||
retryInterval: 500,
|
||||
stabilityDelay: 1000
|
||||
},
|
||||
// 调用父类的配置初始化
|
||||
super.initializeConfig();
|
||||
|
||||
// 添加或覆盖特定于 LongiMainPage 的配置
|
||||
Object.assign(this.config, {
|
||||
menuTimeout: parseInt(process.env.MENU_TIME_OUT || '30000', 10)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待指定时间
|
||||
* @param {number} ms 等待时间(毫秒)
|
||||
* @private
|
||||
*/
|
||||
async wait(ms) {
|
||||
await this.page.waitForTimeout(ms);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查元素是否存在
|
||||
* @param {string} selector 元素选择器
|
||||
* @returns {Promise<boolean>} 是否存在
|
||||
* @private
|
||||
*/
|
||||
async elementExists(selector) {
|
||||
const count = await this.page.locator(selector).count();
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取元素文本
|
||||
* @param {Object} element Playwright元素对象
|
||||
* @returns {Promise<string>} 元素文本
|
||||
* @private
|
||||
*/
|
||||
async getElementText(element) {
|
||||
try {
|
||||
const text = await element.textContent();
|
||||
return text.trim();
|
||||
} catch (error) {
|
||||
console.error('获取元素文本失败:', error.message);
|
||||
return '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user