Angular e2e Testacular Test:如何辨别可见性?

Joh*_*don 4 modal-dialog twitter-bootstrap angularjs karma-runner

如果在单击按钮时显示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');

  });

});
Run Code Online (Sandbox Code Playgroud)

测试输出

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"
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

alt*_*ler 7

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

expect(element('#someElement:visible').count()).toBe(1);
Run Code Online (Sandbox Code Playgroud)

资源