views:

217

answers:

1

Hello,

Scenario: I have logged into a website, gained cookies etc, got to a particular webpage with a form + hidden fields. I now want to be able to create my own http post with my own hidden form data instead of what is on the webpage and verify the response instead of using the one on the webpage.

Reason: Testing against pre-existing data (I know, I know) which could be different on each environment hence no predictable way to use it. We need a workaround.

Is there any way to do this without manually editing the existing form and submitting that? Feels a little 'hacky'.

Ideally, I would like to say something like:

browser.post 'url', 'field1=test&field2=abc'

Thanks

Ben

+2  A: 

I would probably switch to mechanize to muck around at the protocol level. Something like this added to your script

b = WWW::Mechanize.new
 b.get('http://yoursite.com/current_page') do |page|
 # Submit the login form
 my_form = page.form_with(:action => '/post/url') do |f|
   f.form_loginname  = 'tim'
   f.form_pw         = 'password'
 end.click_button
end
Tim
neat idea, so in affect you are creating a new form on the page? Or are you editing an existing form and changing the action?
Ben Hall
The latter, editing the existing form on the page but driving it thru Mechanize (and therefore controlling post form data)
Tim