Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara:Webkit unable to find iframe or its content

I allow users to share photos with other individuals. When the user is viewing a photo and its description, they can click on "share" and a new page loads. On this page the fill in an email address (and optional comments - not tested here) and click "Share Photo". The systems sends an email to the recipient with a link contained and the subject line includes the name of the photo. The page with the Share form also displays a list of individuals the photo has already been shared with.

The full page load is a source of complaints from users. They want a modal window to quickly load and minimize navigation. I agree.

I use shadowbox.js to load the Share page into an iframe in a modal window. It works well and allows a nice fallback to the old page if needed.

But - I just can't get my tests to pass. In particular, Capybara:Webkit just can't find the iframe.

The environment is: Rail 3.0.9 capybara 0.4.1.2 capybara-webkit 0.5.0 cucumber 1.0.2

The Cucumber story:

Feature: Share photo

@javascript
Scenario: User shares photo
  When I follow "Share"
  Then I should see "Share Old Man Photo" inside "#sb-player"
  And I should see information about who I've shared this photo with
  When I fill in "Share with" with "[email protected]"
  And I press "Share Photo"
  Then "[email protected]" should receive an email with subject "Old Man photo has been shared with you"

My step:

Then %r{^I should see "([^"]*)" inside ([^"].*)$} do |expected_text, named_element|
  selector = element_for(named_element)
  within_frame selector do
    page.should have_content(expected_text)
  end
end

The Fail Message:

(::) failed steps (::)

Unable to locate frame.  (Capybara::Driver::Webkit::WebkitError)
./features/step_definitions/sharing_steps.rb:94:in `/^I should see "([^"]*)" inside "([^"]*)"$/'
features/user_shares_photo.feature:21:in `Then I should see "Share Old Man Photo" inside "#sb-player"'

Failing Scenarios:
cucumber features/user_shares_photo.feature:19 

I've tried every combination of element ids. I just can't get Capybara:Webkit to recognize the iframe.

Any ideas or solutions? I can't deliver with failing test and am considering pitching the whole iframe approach - but I'd like to find a solution.

Thanks

like image 287
glimpse nirvana Avatar asked Jul 31 '11 15:07

glimpse nirvana


1 Answers

Need to add time to allow the iframe to open/populate. Sleep 5 did it.

Then %r{^I should see "([^"]*)" inside ([^"].*)$} do |expected_text, named_element|
  sleep 5
  selector = element_for(named_element)
  within_frame selector do
    page.should have_content(expected_text)
  end
end
like image 77
glimpse nirvana Avatar answered Nov 05 '22 00:11

glimpse nirvana