AngularJS&安培;量角器 - 执行。点击(),而一个元素.isDisplayed()安培、量角器、元素、AngularJS

2023-09-13 05:20:59 作者:凉叁

我想在我的AngularJS应用测试显示更多按钮,这样,当用户点击该按钮会加载一些内容和那里是没有更多的显示按钮隐藏。

I want to test "Show more" button in my AngularJS app, so when user hits the button it will load some content and where there is nothing more to show the button hides.

我怎么能执行。点击(),而显示更多显示。我不想硬code回路数,但不知何故插入 .isDisplayed()(即使它返回一个承诺)为而()

How can I perform .click() while "Show more" is displayed. I don't want to hardcode the number of loops but somehow insert .isDisplayed() (even if it returns a promise) into while()

推荐答案

我要找到所有显示更多按钮和过滤器仅可见的使用< A HREF =htt​​p://angular.github.io/protractor/#/api?view=ElementArrayFinder.prototype.filter相对=nofollow> 过滤器() 。执行:

I would find all Show More buttons and filter visible only using filter(). Implementation:

// find all "Show More" links by link text and filter only visible
var showMores = element.all(by.linkText("Show More")).filter(function (link) {
    return link.isDisplayed().then(function (value) {
        return value;
    });
});

// for each visible "Show More", click it
showMores.each(function (link) {
    link.click();

    // TODO: assertions/expectations
});