[英]Angular2 E2E Protractor. Wait until element has class
I need find a way to wait with my e2e test (angular2 project) until the tested element gets an specific css class .我需要找到一种方法来等待我的 e2e 测试(angular2 项目),直到被测元素获得特定的 css 类。
Is there any possible way without browser.wait()
or browser.sleep()
?没有browser.wait()
或browser.sleep()
有什么可能的方法吗?
You've even used the word "wait" in the question, but asking to solve it without the built-in waiting functions.您甚至在问题中使用了“等待”一词,但要求在没有内置等待功能的情况下解决它。 I don't see much sense in that.我认为这没有多大意义。
We've solved something similar before and came up with a custom wait function which can be used as an Expected Condition with browser.wait()
:我们之前已经解决了类似的问题,并提出了一个自定义等待函数,它可以用作browser.wait()
的预期条件:
function waitForCssClass(elementFinder, desiredClass) {
return function () {
return elementFinder.getAttribute('class').then(function (classValue) {
return classValue && classValue.indexOf(desiredClass) >= 0;
});
};
};
browser.wait(waitForCssClass($("#myid"), "desiredClass"), 5000);
This function waits for a class to disappears from an element, given the element object (ElementFinder) and the CSS class you want to check for.给定元素对象 (ElementFinder) 和要检查的 CSS 类,此函数等待类从元素中消失。
static async waitCssClassToDisappear(elem:ElementFinder, cssClass:string, timeout?: number) { await browser.wait(()=>{ return elem.getAttribute('class').then((value) =>{ return value.indexOf(cssClass) < 0; }); }, timeout ? timeout : Utils.defaultTimeout, 'CSS class did not disappear within specified timeout'); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.