[Cucumber:4265] Cucumber login scenario problem

328 views
Skip to first unread message

Amit

unread,
Apr 30, 2010, 2:29:20 AM4/30/10
to Cukes
Hello all,
I am facing a weird problem.I am just trying to login but after
entering
correct parameters it is showing error as invalid username and
password.
I think there is some configuration or fixtures problem because if i
try
to login from GUI then it is working fine(using same database)
Following are the detailed list of gems and code.
Rspec (1.3.0, 1.1.12)
Rspec-rails (1.3.2, 1.1.12)
cucumber (0.6.3)
cucumber-rails (0.3.0)
Webrat (0.5.3, 0.4.3)

config/environments/cucumber.rb
# Edit at your own peril - it's recommended to regenerate this file
# in the future when you upgrade to a newer version of Cucumber.

# IMPORTANT: Setting config.cache_classes to false is known to
# break Cucumber's use_transactional_fixtures method.
# For more information see
https://rspec.lighthouseapp.com/projects/16211/tickets/165
config.cache_classes = true

# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true

# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.0'
unless File.directory?(File.join(Rails.root,
'vendor/plugins/cucumber-rails'))
config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0'
unless File.directory?(File.join(Rails.root,
'vendor/plugins/database_cleaner'))
config.gem 'webrat', :lib => false, :version => '>=0.5.3'
unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
config.gem 'rspec', :lib => false, :version => '>=1.3.0'
unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
config.gem 'rspec-rails', :lib => false, :version => '>=1.3.2'
unless File.directory?(File.join(Rails.root,
'vendor/plugins/rspec-rails'))

features/support/env.rb
# IMPORTANT: This file is generated by cucumber-rails - edit at your
own
peril.
# It is recommended to regenerate this file in the future when you
upgrade to a
# newer version of cucumber-rails. Consider adding your own code to a
new file
# instead of editing this one. Cucumber will automatically load all
features/**/*.rb
# files.

ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) +
'/../../config/environment')

require 'cucumber/formatter/unicode' # Remove this line if you don't
want Cucumber Unicode support
require 'cucumber/rails/rspec'
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'

require 'webrat'
require 'webrat/core/matchers'

Webrat.configure do |config|
config.mode = :rails
config.open_error_files = false # Set to true if you want error
pages
to pop up in the browser
end

Before do
Fixtures.reset_cache
fixtures_folder = File.join(RAILS_ROOT, 'spec', 'fixtures')
fixtures = Dir[File.join(fixtures_folder, '*.yml')].map {|f|
File.basename(f, '.yml') }
Fixtures.create_fixtures(fixtures_folder, fixtures)
end


# If you set this to false, any error raised from within your app will
bubble
# up to your step definition and out to cucumber unless you catch it
somewhere
# on the way. You can make Rails rescue errors and render error pages
on
a
# per-scenario basis by tagging a scenario or feature with the
@allow-rescue tag.
#
# If you set this to true, Rails will rescue all errors and render
error
# pages, more or less in the same way your application would behave in
the
# default production environment. It's not recommended to do this for
all
# of your scenarios, as this makes it hard to discover errors in your
application.
ActionController::Base.allow_rescue = false

# If you set this to true, each scenario will run in a database
transaction.
# You can still turn off transactions on a per-scenario basis, simply
tagging
# a feature or scenario with the @no-txn tag. If you are using
Capybara,
# tagging with @culerity or @javascript will also turn transactions
off.
#
# If you set this to false, transactions will be off for all
scenarios,
# regardless of whether you use @no-txn or not.
#
# Beware that turning transactions off will leave data in your
database
# after each scenario, which can lead to hard-to-debug failures in
# subsequent scenarios. If you do this, we recommend you create a
Before
# block that will explicitly put your database in a known state.
Cucumber::Rails::World.use_transactional_fixtures = true

# How to clean your database when transactions are turned off. See
# http://github.com/bmabey/database_cleaner for more info.
if defined?(ActiveRecord::Base)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
rescue LoadError => ignore_if_database_cleaner_not_present
end
end

features/manage_users.feature
Given a registered user
When he clicks on login link
And after filling all the details
Then the user should be logged in

features/step_definitions/user_steps.rb
Given /^a registered user$/ do
visit '/login'
end

When /^he clicks on login link$/ do
visit '/login'
fill_in("login", :with => "test")
fill_in("password", :with => "test123")
click_button "Log in"
p current_url
p response.body
end

Then /^that user should get created$/ do
@user = User.find_by_login("test")
@user.test.should == "test"
end

This is my whole scenario.Now if i see the current url it says
'/session' which actually should be '/users' and in response.body it
says 'invalid username and password'

Also in my database list of users are already present
Please suggest

--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cu...@googlegroups.com.
To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.

Amit

unread,
Jun 21, 2010, 9:38:04 AM6/21/10
to Cukes
Any suggestions

On Apr 30, 11:29 am, Amit <amitkkulkarni...@gmail.com> wrote:
> Hello all,
> I am facing a weirdproblem.I am just trying tologinbut after
> entering
> correct parameters it is showing error as invalid username and
> password.
> I think there is some configuration or fixturesproblembecause if i
> try
> tologinfrom GUI then it is working fine(using same database)
> Following are the detailed list of gems and code.
> Rspec (1.3.0, 1.1.12)
> Rspec-rails (1.3.2, 1.1.12)
> cucumber (0.6.3)
> cucumber-rails (0.3.0)
> Webrat (0.5.3, 0.4.3)
>
> config/environments/cucumber.rb
> # Edit at your own peril - it's recommended to regenerate this file
> # in the future when you upgrade to a newer version of Cucumber.
>
> # IMPORTANT: Setting config.cache_classes to false is known to
> # break Cucumber's use_transactional_fixtures method.
> # For more information seehttps://rspec.lighthouseapp.com/projects/16211/tickets/165
> #http://github.com/bmabey/database_cleanerfor more info.
> if defined?(ActiveRecord::Base)
>   begin
>     require 'database_cleaner'
>     DatabaseCleaner.strategy = :truncation
>   rescue LoadError => ignore_if_database_cleaner_not_present
>   end
> end
>
> features/manage_users.feature
>     Given a registered user
>     When he clicks onloginlink
>     And after filling all the details
>     Then the user should be logged in
>
> features/step_definitions/user_steps.rb
> Given /^a registered user$/ do
>   visit '/login'
> end
>
> When /^he clicks onloginlink$/ do

aslak hellesoy

unread,
Jun 21, 2010, 9:47:16 AM6/21/10
to cu...@googlegroups.com
See inline below

I strongly recommend against using fixtures. It makes your tests very
brittle. Instead, create whatever records you need in one or more
Given steps. Also look at FactoryGirl or Pickle

The step text (Given a registered user) doesn't match your stepdef
implementation. I would expect the implementation here to create a
User record.
It looks like your fixture code isn't setting up the User correctly either.

Aslak

Amit

unread,
Jun 21, 2010, 10:03:09 AM6/21/10
to Cukes
I dont know about fixtures.But now i am not using fixtures and have
created a new entry itself in the scenario but still is giving me same
problem.Following are the details:
Given /^an user logins with valid credentials$/ do
b = User.new(:login => "test123", :name => "test", :email =>
"t...@test.com",:password => "test123", :password_confirmation =>
"test123", :role_id => 3,
:state => "active")
b.save
b.register!
b.activate
p b
p b.errors
p b.password
visit '/login'
fill_in("login", :with => b.login)
fill_in("password", :with => b.password)
click_button "Log-in"
p current_url
p response.body
end

Now after logging it show show the specific url.but it shows "/
session"
url.it is not logging and in the response.body it says wrong username
and
password.
But from the above i can see that user is created.Following are the
details.Also there are no errors
User id: 6, login: "test123", name: "test", email: "t...@test.com",
crypted_password: "3357b45b09986ef668e6bf563cb2032a8f5a0da8", salt:
"c8024776e7d68ff5b8e473537a5a5c9b9417d10e", created_at: "2010-06-21
13:05:17", updated_at: "2010-06-21 13:05:18", remember_token: nil,
remember_token_expires_at: nil, activated_at: "2010-06-21 13:05:18",
activation_code: nil, deleted_at: nil, state: "active", role_id: 3,
permalink: "test", delta: true, close_account_reasons: nil>

Now i have added debug statements in the controller to check whether
values are going or not.But user parameters are not going into the
sessions controller.because of that it is not accepting since it is
getting blank values.
But i am seeing that user is created so how come the parameters are
going blank.Is there any change do i need to make support/env.rb
> > #http://github.com/bmabey/database_cleanerfor more info.

Amit

unread,
Jun 22, 2010, 2:46:21 AM6/22/10
to Cukes
I just checked it out we re using restfull authentication.So does it
make any difference.Do i need to change in my cucumber environment.

On Jun 21, 7:03 pm, Amit <amitkkulkarni...@gmail.com> wrote:
> I dont know about fixtures.But now i am not using fixtures and have
> created a new entry itself in the scenario but still is giving me sameproblem.Following are the details:
> Given /^an user logins with valid credentials$/ do
> b  = User.new(:login=> "test123", :name => "test", :email =>
> "t...@test.com",:password => "test123", :password_confirmation =>
> "test123", :role_id => 3,
> :state => "active")
> b.save
> b.register!
> b.activate
> p b
> p b.errors
> p b.password
>   visit '/login'
>   fill_in("login", :with => b.login)
>   fill_in("password", :with => b.password)
>   click_button "Log-in"
>   p current_url
>   p response.body
> end
>
> Now after logging it show show the specific url.but it shows "/
> session"
> url.it is not logging and in the response.body it says wrong username
> and
> password.
> But from the above i can see that user is created.Following are the
> details.Also there are no errors
> User id: 6,login: "test123", name: "test", email: "t...@test.com",
> crypted_password: "3357b45b09986ef668e6bf563cb2032a8f5a0da8", salt:
> "c8024776e7d68ff5b8e473537a5a5c9b9417d10e", created_at: "2010-06-21
> 13:05:17", updated_at: "2010-06-21 13:05:18", remember_token: nil,
> remember_token_expires_at: nil, activated_at: "2010-06-21 13:05:18",
> activation_code: nil, deleted_at: nil, state: "active", role_id: 3,
> permalink: "test", delta: true, close_account_reasons: nil>
>
> Now i have added debug statements in the controller to check whether
> values are going or not.But user parameters are not going into the
> sessions controller.because of that it is not accepting since it is
> getting blank values.
> But i am seeing that user is created so how come the parameters are
> going blank.Is there any change do i need to  make support/env.rb
>
> On Jun 21, 6:47 pm, aslak hellesoy <aslak.helle...@gmail.com> wrote:
>
> > See inline below
>
> > On Fri, Apr 30, 2010 at 8:29 AM, Amit <amitkkulkarni...@gmail.com> wrote:
> > > Hello all,
> > > I am facing a weirdproblem.I am just trying tologinbut after
> > > entering
> > > correct parameters it is showing error as invalid username and
> > > password.
> > > I think there is some configuration or fixturesproblembecause if i
> > > try
> > > tologinfrom GUI then it is working fine(using same database)
> > > #http://github.com/bmabey/database_cleanerformore info.
> > > if defined?(ActiveRecord::Base)
> > >  begin
> > >    require 'database_cleaner'
> > >    DatabaseCleaner.strategy = :truncation
> > >  rescue LoadError => ignore_if_database_cleaner_not_present
> > >  end
> > > end
>
> > > features/manage_users.feature
> > >    Given a registered user
> > >    When he clicks onloginlink
> > >    And after filling all the details
> > >    Then the user should be logged in
>
> > > features/step_definitions/user_steps.rb
> > > Given /^a registered user$/ do
>
> > The step text (Given a registered user) doesn't match your stepdef
> > implementation. I would expect the implementation here to create a
> > User record.
> > It looks like your fixture code isn't setting up the User correctly either.
>
> > Aslak
>
> > >  visit '/login'
> > > end
>
> > > When /^he clicks onloginlink$/ do

aslak hellesoy

unread,
Jun 22, 2010, 2:55:52 AM6/22/10
to cu...@googlegroups.com

Right before you log in, do puts User.all.inspect.

This will tell you whether your fixtures are working. Try to isolate the problem.

Aslak

On Jun 22, 2010 8:46 AM, "Amit" <amitkkul...@gmail.com> wrote:

I just checked it out we re using restfull authentication.So does it
make any difference.Do i need to change in my cucumber environment.


On Jun 21, 7:03 pm, Amit <amitkkulkarni...@gmail.com> wrote:

> I dont know about fixtures.But now i...

> created a new entry itself in the scenario but still is giving me sameproblem.Following are the details:

> Given /^an user logins with valid credentials$/ do

> b  = User.new(:login=> "test123", :name => "t...

> > > I am facing a weirdproblem.I am just trying tologinbut after

> > > entering
> > > correct parameters it is showing error as invalid username and
> > > password.

> > > I think there is some configuration or fixturesproblembecause if i
> > > try

> > > tologinfrom GUI then it is working fine(using same database)

> > > Following are the detailed list of gems and code.
> > > Rspec (1.3.0, 1.1.12)

> > > Rspec-rail...

> > > #http://github.com/bmabey/database_cleanerformore info.

> > > if defined?(ActiveRecord::Base)
> > >  begin
> > >    require 'database_cleaner'

> > >    Data...

> > > When /^he clicks onloginlink$/ do

> > >  visit '/login'
> > >  fill_in("login", :with => "test")

> > >  fill_in("password", :with => "...

Amit

unread,
Jun 24, 2010, 4:41:11 AM6/24/10
to Cukes
Hi Aslak,
I checked with inspect and i can see all the users in the list but
still i ma getting the problem.
Now commented the fixtures part and again tried the same by creating a
new user then also same problem is coming.
Also i checked the we use restfull authentication so after
investigation i added a line in env.rb i.e.
ApplicationController.send(:public, :logged_in?, :current_user, :authorized?)
but no success.

If i do this in rspec then it is working fine.So i am not getting
exactly what the problem is.


On Jun 22, 11:55 am, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> Right before you log in, do puts User.all.inspect.
>
> This will tell you whether your fixtures are working. Try to isolate the
> problem.
>
> Aslak
>

Amit

unread,
Jun 24, 2010, 4:46:03 AM6/24/10
to Cukes
I also added debugging statements in controller from where this action
is called for checking the params but surprisingly i am getting nil
values.In short whatever values i am passing they are not going to the
controller.

On Jun 24, 1:41 pm, Amit <amitkkulkarni...@gmail.com> wrote:
> Hi Aslak,
> I checked with inspect and i can see all the users in the list but
> still i ma getting theproblem.
> Now commented the fixtures part and again tried the same by creating a
> new user then also sameproblemis coming.

Amit

unread,
Jun 24, 2010, 5:52:46 AM6/24/10
to Cukes
I checked the debugging statements in the controller.Following are
the params i am getting
{"commit"=>"Log-in", "action"=>"create", "controller"=>"sessions",
"login"=>"", "password"=>""}
It is calling the right controller and the action but it is not
passing the parameters.

aslak hellesoy

unread,
Jun 24, 2010, 5:58:52 AM6/24/10
to cu...@googlegroups.com

And you are really filling in the fields with webrat or capybara?

On Jun 24, 2010 11:52 AM, "Amit" <amitkkul...@gmail.com> wrote:

I checked the debugging statements  in the controller.Following are
the params i am getting
{"commit"=>"Log-in", "action"=>"create", "controller"=>"sessions",
"login"=>"", "password"=>""}
It is calling the right controller and the action but it is not
passing the parameters.


On Jun 24, 1:46 pm, Amit <amitkkulkarni...@gmail.com> wrote:

> I also added debugging statements in...

Amit

unread,
Jun 24, 2010, 6:10:02 AM6/24/10
to Cukes
I am filling the fields with webrat.
Following is the code in my step definition:
Given /^an user logins with valid credentials$/ do
b = User.new(:login => "test123", :name => "test", :email =>
"te...@test.com", :password => "test123", :password_confirmation =>
"test123", :role_id => 3, :state => "active")
b.save
b.register!
b.activate
visit '/login'
fill_in("login", :with => "test123")
fill_in("password", :with => "test123")
click_button "Log-in"
p b.errors
p User.all.inspect
end


On Jun 24, 2:58 pm, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> And you are really filling in the fields with webrat or capybara?
>

Amit Kulkarni

unread,
Jul 8, 2010, 9:08:08 AM7/8/10
to Cukes
Any solution on this...

Chuck van der Linden

unread,
Jul 8, 2010, 12:47:29 PM7/8/10
to Cukes
I'm coming into this late, so not sure if I can add much, but it seems
to me that the order of your steps might be part of the problem

From your first postings I noticed this

Given a registered user
When he clicks on login link
And after filling all the details
Then the user should be logged in


Now, if the first step is doing all the logging in etc, then the next
steps would seem to be redundant, or might have the effect of going
back to the login page and clicking the link with no data filled in???

Also IMHO doing an 'and' after a 'when' is bad form, there should be
one single action that's being taken, not a series of actions. If
clicking the login link is the 'critical' action in this test, then
filling in all the details should come before that step. (I don't
know if 'details' in this instance refers to profile details, or
username and password). If the filling in of some kind of details
after submitting credentials is the critical step, then that should be
the 'when' step and the clicking the login link should be part of your
'given' steps


In my tests I have one 'utility' step that I used to login a user, but
I don't use it for my test of the actual login page, I use it in other
scripts that require a user to be logged in.

My test for the actual login process is slightly more detailed (one of
the first tests that should get run really, considering nearly
everything else depends on that working) is more like this (with
comments added to roughly describe what the steps do)

Given no user is logged in #calls logout page (ensures no old
session cookie present)
And I am on the login page #calls up the login page
And I have entered username of: <valid username> #checks for presence
of username field, and enters value
And I have entered password of: <valid password for username> #checks
for presence of field, and enters value
When I click the Login button #checks for presence of button, and
clicks it
Then I see the text: welcome <valid username> in the page header
#looks for the greeting given a logged in user
And (any other checks to see that the right user got logged in)

The 'utility' step user for later scripts pretty much does all of the
above, sans a lot of the checks etc which would be redundant, and
takes a username (test passwords being standardized) as an input.

It seems to me a bit like you are trying to combine the two, and are
using an 'create a user and log them in' step inside a more granular
set of steps.. So if I read that right, your script ends up getting
ahead of itself

The other potential is that if you are actually 'creating' this user
right before logging it in, do you need to allow any time for it to
get persisted in some way so that it's 'findable' when you go to log
in? If things work manually but not automated, that could be the
cause of the problem

On Jul 8, 6:08 am, Amit Kulkarni <amitkkulkarni...@gmail.com> wrote:
> Any solution on this...
>
>
>
> On Thu, Jun 24, 2010 at 3:40 PM, Amit <amitkkulkarni...@gmail.com> wrote:
> > I am filling the fields with webrat.
> > Following is the code in my step definition:
> > Given /^an user logins with valid credentials$/ do
> > b  = User.new(:login => "test123", :name => "test", :email =>
> > "t...@test.com", :password => "test123", :password_confirmation =>
> > cukes+un...@googlegroups.com <cukes%2Bunsu...@googlegroups.com>.
> > For more options, visit this group at
> >http://groups.google.com/group/cukes?hl=en.- Hide quoted text -
>
> - Show quoted text -

Amit Kulkarni

unread,
Jul 9, 2010, 4:57:47 AM7/9/10
to cu...@googlegroups.com
Thanks a lot Chuck.
But after re-arranging the steps still the same problem is appearing
If i see in console (test environment) then i am seeing the user present already.If i login manually then it is working fine but somehow for cucumber it is not getting the user.
Is there anything i need to add to retrieve the user details in environment.rb so that it gets successfully logged in.


To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages