我尝试用黄瓜测试我的php web应用程序时遇到了麻烦。基本上,在提交表单时,button_press方法无法提交buttonName_x和buttonName_y POST变量。
我希望有人能够帮助我 - 提前感谢!
编辑:我能够为webrat编写一个脏补丁,以便能够暂时解决问题。但是,我仍然很高兴听到更好的解决方案。
这是有问题的HTML:
<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>
提取失败的特征:
Scenario: post news
[...]
When I insert "This is a subject!" for newsForm.subject
And I insert "Magnificient News Post" for newsForm.content
And I press newsForm.submit
[...]
var_dump($ _ 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
答案 0 :(得分:1)
看起来好像这已经是outstanding request了一段时间。
有一些补丁从该线程链接到你可以在本地应用于webrat gem,虽然这可能是你已经完成的,因为你提到你已经使用了'脏补丁'!
最好对该主题发表评论,特别是回应布莱恩的问题:
是否足以传递0,0或1,1的X / Y,或者是否有人做任何取决于确切值的事情?
你可能会看到它得到妥善解决。