Capybara with AJAX

28 views
Skip to first unread message

Garrett Wilson

unread,
Aug 17, 2013, 11:08:18 AM8/17/13
to rubyonra...@googlegroups.com
I have a table that is populated using AJAX pagination (Kaminari). What I'm trying to do is view this page and make sure there is certain content within the table. This causes a problem with my Capybara test because it doesn't wait for the pagination to finish before it checks the page for the content. I'm thinking it's something simple that I'm overlooking, but I have been unable to find a solution through google. I suppose I could just wait for a given amount of time, but this solution seems hacky to me.

Here is my test:

     visit accounts_path

    #This is the text that should be inside the paginated table
    page.should have_content('test...@mail.com')

Frederick Cheung

unread,
Aug 18, 2013, 5:22:57 AM8/18/13
to rubyonra...@googlegroups.com
On Saturday, August 17, 2013 4:08:18 PM UTC+1, Garrett Wilson wrote:
>
> Here is my test:
>
>      visit accounts_path
>
>     #This is the text that should be inside the paginated table
>     page.should have_content('test...@mail.com')


This should work fine - capybara is pretty good at waiting for stuff to load automatically. What capybara driver are you using? The default rack_test driver won't work here because it doesn't run javascript (since there is no browser). There are several drivers that do run javascript such as selenium (which runs an actual browser) or ones like poltergeist or capybara_webkit that run a headless WebKit browser

Fred

Tamara Temple

unread,
Aug 18, 2013, 3:00:18 PM8/18/13
to rubyonra...@googlegroups.com
Does this help? https://github.com/jnicklas/capybara#asynchronous-javascript-ajax-and-friends

This is typically why I use watir-webdriver — testing async stuff just seems more intuitive with wait_until and wait_for.

Reply all
Reply to author
Forward
0 new messages