0

I have been running into trouble while trying to test my php web application with cucumber. Basically, the button_press method fails to submit the buttonName_x and buttonName_y POST variables when submitting the form.

I hope someone is able to help me with this - thanks in advance!

EDIT: I was able to write a dirty patch for webrat to be able to temporarily resolve the issue. However, I'd still be glad to hear of a better solution.

This is the html in question:

                <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>

an extraction of the failing Feature:

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
    [...]

a var_dump($_POST) resulted in:

array(2) { ["content"]=> string(22) "Magnificient News Post" ["subject"]=> string(18) "This is a subject!" } 

whereas a request via firefox results in:

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" } 

my step definitions look as follows:

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

and finally, my 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
Andreas Grapentin
  • 5,499
  • 4
  • 39
  • 57

1 Answers1

1

It looks as though this has been an outstanding request for some time.

There are a few patches linked from that thread which you could apply to the webrat gem locally, although this is probably what you've done already as you mention you've used a 'dirty patch'!

It would probably be best to comment on that thread, in particular responding to Bryan's question:

Is it sufficient to pass in an X/Y of 0,0 or 1,1, or is anyone doing anything that depends on the exact values?

And you may see it get resolved properly.

Jon M
  • 11,669
  • 3
  • 41
  • 47