【问题标题】:Testing modal dialogs with zombie.js使用zombie.js 测试模态对话框
【发布时间】:2012-09-14 02:37:05
【问题描述】:

我在模态对话框中有一些输入字段,就像这样(那是玉):

      .modal-body
            .control-group
                label.required(for="event-planner-email")= Email
                .input
                    input#event-planner-email(name="email", type='text')

            .control-group
                label.required(for="event-planner-name")= Name
                .input
                    input#event-planner-name(name="name", type='text')

我希望能够在测试中填写它们。我尝试按下打开模式的链接并使用zombie.js浏览器对象填充字段,coffee中的代码如下:

          browser.clickLink 'a#open-planner', () ->
                browser
                    .fill('event-planner-email', someEmail)
                    .fill('event-planner-name', someName)
                    .pressButton 'Create', () ->
                         do done

但我收到一条错误消息:“没有与 'event-planner-email' 匹配的 INPUT”。如果有人知道如何做到这一点,将不胜感激。谢谢!

【问题讨论】:

    标签: coffeescript pug zombie.js


    【解决方案1】:

    当您的回电触发时,模式可能还没有出现。如果发生显示模态的转换,则必须等待该转换完成。

    也许尝试在clickLink 的回调中添加setTimeout

    browser.clickLink 'a#open-planner', ->
        fillForm = ->
            browser
                .fill('event-planner-email', someEmail)
                .fill('event-planner-name', someName)
                .pressButton 'Create', ->
                     do done
    
        setTimeout fillForm, 1000
    

    【讨论】:

      【解决方案2】:

      来自Bootstrap docs

      你需要在模态加载后运行你的僵尸代码,所以你应该使用“显示”事件

      $('#myModal').on('shown', function () {
        // zombie
      })
      

      我不知道如何在咖啡中表达这一点

      【讨论】:

        【解决方案3】:

        谢谢大家,原来我只是没有为输入元素使用正确的 css 选择器,所以而不是

                        .fill('event-planner-email', someEmail)
        

        应该是

                        .fill('input#event-planner-email', someEmail)
        

        因为在上面的jade sn-p中,'event-planner-email'是输入元素的id。想删除我的问题,以免我进一步暴露我的愚蠢,但显然为时已晚。

        【讨论】:

          猜你喜欢
          • 2013-08-12
          • 2010-10-26
          • 1970-01-01
          • 2011-09-27
          • 2015-07-09
          • 2018-01-20
          • 1970-01-01
          • 2010-11-20
          • 1970-01-01
          相关资源
          最近更新 更多