Forum: RSpec problem using cucumber with selenium

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Barun S. (Guest)
on 2009-04-20 23:13
(Received via mailing list)
I'm trying to use Cucumber with Selenium to test my app.  I have a
method
called "login_as" defined as follows:

  def login_as(user, password)
    visit new_session_path
    fill_in "username", :with  => user.username
    fill_in "password", :with => password
    click_button('Go')
    response.body.should =~ /Signed in as <a
href=\"[^\"]+\">#{user.username}<\/a>/
  end


This works fine when I'm not using Selenium, but it fails when I do use
Selenium.  Weirder still is that if I use Selenium but put a "debugger"
step
before the "click_button" step, and I execute the last two lines through
the
console, everything works.  When it fails, the error seems to indicate
that
nothing on the page has changed -- that is, that "response" is still the
old
response from before I executed the "click_button" step.  My best guess
is
that the code perhaps isn't waiting for the browser to actually load the
new
page before looking at the response.  Does anyone know how to fix this
issue?

Thanks..
Barun S. (Guest)
on 2009-04-20 23:26
(Received via mailing list)
found the answer via some more searching; it appears this is a bug with
webrat that hasn't been fixed yet; if i add
"selenium.wait_for_page_to_load(5)"
after the click_button command, things work fine.

i've opened up a new ticket in the webrat lighthouse acct.
roovo (Guest)
on 2009-04-21 01:50
(Received via mailing list)
2009/4/20 Barun S. <removed_email_address@domain.invalid>

> found the answer via some more searching; it appears this is a bug with
> webrat that hasn't been fixed yet; if i add
> "selenium.wait_for_page_to_load(5)"
> after the click_button command, things work fine.
>

I hit a similar problem and ended up putting the following in my feature
setup (it would need something similar for the response method but I'm
not
actually using that).
Doing it this way means you don't have to put any extras in your
features to
work around the bug so once it's fixed you can just remove the hack :)
module Webrat
  class SeleniumSession
    def response_body
      sleep 0.2
      selenium.get_html_source
    end
  end
end

I've not experimented with the sleep length I just tried it with 0.2 and
it
worked...

-- roovo
This topic is locked and can not be replied to.