0
我試圖用黃瓜測試我的php web應用程序時遇到了麻煩。基本上,在提交表單時,button_press方法未能提交buttonName_x和buttonName_y POST變量。缺少來自webrat的button_press的POST變量
我希望有人能夠幫助我 - 在此先感謝!
編輯:我能寫一個骯髒的修補程序的網頁能夠暫時解決問題。不過,我仍然很高興聽到更好的解決方案。
這是有問題的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
謝謝,我會那樣做的。 –