webrat'中缺少POST变量;按下按钮
我在尝试使用cucumber测试我的php web应用程序时遇到了麻烦。基本上,button_press方法在提交表单时无法提交buttonName_x和buttonName_y POST变量 我希望有人能在这方面帮助我-提前谢谢强> 编辑:我能够为webrat编写一个脏补丁,以便能够临时解决问题。不过,我还是很高兴听到更好的解决方案 这是所讨论的html:webrat'中缺少POST变量;按下按钮,post,cucumber,mechanize,webrat,Post,Cucumber,Mechanize,Webrat,我在尝试使用cucumber测试我的php web应用程序时遇到了麻烦。基本上,button_press方法在提交表单时无法提交buttonName_x和buttonName_y POST变量 我希望有人能在这方面帮助我-提前谢谢 编辑:我能够为webrat编写一个脏补丁,以便能够临时解决问题。不过,我还是很高兴听到更好的解决方案 这是所讨论的html: <form id="newsForm" action="/index.php?page=adminpan
<form id="newsForm" action="/index.php?page=adminpanel&view=newscontrol" method="post">
<table cellpadding="0" cellspacing="0" class="tableList">
<thead id="editor">
<tr>
<th colspan="3">News Editor</th>
</tr>
</thead>
<tbody>
<tr class="rowA">
<td colspan="3">Titel: <input type="text" name="subject" value="'.utf8htmlentities($subject).'" size="121" /></td>
</tr>
<tr class="rowB">
<td colspan="3">
<textarea id="content" name="content" rows="10" cols="10">'.utf8htmlentities($content).'</textarea>
</td>
</tr>
<tr class="submitRow">
<td colspan="3"><input type="image" src="res/images/design/button_preview.gif" name="previewNews" alt="preview" /> <input type="image" src="res/images/design/button_sendx.gif" name="submitNews" alt="submit" /></td>
</tr>
</tbody>
</table>
</form>
变量转储($\u POST)导致:
array(2) { ["content"]=> string(22) "Magnificient News Post" ["subject"]=> string(18) "This is a subject!" }
而通过firefox的请求会导致:
array(4) { ["content"]=> string(22) "Magnificient News Post" ["subject"]=> string(18) "This is a subject!" ["submitNews_x"]=> string(1) "0" ["submitNews_y"]=> string(1) "0" }
我的步骤定义如下所示:
When /^I insert "(.*?)" for (.*?)\.(.*?)$/ do |input, form, item|
within 'form[id="' + form + '"]' do |scope|
scope.fill_in(item, :with => input)
end
end
When /^I press (.*?)\.(.*?)$/ do |form, item|
within 'form[id="' + form + '"]' do |scope|
scope.click_button(item)
end
end
最后,我的env.rb:
# RSpec
require 'rspec/expectations'
# Webrat
require 'webrat'
require 'test/unit/assertions'
World(Test::Unit::Assertions)
Webrat.configure do |config|
config.mode = :mechanize
end
class MechanizeWorld < Webrat::MechanizeAdapter
include Webrat::Matchers
include Webrat::Methods
Webrat::Methods.delegate_to_session :response_code, :response_body, :response, :redirected_to
end
World do
MechanizeWorld.new
session = Webrat::Session.new
session.extend(Webrat::Methods)
session.extend(Webrat::Matchers)
session
end
#RSpec
要求“rspec/预期”
#韦伯拉特
需要“网络鼠”
需要“测试/单元/断言”
世界(测试::单元::断言)
Webrat.configure do | config|
config.mode=:机械化
结束
类MechanizeWorld
这似乎是一段时间以来的问题
有几个补丁链接到该线程,您可以在本地应用到webrat gem,尽管这可能是您已经做过的,因为您提到您使用了一个“脏补丁”
最好就这一主题发表评论,特别是回答布赖恩的问题:
<form id="newsForm" action="/index.php?page=adminpanel&view=newscontrol" method="post">
<table cellpadding="0" cellspacing="0" class="tableList">
<thead id="editor">
<tr>
<th colspan="3">News Editor</th>
</tr>
</thead>
<tbody>
<tr class="rowA">
<td colspan="3">Titel: <input type="text" name="subject" value="'.utf8htmlentities($subject).'" size="121" /></td>
</tr>
<tr class="rowB">
<td colspan="3">
<textarea id="content" name="content" rows="10" cols="10">'.utf8htmlentities($content).'</textarea>
</td>
</tr>
<tr class="submitRow">
<td colspan="3"><input type="image" src="res/images/design/button_preview.gif" name="previewNews" alt="preview" /> <input type="image" src="res/images/design/button_sendx.gif" name="submitNews" alt="submit" /></td>
</tr>
</tbody>
</table>
</form>
传递0,0或1,1的X/Y就足够了吗,或者有人在做任何依赖于精确值的事情吗
你可能会看到它得到了正确的解决