使用 const 在 puppeteer 测试中导入定位器
Importing locators in puppeteer tests using const
我有一个对象存储库文件,用于存储所有定位器。然而,为了提高可维护性和可读性,我现在使用 const 对定位器进行分组。例如:
const delivery = {
DELIVERY_HEADING: "xpath=//div[OOtext()='Delivery']",
DELIVERY_COUNT: '.bit-deliverylistrow'
};
const operations = {
SAVE_AUD: '.bit-save-btn',
SAVE_AUDNAME: "xpath=//*[text()='Audience name']/../input"
};
module.exports = { delivery, operations }
在测试中,我使用导入并将它们用作:
const or = require('../TestData/OR');
await page.focus(or.delivery.DELIVERY_HEADING);
await page.type(or.operations.SAVE_AUDNAME,'hello');
有没有一种方法我不必在测试中引用 const 并直接调用对象定位器,因为很难确定哪个 const 有哪个定位器?
我愿意await page.focus(or.DELIVERY_HEADING)
任何指点都会有所帮助。
您可以使用展开 ...
创建单个对象。
module.exports = { ...delivery, ...operations }
现在可以了,
await page.focus(or.DELIVERY_HEADING)
我有一个对象存储库文件,用于存储所有定位器。然而,为了提高可维护性和可读性,我现在使用 const 对定位器进行分组。例如:
const delivery = {
DELIVERY_HEADING: "xpath=//div[OOtext()='Delivery']",
DELIVERY_COUNT: '.bit-deliverylistrow'
};
const operations = {
SAVE_AUD: '.bit-save-btn',
SAVE_AUDNAME: "xpath=//*[text()='Audience name']/../input"
};
module.exports = { delivery, operations }
在测试中,我使用导入并将它们用作:
const or = require('../TestData/OR');
await page.focus(or.delivery.DELIVERY_HEADING);
await page.type(or.operations.SAVE_AUDNAME,'hello');
有没有一种方法我不必在测试中引用 const 并直接调用对象定位器,因为很难确定哪个 const 有哪个定位器?
我愿意await page.focus(or.DELIVERY_HEADING)
任何指点都会有所帮助。
您可以使用展开 ...
创建单个对象。
module.exports = { ...delivery, ...operations }
现在可以了,
await page.focus(or.DELIVERY_HEADING)