AngularJS&安培;量角器 - 执行。点击(),而一个元素.isDisplayed() [英] AngularJS & Protractor - Perform .click() while an element .isDisplayed()

查看:149
本文介绍了AngularJS&安培;量角器 - 执行。点击(),而一个元素.isDisplayed()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的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
});

这篇关于AngularJS&安培;量角器 - 执行。点击(),而一个元素.isDisplayed()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆