Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用const在木偶演员测试中导入定位器_Javascript_Puppeteer - Fatal编程技术网

Javascript 使用const在木偶演员测试中导入定位器

Javascript 使用const在木偶演员测试中导入定位器,javascript,puppeteer,Javascript,Puppeteer,我有一个存储所有定位器的对象存储库文件。然而,为了提高可维护性和可读性,我现在使用const对定位器进行分组。例如: const delivery = { DELIVERY_HEADING: "xpath=//div[OOtext()='Delivery']", DELIVERY_COUNT: '.bit-deliverylistrow' }; const operations = { SAVE_AUD: '.bit-save-btn', SAVE_AUDNAME

我有一个存储所有定位器的对象存储库文件。然而,为了提高可维护性和可读性,我现在使用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');
有没有一种方法我不必在测试中引用常量并直接调用对象定位器,因为很难识别哪个常量有哪个定位器

我想做
wait page.focus(或.DELIVERY\u HEADING)


任何指针都会有帮助。

您可以使用排列
创建单个对象

module.exports = { ...delivery, ...operations }
现在你可以做了

await page.focus(or.DELIVERY_HEADING)