Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created November 1, 2012 14:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/3994117 to your computer and use it in GitHub Desktop.
Save JoshCheek/3994117 to your computer and use it in GitHub Desktop.
Setting a hidden field with Capybara
require 'sinatra/base'
class ExampleApp < Sinatra::Base
get '/get_form' do
'<html>
<body>
<form action="/post_form" method="post" accept-charset="utf-8">
<input type="hidden" name="hidden_face" value=":(" id="hidden_face">
<p><input type="submit" value="Submit!"></p>
</form>
</body>
</html>'
end
post '/post_form' do
puts "RECEIVED: #{params.inspect}"
end
end
require 'capybara'
require 'capybara/dsl'
Capybara.app = ExampleApp
Capybara.use_default_driver
extend Capybara::DSL
puts "Submitting form without changing, expect value to be a sad face"
visit '/get_form'
click_button "Submit!"
puts
puts "Submitting form after changing the hidden field, expect value to be a happy face"
visit '/get_form'
hidden_field = find :xpath, "//input[@id='hidden_face']"
hidden_field.set ":)"
click_button "Submit!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment