Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submitting forms doesn't work #74

Open
clofresh opened this issue Jun 24, 2011 · 3 comments
Open

Submitting forms doesn't work #74

clofresh opened this issue Jun 24, 2011 · 3 comments

Comments

@clofresh
Copy link

When I fill out a form and submit, it doesn't pass along the form values, it only submits an empty form.

Test server:

require 'rubygems'
require 'sinatra'

get '/' do
  <<-EOF
    <html>
    <head><title>Testing submitting forms</title></head>
    <body>
      Log In
      <form method="post" action="/" id="myform">
        <label for="username"><input id="username" name="username">
        <label for="password"><input id="password" name="password" type="password">
        <input type="submit" value="Log In">
      </form>
    </body>
    </html>
  EOF
end

post '/' do
  <<-EOF
    <html>
    <head><title>Testing cucumber</title></head>
    <body>
      Values: #{params[:username]}, #{params[:password]}
    </body>
    </html>
  EOF
end

Feature:

Feature: Submitting form
  cucumber-nagios should be able to submit forms

  Scenario: Visiting home page
    When I go to "http://localhost:4567/"
    And I fill in "username" with "my user"
    And I fill in "password" with "my password"
    And I press "Log In"
    Then the request should succeed
    And I should see "Values: my user, my password"

Output:

Feature: Submitting form
  cucumber-nagios should be able to submit forms

  Scenario: Visiting home page                      # features/testing/submitting_forms.feature:4
    When I go to "http://localhost:4567/"           # features/steps/http_steps.rb:11
    And I fill in "username" with "my user"         # features/steps/http_steps.rb:23
    And I fill in "password" with "my password"     # features/steps/http_steps.rb:23
    And I press "Log In"                            # features/steps/http_steps.rb:15
    Then the request should succeed                 # features/steps/http_steps.rb:64
    And I should see "Values: my user, my password" # features/steps/http_steps.rb:52
      expected: /Values: my user, my password/m
           got: "    <html>\n    <head><title>Testing cucumber</title></head>\n    <body>\n      Values: , \n    </body>\n    </html>\n" (using =~)
      Diff:
      @@ -1,2 +1,7 @@
      -/Values: my user, my password/m
      +    <html>
      +    <head><title>Testing cucumber</title></head>
      +    <body>
      +      Values: , 
      +    </body>
      +    </html>
       (RSpec::Expectations::ExpectationNotMetError)
      ./features/steps/http_steps.rb:53:in `/^I should see "(.*)"$/'
      features/testing/submitting_forms.feature:10:in `And I should see "Values: my user, my password"'

Failing Scenarios:
cucumber features/testing/submitting_forms.feature:4 # Scenario: Visiting home page

1 scenario (1 failed)
6 steps (1 failed, 5 passed)
0m0.030s

This is my Gemfile.lock:

GEM
  remote: http://rubygems.org/
  specs:
    amqp (0.6.7)
      eventmachine (>= 0.12.4)
    builder (3.0.0)
    cucumber (0.10.6)
      builder (>= 2.1.2)
      diff-lcs (>= 1.1.2)
      gherkin (~> 2.4.0)
      json (>= 1.4.6)
      term-ansicolor (>= 1.0.5)
    cucumber-nagios (0.9.2)
      amqp (= 0.6.7)
      bundler (~> 1.0.7)
      cucumber (>= 0.10.0)
      mechanize (= 1.0.0)
      net-ssh (~> 2.1.0)
      rspec (>= 2.3.0)
      templater (>= 1.0.0)
      webrat (= 0.7.2)
    diff-lcs (1.1.2)
    eventmachine (0.12.10)
    extlib (0.9.15)
    gherkin (2.4.0)
      json (>= 1.4.6)
    highline (1.6.2)
    json (1.5.2)
    mechanize (1.0.0)
      nokogiri (>= 1.2.1)
    net-ssh (2.1.4)
    nokogiri (1.4.4)
    rack (1.3.0)
    rack-test (0.6.0)
      rack (>= 1.0)
    rspec (2.6.0)
      rspec-core (~> 2.6.0)
      rspec-expectations (~> 2.6.0)
      rspec-mocks (~> 2.6.0)
    rspec-core (2.6.4)
    rspec-expectations (2.6.0)
      diff-lcs (~> 1.1.2)
    rspec-mocks (2.6.0)
    templater (1.0.0)
      diff-lcs (>= 1.1.2)
      extlib (>= 0.9.5)
      highline (>= 1.4.0)
    term-ansicolor (1.0.5)
    webrat (0.7.2)
      nokogiri (>= 1.2.0)
      rack (>= 1.0)
      rack-test (>= 0.5.3)

PLATFORMS
  ruby

DEPENDENCIES
  cucumber-nagios

I thought it might be an issue with webrat, but I created a webrat spec to do the same test and it passes:

  it "should submit forms" do
    visit "http://localhost:4567/"
    fill_in "username", :with => "my username"
    fill_in "password", :with => "my password"
    response = click_button "Log In"

    response.should contain("Values: my username, my password")
  end
@josephholsten
Copy link
Contributor

I can confirm. For the lazy, I've dropped this in a git repo: https://github.com/josephholsten/cuke-nag-forms-test

Looks like the response object is getting messed up. Very weird.

@melezhik
Copy link

I had the same issue with submitting forms, googled for while and found workaround - in features/support/env.rb one should have this to have webrat doing right job:

Webrat.configure do |config|
  config.mode = :rails
  config.open_error_files = false
end

@voodoo
Copy link

voodoo commented Nov 1, 2011

This worked for me, appreciate the heads up!

Webrat.configure do |config|
  config.mode = :rails
  config.open_error_files = false
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants