2011-12-06 83 views
0

我試圖用黃瓜測試我的php web應用程序時遇到了麻煩。基本上,在提交表單時,button_press方法未能提交buttonName_x和buttonName_y POST變量。缺少來自webrat的button_press的POST變量

我希望有人能夠幫助我 - 在此先感謝!

編輯:我能寫一個骯髒的修補程序的網頁能夠暫時解決問題。不過,我仍然很高興聽到更好的解決方案。

這是有問題的HTML:

   <form id="newsForm" action="/index.php?page=adminpanel&amp;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:&nbsp;<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 

回答

1

看起來好像這已經有一段時間了outstanding request

從該線程鏈接了一些可以在本地適用於網頁版寶石的修補程序,雖然這可能是您在提到您已經使用「髒修補程序」時已經完成的工作!

它可能是最好的上線發表評論,特別是應對Bryan的問題:

是否足以在X通/ 0,0或1,1 Y,或者是任何人做什麼取決於確切的價值?

而且您可能會看到它得到正確解決。

+0

謝謝,我會那樣做的。 –