[rspec-users] [cucumber] webrat+selenium integration problem: record n

Balint Erdi lists at ruby-forum.com
Wed Mar 25 19:25:14 EDT 2009

> Hey Ben, thanks a lot.
> The problem I am experiencing now is that information stored in the 
> session does not seem to be retained between steps (again, only in the 
> case of selenium sessions, plain sesssion work fine). So the login 
> function works fine now but when I go to another page afterwards it 
> throws a big error because the action tries to render something based on 
> the current user.
> Is the session store I am using relevant? I used the default 
> cookie-based storage and then tried to change to the active-record based 
> one to no avail. My config is at http://gist.github.com/83635
> Thank you,
> Balint

Ok, I think I have the problem and it has nothing to do with session 
storage. I intend to explain it below so others might benefit from it.

  Scenario: Successfully sharing album with group via the "Share with 
group" link
    Given I am logged in as "pepito"
    When I go to my photosets page

I used some existing step definitions I wrote for non-selenium features 
to log in the user like so:

  Given /^I log in as "(.*)"$/ do |login_name|
    @user = User.find_by_login(login_name)
    post "/session", :login => @user.login, :password => 'secret' # !!!

  Given /^I am logged in as "(.*)"$/ do |login_name|
    Given %(the user "#{login_name}" exists)
    Given %(the user "#{login_name}" is active)
    Given %(I log in as "#{login_name}")

When the feature gets to "When I go to my photosets page", the selenium 
browser is launched but there is no user logged in here, there is no 
session, so that step will fail miserably. That's because the line 
denoted by !!! does not log in the user in the selenium session but in 
the "test session" (I know this is not the proper definition but I 
cannot precisely name it).

So if I need a logged in user in a selenium feature I should go the 
"hard way" and start from scratch:

  Given the user "pepito" exists
  And the user "pepito" is active
  When I go to the login page
  And I fill in "login" with "pepito"
  And I fill in "password" with "secret"
  And I press "entrar"
  And I go to my photosets page

It takes some time to get one's head around realizing there is a test 
world and a selenium world and keep in mind which action modifies which 
world and learn how they can interact with each other (through the 
database I guess if they use the same environment).

Please correct me if I am wrong in anything I say above,

Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list