gpt4 book ai didi

javascript - Protractor :自定义 ExpectedConditions - 属性更改

转载 作者:行者123 更新时间:2023-11-29 17:41:28 28 4
gpt4 key购买 nike

我正在尝试实现自定义 ExpectedConditions 方法,它将等待元素属性发生变化。

这是我的解决方案:

const ECC = function() {
/**
* Expect element attribute to have specific value.
*
* @param {ElementFinder} elementFinder
* @param {string} attrName attribute name to check
* @param {string} attrVal attribute value to check for
*
* @return {boolean}
*/
this.attributeToHave = async (elementFinder, attrName, attrVal) => {
const EC = protractor.ExpectedConditions;
const hasAttr = async () => {
const actualText = elementFinder.getAttribute(attrName);
return actualText.indexOf(attrVal) !== -1;
};

return await EC.and(EC.presenceOf(elementFinder), await hasAttr);
};
};

module.exports = new ECC();

在我的 onPrepare 中:

const {expectedConditions} = require('@utils/protractor');
global.ECC = expectedConditions;

最后在我的测试套件中:

 await browser.wait(await ECC.attributeToHave(dropdown, 'aria-hidden', 'false'), 3000);

但它一直说失败:WAITING 3006 毫秒后超时,请问我做错了什么?

最佳答案

请进行以下更改后重试:

this.attributeToHave = async (elementFinder, attrName, attrVal) => {
const EC = protractor.ExpectedConditions;
const hasAttr = async () => {
const actualText = await elementFinder.getAttribute(attrName); // should add await
return actualText.indexOf(attrVal) !== -1;
};

return await EC.and(EC.presenceOf(elementFinder), await hasAttr()); // should call `hasAttr()` this function.
};

关于javascript - Protractor :自定义 ExpectedConditions - 属性更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52792877/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com