加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

twitter-bootstrap – Angular e2e Testacular Test:如何辨别可

发布时间:2020-12-17 20:39:08 所属栏目:安全 来源:网络整理
导读:题 如果在单击按钮时显示Bootstrap模式,是否有人成功测试过? 细节 我正在编写一个Testacular测试,用于检查单击按钮时是否显示Bootstrap模式.问题是对css(‘display’)的调用返回’none’,即使我可以看到窗口弹出并且可见. 我想知道是否有一些怪异的Bootstra

如果在单击按钮时显示Bootstrap模式,是否有人成功测试过?

细节

我正在编写一个Testacular测试,用于检查单击按钮时是否显示Bootstrap模式.问题是对css(‘display’)的调用返回’none’,即使我可以看到窗口弹出并且可见.

我想知道是否有一些怪异的Bootstrap Modal会复制一个html块然后用不同的id显示.我当然希望不是!

场景

describe('e2e',function() {

  beforeEach(function() {
    browser().navigateTo('/chessClub/');
  });


  it('should display editor when add member button clicked',function() {
    expect(element('title').text()).toBe("Chess Club");

      expect(element('#myModal').css('display')).toBe('none'); //as expected,it is none
              //click the button to show the modal
      element('#addMemberButton','Add Member Button').click();

              //this 2nd expect still return 'none'
      expect(element('#myModal').css('display')).toBe('block');

  });

});

测试输出

Chrome 25.0 e2e should display editor when add member button clicked FAILED
    expect element '#myModal' get css 'display' toBe "block"
    /Users/jgordon/learning/chessClub/web-app/test/e2e/scenarios.js:17:4: expected "block" but was "none"

HTML

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">{{editorLabel}}</h3>
    </div>
    <div class="modal-body">
        <form>
            <label>
                Name
            </label>
                <input type="text" ng-model="editedMember.name" placeholder="John Doe">
            <label>
                Grade
            </label>
                <input type="text" ng-model="editedMember.grade">
            <label>
                Ladder Position
            </label>
                <input type="text" ng-model="editedMember.ladderPosition">
        </form>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-primary" ng-click="saveMember()">Save changes</button>
    </div>
</div>

解决方法

一种方法,虽然有点hacky是使用:visible选择器并计算有多少匹配

expect(element('#someElement:visible').count()).toBe(1);

Source

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读