关于Rails上的ruby 3:让水豚/Cucumber 和Poltergeist与Twitter Bootstrap模态对话框一起使用

Getting capybara/cucumber and poltergeist to work with twitter bootstrap modal dialog box

上下文:
我正在与Cucumber / Capybara / PhantomJS / Poltergeist测试Rails应用。我的一个Cucumber 步骤定义文件中有一个click_link调用。然后,此click_link调用导致Rails调用控制器的show方法。控制器通过特定的ID查找对象,并以javascript格式(format.js)进行响应。然后,由show.js.erb文件给出的响应将在Twitter Bootstrap模态对话框上执行一些文本字符串替换,以在框中显示自定义状态消息。然后将显示模式对话框。

这一切都可以在生产中使用。但这似乎在测试中不起作用。我收到一条错误消息"找不到具有值或ID或文本\\'Close \\'的按钮(Capybara :: ElementNotFound)"。另外,puts page.html只会显示以下内容:

1
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">

这使我认为模式对话框完全没有显示。任何人对发生的事情有任何想法吗?

cucumber_steps.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
When /^I click this link$/ do

  click_link"Some link to call show method"

  puts page.html

end

And /^I click close button in the modal box$/ do

   click_button 'Close'

end

Twitter引导程序的模式框页面中的HTML:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<ul>

 
<li>
Some link to call show method
</li>


</ul>

 :
 :
    <form>



 

    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

    <h3 id="myModalLabel">Modal header

 

 

    <p>One fine body…</p>

 

 

    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>

    <button class="btn btn-primary">Save changes</button>

 



</form>

Rails显示方法

1
2
3
4
5
6
7
8
9
10
11
def show

    @kite = Kite.find(params[:id])

    respond_to do |format|

      format.js

    end

  end

关闭按钮错误

由于使用click_button"Close"且单击按钮的ID或文本未使用"关闭",因此出现错误:
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

要解决错误,您要回来,我将执行以下操作:

1
2
close_button = page.find('button.close')
click_button close_button

一般问题

您已经遗漏了很多有关执行情况的细节,因此很难确定您出了错的地方。我要检查的第一件事是确保您在env.rb文件

中设置了poltergeist