2012-10-21 24 views
1

在Web应用程序中,我使用jQueryUI的模式对话框来确认操作:如何模拟与水豚的jQuery-UI模式对话框按钮的点击?

function erase() { 
    $("#dialog").text("Are you sure want to delete this record?") 
    .attr("title", "Delete...") 
    .dialog({ 
    modal: true, 
    buttons: { 
     Delete: function() { 
     $.ajax({ 
      ...snip... 
      success: function() { 
      self.location = "."; // returns to the welcome page 
      } 
     }); 
     }, 
     ...snip... 
    } 
    }); 
} 

代码工作得很好,但我不能与水豚测试它成功:

...snip... 
Capybara.default_driver = :webkit 
...snip... 

def in_dialog() 
    f = find('.ui-dialog') 
end 

feature 'Delete a record' do 
...snip... 
    scenario 'for any record' do 
    click_on 'Delete...' 
    page.should have_content 'Are you sure want to delete this record?' 
    in_dialog.click_button 'Delete' 
    page.should have_content 'Welcome' 
    ...snip... 
    end 
end 

水豚发现按钮,但一切都好像回调从未被解雇。

我尝试了不同的解决方法(其中有几个我计算器上找到):

  • 睡眠,
  • “等AJAX”
  • page.native.send_keys(:收益),而不是click_button 'Delete',
  • find('button',:text =>'Delete')。click代替click_button'Delete',
  • Selenium驱动代替webkit驱动。

无效。任何其他想法?

+0

你可以发表一个复制案例(如果它对于SO来说很大,那么对于例如gist.github.com)? –

+1

以下是与我的测试服务器交互的水豚场景的要点:https://gist.github.com/4547091 –

+0

请准备包括相关HTML/JS文件的复制案例。如果我不知道如何重现问题,你如何指望我们告诉如何解决问题? –

回答

1

您发布了code that you use to interact with the server的评论。

我在浏览器中手动执行了这些步骤,但点击按钮“Supprimer”返回409错误,没有其他事情发生。这就是为什么当你点击这个按钮时你的测试没有任何反应。

+0

我必须承认,水豚的情况与我手动测试的不完全一样,前者因为未报告的错误而失败。看起来我对应用程序过于自信,而且在Capybara-jQueryUI集成方面还不够。现在该错误已修复,该方案运行良好。谢谢您的帮助。 –

1

嗯,睡觉至少应该有工作,但这里是我用什么来确保我的AJAX调用返回:

in_dialog.click_button 'Delete' 
wait_until { page.evaluate_script("jQuery.active") == 0 } 
page.should have_content 'Welcome' 
+0

感谢您的建议。这似乎与我之前尝试的类似,但我会再试一次。 –

+0

嗯,它没有工作:( 有没有人在jQueryUI水豚有任何成功? –

+2

'wait_until'已被弃用,它被从水豚2.0中删除,你不应该使用它 – luacassus

0

你总是可以执行水豚的场景中自定义JavaScript代码。你试过类似的东西:

# when 
page.execute_script("$('.the-button-selector').click();") 
# then 
page.should_not have_css(".the-dialog-selector")